@@ -23,10 +23,14 @@ import (
23
23
"github.com/golang/protobuf/proto"
24
24
"github.com/hyperledger/fabric/common/cauthdsl"
25
25
"github.com/hyperledger/fabric/common/flogging"
26
+ "github.com/hyperledger/fabric/common/policies"
26
27
"github.com/hyperledger/fabric/core/chaincode/shim"
27
28
"github.com/hyperledger/fabric/core/common/ccprovider"
28
29
"github.com/hyperledger/fabric/core/common/sysccprovider"
29
30
"github.com/hyperledger/fabric/core/peer"
31
+ "github.com/hyperledger/fabric/core/policy"
32
+ "github.com/hyperledger/fabric/core/policyprovider"
33
+ "github.com/hyperledger/fabric/msp/mgmt"
30
34
pb "github.com/hyperledger/fabric/protos/peer"
31
35
"github.com/hyperledger/fabric/protos/utils"
32
36
)
@@ -82,6 +86,10 @@ type LifeCycleSysCC struct {
82
86
// methods of the system chaincode package without
83
87
// import cycles
84
88
sccprovider sysccprovider.SystemChaincodeProvider
89
+
90
+ // policyChecker is the interface used to perform
91
+ // access control
92
+ policyChecker policy.PolicyChecker
85
93
}
86
94
87
95
//----------------errors---------------
@@ -564,6 +572,10 @@ func (lscc *LifeCycleSysCC) executeUpgrade(stub shim.ChaincodeStubInterface, cha
564
572
//Init only initializes the system chaincode provider
565
573
func (lscc * LifeCycleSysCC ) Init (stub shim.ChaincodeStubInterface ) pb.Response {
566
574
lscc .sccprovider = sysccprovider .GetSystemChaincodeProvider ()
575
+
576
+ // Init policy checker for access control
577
+ lscc .policyChecker = policyprovider .GetPolicyChecker ()
578
+
567
579
return shim .Success (nil )
568
580
}
569
581
@@ -580,12 +592,24 @@ func (lscc *LifeCycleSysCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response
580
592
581
593
function := string (args [0 ])
582
594
595
+ // Handle ACL:
596
+ // 1. get the signed proposal
597
+ sp , err := stub .GetSignedProposal ()
598
+ if err != nil {
599
+ return shim .Error (fmt .Sprintf ("Failed retrieving signed proposal on executing %s with error %s" , function , err ))
600
+ }
601
+
583
602
switch function {
584
603
case INSTALL :
585
604
if len (args ) < 2 {
586
605
return shim .Error (InvalidArgsLenErr (len (args )).Error ())
587
606
}
588
607
608
+ // 2. check local MSP Admins policy
609
+ if err = lscc .policyChecker .CheckPolicyNoChannel (mgmt .Admins , sp ); err != nil {
610
+ return shim .Error (fmt .Sprintf ("Authorization for INSTALL on %s has been denied with error %s" , args [1 ], err ))
611
+ }
612
+
589
613
depSpec := args [1 ]
590
614
591
615
err := lscc .executeInstall (stub , depSpec )
@@ -598,6 +622,9 @@ func (lscc *LifeCycleSysCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response
598
622
return shim .Error (InvalidArgsLenErr (len (args )).Error ())
599
623
}
600
624
625
+ // TODO: add access control check
626
+ // once the instantiation process will be completed.
627
+
601
628
//chain the chaincode shoud be associated with. It
602
629
//should be created with a register call
603
630
chainname := string (args [1 ])
@@ -652,6 +679,9 @@ func (lscc *LifeCycleSysCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response
652
679
return shim .Error (InvalidChainNameErr (chainname ).Error ())
653
680
}
654
681
682
+ // TODO: add access control check
683
+ // once the instantiation process will be completed.
684
+
655
685
depSpec := args [2 ]
656
686
657
687
// optional arguments here (they can each be nil and may or may not be present)
@@ -696,6 +726,13 @@ func (lscc *LifeCycleSysCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response
696
726
chain := string (args [1 ])
697
727
ccname := string (args [2 ])
698
728
729
+ // 2. check local Channel Readers policy
730
+ // Notice that this information are already available on the ledger
731
+ // therefore we enforce here that the caller is reader of the channel.
732
+ if err = lscc .policyChecker .CheckPolicy (chain , policies .ChannelApplicationReaders , sp ); err != nil {
733
+ return shim .Error (fmt .Sprintf ("Authorization for %s on channel %s has been denied with error %s" , function , args [1 ], err ))
734
+ }
735
+
699
736
cdbytes , err := lscc .getCCInstance (stub , ccname )
700
737
if err != nil {
701
738
logger .Errorf ("error getting chaincode %s on channel: %s(err:%s)" , ccname , chain , err )
@@ -722,11 +759,23 @@ func (lscc *LifeCycleSysCC) Invoke(stub shim.ChaincodeStubInterface) pb.Response
722
759
if len (args ) != 1 {
723
760
return shim .Error (InvalidArgsLenErr (len (args )).Error ())
724
761
}
762
+
763
+ // 2. check local MSP Admins policy
764
+ if err = lscc .policyChecker .CheckPolicyNoChannel (mgmt .Admins , sp ); err != nil {
765
+ return shim .Error (fmt .Sprintf ("Authorization for GETCHAINCODES on channel %s has been denied with error %s" , args [0 ], err ))
766
+ }
767
+
725
768
return lscc .getChaincodes (stub )
726
769
case GETINSTALLEDCHAINCODES :
727
770
if len (args ) != 1 {
728
771
return shim .Error (InvalidArgsLenErr (len (args )).Error ())
729
772
}
773
+
774
+ // 2. check local MSP Admins policy
775
+ if err = lscc .policyChecker .CheckPolicyNoChannel (mgmt .Admins , sp ); err != nil {
776
+ return shim .Error (fmt .Sprintf ("Authorization for GETINSTALLEDCHAINCODES on channel %s has been denied with error %s" , args [0 ], err ))
777
+ }
778
+
730
779
return lscc .getInstalledChaincodes ()
731
780
}
732
781
0 commit comments