Skip to content

Commit 5fa00ff

Browse files
committed
[FAB-7604] Peer deliver unusable when pol. not defined
After FAB-7521, the peer deliver service is unusable because the BLOCKEVENT policy is not set by default. This CR uses the aclmgmt package, which will check for the policy and, if not set, use the default value (in this case, channel readers). It also restores the behave tests to their previous state to ensure peer deliver remains usable by default. Change-Id: I46e71853881271539e28a110ce8b81d3bd248d19 Signed-off-by: Will Lahti <wtlahti@us.ibm.com>
1 parent 4f1235a commit 5fa00ff

File tree

8 files changed

+73
-108
lines changed

8 files changed

+73
-108
lines changed

bddtests/features/bootstrap.feature

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ Feature: Bootstrap
254254
| ChainId | Start | End |
255255
| com.acme.blockchain.jdoe.channel1 | 0 | 0 |
256256

257-
Then user "dev0Org0" should get a delivery "genesisBlockForMyNewChannel" from "peer0" of "0" blocks with "0" messages within "1" seconds
257+
Then user "dev0Org0" should get a delivery "genesisBlockForMyNewChannel" from "peer0" of "1" blocks with "1" messages within "1" seconds
258258

259259
When user "dev0Org0" using cert alias "consortium1-cert" connects to deliver function on orderer "peer2" using port "7051"
260260
And user "dev0Org0" sends deliver a seek request on orderer "peer2" with properties:
261261
| ChainId | Start | End |
262262
| com.acme.blockchain.jdoe.channel1 | 0 | 0 |
263263

264-
Then user "dev0Org0" should get a delivery "genesisBlockForMyNewChannelFromOtherOrgsPeer" from "peer2" of "0" blocks with "0" messages within "1" seconds
264+
Then user "dev0Org0" should get a delivery "genesisBlockForMyNewChannelFromOtherOrgsPeer" from "peer2" of "1" blocks with "1" messages within "1" seconds
265265

266266
# Entry point for invoking on an existing channel
267267
When user "peer0Admin" creates a chaincode spec "ccSpec" with name "example02" of type "GOLANG" for chaincode "github.com/hyperledger/fabric/examples/chaincode/go/chaincode_example02" with args

common/config/api.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ SPDX-License-Identifier: Apache-2.0
66
package config
77

88
import (
9-
"github.com/hyperledger/fabric/common/resourcesconfig"
109
cb "github.com/hyperledger/fabric/protos/common"
1110
)
1211

@@ -26,7 +25,4 @@ type Manager interface {
2625

2726
// GetResourceConfig defines methods that are related to resource configuration
2827
GetResourceConfig(channel string) Config
29-
30-
// GetPolicyMapper returns API to the policy mapper
31-
GetPolicyMapper(channel string) resourcesconfig.PolicyMapper
3228
}

common/deliver/deliver.go

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,19 @@ type Support interface {
6868
Errored() <-chan struct{}
6969
}
7070

71-
// PolicyNameProvider provides a policy name given the channel id
72-
type PolicyNameProvider func(chainID string) (string, error)
71+
// PolicyChecker checks the envelope against the policy logic supplied by the
72+
// function
73+
type PolicyChecker func(envelope *cb.Envelope, channelID string) error
7374

7475
type deliverServer struct {
7576
sm SupportManager
76-
policyProvider PolicyNameProvider
77+
policyChecker PolicyChecker
7778
timeWindow time.Duration
7879
bindingInspector comm.BindingInspector
7980
}
8081

8182
// NewHandlerImpl creates an implementation of the Handler interface
82-
func NewHandlerImpl(sm SupportManager, policyProvider PolicyNameProvider, timeWindow time.Duration, mutualTLS bool) Handler {
83+
func NewHandlerImpl(sm SupportManager, policyChecker PolicyChecker, timeWindow time.Duration, mutualTLS bool) Handler {
8384
// function to extract the TLS cert hash from a channel header
8485
extract := func(msg proto.Message) []byte {
8586
chdr, isChannelHeader := msg.(*cb.ChannelHeader)
@@ -92,7 +93,7 @@ func NewHandlerImpl(sm SupportManager, policyProvider PolicyNameProvider, timeWi
9293

9394
return &deliverServer{
9495
sm: sm,
95-
policyProvider: policyProvider,
96+
policyChecker: policyChecker,
9697
timeWindow: timeWindow,
9798
bindingInspector: bindingInspector,
9899
}
@@ -166,13 +167,7 @@ func (ds *deliverServer) deliverBlocks(srv ab.AtomicBroadcast_DeliverServer, env
166167

167168
lastConfigSequence := chain.Sequence()
168169

169-
policyName, err := ds.policyProvider(chdr.ChannelId)
170-
if err != nil {
171-
logger.Warningf("[channel: %s] failed to obtain policy name due to %s", chdr.ChannelId, err)
172-
return sendStatusReply(srv, cb.Status_BAD_REQUEST)
173-
}
174-
sf := NewSigFilter(policyName, chain)
175-
if err := sf.Apply(envelope); err != nil {
170+
if err := ds.policyChecker(envelope, chdr.ChannelId); err != nil {
176171
logger.Warningf("[channel: %s] Received unauthorized deliver request from %s: %s", chdr.ChannelId, addr, err)
177172
return sendStatusReply(srv, cb.Status_FORBIDDEN)
178173
}
@@ -225,7 +220,7 @@ func (ds *deliverServer) deliverBlocks(srv ab.AtomicBroadcast_DeliverServer, env
225220
currentConfigSequence := chain.Sequence()
226221
if currentConfigSequence > lastConfigSequence {
227222
lastConfigSequence = currentConfigSequence
228-
if err := sf.Apply(envelope); err != nil {
223+
if err := ds.policyChecker(envelope, chdr.ChannelId); err != nil {
229224
logger.Warningf("[channel: %s] Client authorization revoked for deliver request from %s: %s", chdr.ChannelId, addr, err)
230225
return sendStatusReply(srv, cb.Status_FORBIDDEN)
231226
}

0 commit comments

Comments
 (0)