Skip to content

Commit bb80a49

Browse files
committed
FAB-2457 ACL for proposals to application cc
Proposals to application chaincodes must be checked against the channel writers as agreed in the discussion section of the JIRA item. There are no tests because they were originally added in 2fc6bc6. Change-Id: I28a33b00bc607b9d513e63e3e2a02c581b81f7f8 Signed-off-by: Alessandro Sorniotti <[email protected]>
1 parent cacb292 commit bb80a49

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

core/endorser/endorser.go

+11-19
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"errors"
2727

28+
"github.com/hyperledger/fabric/common/policies"
2829
"github.com/hyperledger/fabric/common/util"
2930
"github.com/hyperledger/fabric/core/chaincode"
3031
"github.com/hyperledger/fabric/core/chaincode/shim"
@@ -55,27 +56,16 @@ func NewEndorserServer() pb.EndorserServer {
5556
}
5657

5758
// checkACL checks that the supplied proposal complies
58-
// with the policies of the chain; for a system chaincode
59-
// we use the admins policy, whereas for normal chaincodes
60-
// we use the writers policy
59+
// with the writers policy of the chain
6160
func (*Endorser) checkACL(signedProp *pb.SignedProposal, chdr *common.ChannelHeader, shdr *common.SignatureHeader, hdrext *pb.ChaincodeHeaderExtension) error {
62-
/****** FAB-2457- we need to fix this right
6361
// get policy manager to check ACLs
6462
pm := peer.GetPolicyManager(chdr.ChannelId)
6563
if pm == nil {
6664
return fmt.Errorf("No policy manager available for chain %s", chdr.ChannelId)
6765
}
6866

6967
// access the policy to use to validate this proposal
70-
var policyName string
71-
if syscc.IsSysCC(hdrext.ChaincodeId.Name) {
72-
// in the case of a system chaincode, we use the admin policy
73-
policyName = policies.ChannelApplicationAdmins
74-
} else {
75-
// in the case of a normal chaincode, we use the writers policy
76-
policyName = policies.ChannelApplicationWriters
77-
}
78-
policy, _ := pm.GetPolicy(policyName)
68+
policy, _ := pm.GetPolicy(policies.ChannelApplicationWriters)
7969

8070
// evaluate that this proposal complies with the writers
8171
err := policy.Evaluate(
@@ -86,11 +76,10 @@ func (*Endorser) checkACL(signedProp *pb.SignedProposal, chdr *common.ChannelHea
8676
}})
8777
if err != nil {
8878
return fmt.Errorf("The proposal does not comply with the %s for channel %s, error %s",
89-
policyName,
79+
policies.ChannelApplicationWriters,
9080
chdr.ChannelId,
9181
err)
9282
}
93-
**********/
9483

9584
return nil
9685
}
@@ -345,10 +334,13 @@ func (e *Endorser) ProcessProposal(ctx context.Context, signedProp *pb.SignedPro
345334
return nil, fmt.Errorf("Duplicate transaction found [%s]. Creator [%x]. [%s]", txid, shdr.Creator, err)
346335
}
347336

348-
// check ACL - we verify that this proposal
349-
// complies with the policy of the chain
350-
if err = e.checkACL(signedProp, chdr, shdr, hdrExt); err != nil {
351-
return &pb.ProposalResponse{Response: &pb.Response{Status: 500, Message: err.Error()}}, err
337+
// check ACL only for application chaincodes; ACLs
338+
// for system chaincodes are checked elsewhere
339+
if !syscc.IsSysCC(hdrExt.ChaincodeId.Name) {
340+
// check that the proposal complies with the channel's writers
341+
if err = e.checkACL(signedProp, chdr, shdr, hdrExt); err != nil {
342+
return &pb.ProposalResponse{Response: &pb.Response{Status: 500, Message: err.Error()}}, err
343+
}
352344
}
353345
} else {
354346
// chainless proposals do not/cannot affect ledger and cannot be submitted as transactions

0 commit comments

Comments
 (0)