Skip to content

Commit 43ece2d

Browse files
committed
[FAB-9739] Introduce ACLProvider interface
Pass the ACL provider to chaincode support instead of getting it from a global out of the handler. Change-Id: I4f58cea1b17db248d190a7f48cdd1f2da2030fce Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
1 parent a12d256 commit 43ece2d

7 files changed

+55
-6
lines changed

core/chaincode/chaincode_support.go

+3
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func NewChaincodeSupport(
5252
caCert []byte,
5353
certGenerator CertGenerator,
5454
packageProvider PackageProvider,
55+
aclProvider ACLProvider,
5556
) *ChaincodeSupport {
5657
cs := &ChaincodeSupport{
5758
caCert: caCert,
@@ -63,6 +64,7 @@ func NewChaincodeSupport(
6364
executetimeout: config.ExecuteTimeout,
6465
handlerRegistry: NewHandlerRegistry(userrunsCC),
6566
PackageProvider: packageProvider,
67+
ACLProvider: aclProvider,
6668
}
6769

6870
// Keep TestQueries working
@@ -100,6 +102,7 @@ type ChaincodeSupport struct {
100102
userRunsCC bool
101103
ContainerRuntime Runtime
102104
PackageProvider PackageProvider
105+
ACLProvider ACLProvider
103106
sccp sysccprovider.SystemChaincodeProvider
104107
}
105108

core/chaincode/chaincode_support_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,16 @@ func initMockPeer(chainIDs ...string) (*ChaincodeSupport, error) {
167167
ccprovider.SetChaincodesPath(ccprovider.GetCCsPath())
168168
ca, _ := accesscontrol.NewCA()
169169
certGenerator := accesscontrol.NewAuthenticator(ca)
170-
chaincodeSupport := NewChaincodeSupport(GlobalConfig(), "0.0.0.0:7052", true, ccStartupTimeout, ca.CertBytes(), certGenerator, &ccprovider.CCInfoFSImpl{})
170+
chaincodeSupport := NewChaincodeSupport(
171+
GlobalConfig(),
172+
"0.0.0.0:7052",
173+
true,
174+
ccStartupTimeout,
175+
ca.CertBytes(),
176+
certGenerator,
177+
&ccprovider.CCInfoFSImpl{},
178+
aclmgmt.GetACLProvider(),
179+
)
171180
SideEffectInitialize(chaincodeSupport)
172181
chaincodeSupport.SetSysCCProvider(sccp)
173182
chaincodeSupport.executetimeout = time.Duration(1) * time.Second

core/chaincode/exectransaction_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,16 @@ func initPeer(chainIDs ...string) (net.Listener, *ChaincodeSupport, func(), erro
116116
ccprovider.SetChaincodesPath(ccprovider.GetCCsPath())
117117
ca, _ := accesscontrol.NewCA()
118118
certGenerator := accesscontrol.NewAuthenticator(ca)
119-
chaincodeSupport := NewChaincodeSupport(GlobalConfig(), peerAddress, false, ccStartupTimeout, ca.CertBytes(), certGenerator, &ccprovider.CCInfoFSImpl{})
119+
chaincodeSupport := NewChaincodeSupport(
120+
GlobalConfig(),
121+
peerAddress,
122+
false,
123+
ccStartupTimeout,
124+
ca.CertBytes(),
125+
certGenerator,
126+
&ccprovider.CCInfoFSImpl{},
127+
aclmgmt.GetACLProvider(),
128+
)
120129
chaincodeSupport.SetSysCCProvider(sccp)
121130
SideEffectInitialize(chaincodeSupport)
122131
pb.RegisterChaincodeSupportServer(grpcServer, chaincodeSupport)

core/chaincode/handler.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
commonledger "github.com/hyperledger/fabric/common/ledger"
1919
"github.com/hyperledger/fabric/common/resourcesconfig"
2020
"github.com/hyperledger/fabric/common/util"
21-
"github.com/hyperledger/fabric/core/aclmgmt"
2221
"github.com/hyperledger/fabric/core/aclmgmt/resources"
2322
"github.com/hyperledger/fabric/core/common/ccprovider"
2423
"github.com/hyperledger/fabric/core/common/sysccprovider"
@@ -42,6 +41,12 @@ var chaincodeLogger = flogging.MustGetLogger("chaincode")
4241

4342
type stateHandlers map[pb.ChaincodeMessage_Type]func(*pb.ChaincodeMessage)
4443

44+
// ACLProvider is responsible for performing access control checks when invoking
45+
// chaincode.
46+
type ACLProvider interface {
47+
CheckACL(resName string, channelID string, idinfo interface{}) error
48+
}
49+
4550
// internal interface to scope dependencies on ChaincodeSupport
4651
type handlerSupport interface {
4752
deregisterHandler(*Handler) error
@@ -83,6 +88,8 @@ type Handler struct {
8388

8489
keepalive time.Duration
8590
userRunsCC bool
91+
92+
aclProvider ACLProvider
8693
}
8794

8895
func shorttxid(txid string) string {
@@ -206,7 +213,7 @@ func (h *Handler) checkACL(signedProp *pb.SignedProposal, proposal *pb.Proposal,
206213
return errors.Errorf("signed proposal must not be nil from caller [%s]", ccIns.String())
207214
}
208215

209-
return aclmgmt.GetACLProvider().CheckACL(resources.Peer_ChaincodeToChaincode, ccIns.ChainID, signedProp)
216+
return h.aclProvider.CheckACL(resources.Peer_ChaincodeToChaincode, ccIns.ChainID, signedProp)
210217
}
211218

212219
func (h *Handler) deregister() {
@@ -325,6 +332,7 @@ func newChaincodeSupportHandler(chaincodeSupport *ChaincodeSupport, peerChatStre
325332
activeTransactions: NewActiveTransactions(),
326333
keepalive: chaincodeSupport.keepalive,
327334
userRunsCC: chaincodeSupport.userRunsCC,
335+
aclProvider: chaincodeSupport.ACLProvider,
328336
sccp: sccp,
329337
}
330338

core/chaincode/systemchaincode_test.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/hyperledger/fabric/common/util"
16+
"github.com/hyperledger/fabric/core/aclmgmt"
1617
"github.com/hyperledger/fabric/core/chaincode/accesscontrol"
1718
"github.com/hyperledger/fabric/core/chaincode/shim"
1819
"github.com/hyperledger/fabric/core/common/ccprovider"
@@ -121,7 +122,16 @@ func initSysCCTests() (*oldSysCCInfo, net.Listener, *ChaincodeSupport, error) {
121122
ccStartupTimeout := time.Duration(5000) * time.Millisecond
122123
ca, _ := accesscontrol.NewCA()
123124
certGenerator := accesscontrol.NewAuthenticator(ca)
124-
chaincodeSupport := NewChaincodeSupport(GlobalConfig(), peerAddress, false, ccStartupTimeout, ca.CertBytes(), certGenerator, &ccprovider.CCInfoFSImpl{})
125+
chaincodeSupport := NewChaincodeSupport(
126+
GlobalConfig(),
127+
peerAddress,
128+
false,
129+
ccStartupTimeout,
130+
ca.CertBytes(),
131+
certGenerator,
132+
&ccprovider.CCInfoFSImpl{},
133+
aclmgmt.GetACLProvider(),
134+
)
125135
pb.RegisterChaincodeSupportServer(grpcServer, chaincodeSupport)
126136

127137
go grpcServer.Serve(lis)

core/scc/cscc/configure_test.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,16 @@ func TestConfigerInvokeJoinChainCorrectParams(t *testing.T) {
195195
ccStartupTimeout := time.Duration(30000) * time.Millisecond
196196
ca, _ := accesscontrol.NewCA()
197197
certGenerator := accesscontrol.NewAuthenticator(ca)
198-
chaincode.NewChaincodeSupport(chaincode.GlobalConfig(), peerEndpoint, false, ccStartupTimeout, ca.CertBytes(), certGenerator, &ccprovider.CCInfoFSImpl{})
198+
chaincode.NewChaincodeSupport(
199+
chaincode.GlobalConfig(),
200+
peerEndpoint,
201+
false,
202+
ccStartupTimeout,
203+
ca.CertBytes(),
204+
certGenerator,
205+
&ccprovider.CCInfoFSImpl{},
206+
aclmgmt.GetACLProvider(),
207+
)
199208

200209
// Init the policy checker
201210
policyManagerGetter := &policymocks.MockChannelPolicyManagerGetter{

peer/node/start.go

+1
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ func registerChaincodeSupport(grpcServer *comm.GRPCServer, ccEndpoint string, ca
596596
ca.CertBytes(),
597597
authenticator,
598598
&ccprovider.CCInfoFSImpl{},
599+
aclmgmt.GetACLProvider(),
599600
)
600601
chaincode.SideEffectInitialize(chaincodeSupport)
601602

0 commit comments

Comments
 (0)