Skip to content

Commit 3737e31

Browse files
author
Jason Yellick
committed
[FAB-1575] Add orderer egress policy shared config
https://jira.hyperledger.org/browse/FAB-1575 This changeset is the first in a series to enforce Deliver signatures. This changeset adds an orderer shared config item called EgressPolicy which is a reference to a backing policy which is to be used to filter deliver requests. Change-Id: I76443378f5c8ade31bd543c31d4093ded0684f73 Signed-off-by: Jason Yellick <[email protected]>
1 parent 1bf6190 commit 3737e31

File tree

10 files changed

+170
-27
lines changed

10 files changed

+170
-27
lines changed

bddtests/orderer/configuration_pb2.py

+44-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bddtests/steps/bootstrap_util.py

+8
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class BootstrapHelper:
229229
KEY_CHAIN_CREATORS = "ChainCreators"
230230
KEY_ACCEPT_ALL_POLICY = "AcceptAllPolicy"
231231
KEY_INGRESS_POLICY = "IngressPolicy"
232+
KEY_EGRESS_POLICY = "EgressPolicy"
232233
KEY_BATCH_SIZE = "BatchSize"
233234

234235
DEFAULT_MODIFICATION_POLICY_ID = "DefaultModificationPolicy"
@@ -296,6 +297,13 @@ def encodeChainCreators(self):
296297
value=orderer_dot_configuration_pb2.ChainCreators(policies=BootstrapHelper.DEFAULT_CHAIN_CREATORS).SerializeToString())
297298
return self.signConfigItem(configItem)
298299

300+
def encodeEgressPolicy(self):
301+
configItem = self.getConfigItem(
302+
commonConfigType=common_dot_configuration_pb2.ConfigurationItem.ConfigurationType.Value("Orderer"),
303+
key=BootstrapHelper.KEY_EGRESS_POLICY,
304+
value=orderer_dot_configuration_pb2.EgressPolicy(name=BootstrapHelper.KEY_ACCEPT_ALL_POLICY).SerializeToString())
305+
return self.signConfigItem(configItem)
306+
299307
def encodeIngressPolicy(self):
300308
configItem = self.getConfigItem(
301309
commonConfigType=common_dot_configuration_pb2.ConfigurationItem.ConfigurationType.Value("Orderer"),

orderer/common/bootstrap/provisional/envelope.go

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ func (cbs *commonBootstrapper) makeGenesisConfigEnvelope() *cb.ConfigurationEnve
2929
cbs.encodeChainCreators(),
3030
cbs.encodeAcceptAllPolicy(),
3131
cbs.encodeIngressPolicy(),
32+
cbs.encodeEgressPolicy(),
3233
cbs.lockDefaultModificationPolicy(),
3334
)
3435
}
@@ -42,6 +43,7 @@ func (kbs *kafkaBootstrapper) makeGenesisConfigEnvelope() *cb.ConfigurationEnvel
4243
kbs.encodeChainCreators(),
4344
kbs.encodeAcceptAllPolicy(),
4445
kbs.encodeIngressPolicy(),
46+
kbs.encodeEgressPolicy(),
4547
kbs.lockDefaultModificationPolicy(),
4648
)
4749
}

orderer/common/bootstrap/provisional/item.go

+10
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ func (cbs *commonBootstrapper) encodeIngressPolicy() *cb.SignedConfigurationItem
8585
return &cb.SignedConfigurationItem{ConfigurationItem: utils.MarshalOrPanic(configItem), Signatures: nil}
8686
}
8787

88+
func (cbs *commonBootstrapper) encodeEgressPolicy() *cb.SignedConfigurationItem {
89+
configItemKey := sharedconfig.EgressPolicyKey
90+
configItemValue := utils.MarshalOrPanic(&ab.EgressPolicy{Name: AcceptAllPolicyKey})
91+
modPolicy := configtx.DefaultModificationPolicyID
92+
93+
configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
94+
configItem := utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Orderer, lastModified, modPolicy, configItemKey, configItemValue)
95+
return &cb.SignedConfigurationItem{ConfigurationItem: utils.MarshalOrPanic(configItem), Signatures: nil}
96+
}
97+
8898
func (cbs *commonBootstrapper) lockDefaultModificationPolicy() *cb.SignedConfigurationItem {
8999
// Lock down the default modification policy to prevent any further policy modifications
90100
configItemKey := configtx.DefaultModificationPolicyID

orderer/common/sharedconfig/sharedconfig.go

+18
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ const (
4848

4949
// IngressPolicyKey is the cb.ConfigurationItem type key name for the IngressPolicy message
5050
IngressPolicyKey = "IngressPolicy"
51+
52+
// EgressPolicyKey is the cb.ConfigurationItem type key name for the EgressPolicy message
53+
EgressPolicyKey = "EgressPolicy"
5154
)
5255

5356
var logger = logging.MustGetLogger("orderer/common/sharedconfig")
@@ -77,6 +80,9 @@ type Manager interface {
7780

7881
// IngressPolicy returns the name of the policy to validate incoming broadcast messages against
7982
IngressPolicy() string
83+
84+
// EgressPolicy returns the name of the policy to validate incoming broadcast messages against
85+
EgressPolicy() string
8086
}
8187

8288
type ordererConfig struct {
@@ -86,6 +92,7 @@ type ordererConfig struct {
8692
chainCreators []string
8793
kafkaBrokers []string
8894
ingressPolicy string
95+
egressPolicy string
8996
}
9097

9198
// ManagerImpl is an implementation of Manager and configtx.ConfigHandler
@@ -135,6 +142,11 @@ func (pm *ManagerImpl) IngressPolicy() string {
135142
return pm.config.ingressPolicy
136143
}
137144

145+
// EgressPolicy returns the name of the policy to validate incoming deliver seeks against
146+
func (pm *ManagerImpl) EgressPolicy() string {
147+
return pm.config.egressPolicy
148+
}
149+
138150
// BeginConfig is used to start a new configuration proposal
139151
func (pm *ManagerImpl) BeginConfig() {
140152
if pm.pendingConfig != nil {
@@ -212,6 +224,12 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
212224
return fmt.Errorf("Unmarshaling error for IngressPolicy: %s", err)
213225
}
214226
pm.pendingConfig.ingressPolicy = ingressPolicy.Name
227+
case EgressPolicyKey:
228+
egressPolicy := &ab.EgressPolicy{}
229+
if err := proto.Unmarshal(configItem.Value, egressPolicy); err != nil {
230+
return fmt.Errorf("Unmarshaling error for EgressPolicy: %s", err)
231+
}
232+
pm.pendingConfig.egressPolicy = egressPolicy.Name
215233
case KafkaBrokersKey:
216234
kafkaBrokers := &ab.KafkaBrokers{}
217235
if err := proto.Unmarshal(configItem.Value, kafkaBrokers); err != nil {

orderer/common/sharedconfig/sharedconfig_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -339,3 +339,44 @@ func TestIngressPolicy(t *testing.T) {
339339
t.Fatalf("IngressPolicy should have ended as %s but was %s", endPolicy, nowPolicy)
340340
}
341341
}
342+
343+
func TestEgressPolicy(t *testing.T) {
344+
endPolicy := "foo"
345+
invalidMessage :=
346+
&cb.ConfigurationItem{
347+
Type: cb.ConfigurationItem_Orderer,
348+
Key: EgressPolicyKey,
349+
Value: []byte("Garbage Data"),
350+
}
351+
validMessage := &cb.ConfigurationItem{
352+
Type: cb.ConfigurationItem_Orderer,
353+
Key: EgressPolicyKey,
354+
Value: utils.MarshalOrPanic(&ab.EgressPolicy{Name: endPolicy}),
355+
}
356+
m := NewManagerImpl()
357+
m.BeginConfig()
358+
359+
err := m.ProposeConfig(validMessage)
360+
if err != nil {
361+
t.Fatalf("Error applying valid config: %s", err)
362+
}
363+
364+
m.CommitConfig()
365+
m.BeginConfig()
366+
367+
err = m.ProposeConfig(invalidMessage)
368+
if err == nil {
369+
t.Fatalf("Should have failed on invalid message")
370+
}
371+
372+
err = m.ProposeConfig(validMessage)
373+
if err != nil {
374+
t.Fatalf("Error re-applying valid config: %s", err)
375+
}
376+
377+
m.CommitConfig()
378+
379+
if nowPolicy := m.EgressPolicy(); nowPolicy != endPolicy {
380+
t.Fatalf("EgressPolicy should have ended as %s but was %s", endPolicy, nowPolicy)
381+
}
382+
}

orderer/mocks/sharedconfig/sharedconfig.go

+7
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ type Manager struct {
3333
KafkaBrokersVal []string
3434
// IngressPolicyVal is returned as the result of IngressPolicy()
3535
IngressPolicyVal string
36+
// EgressPolicyVal is returned as the result of EgressPolicy()
37+
EgressPolicyVal string
3638
}
3739

3840
// ConsensusType returns the ConsensusTypeVal
@@ -64,3 +66,8 @@ func (scm *Manager) KafkaBrokers() []string {
6466
func (scm *Manager) IngressPolicy() string {
6567
return scm.IngressPolicyVal
6668
}
69+
70+
// EgressPolicy returns the EgressPolicyVal
71+
func (scm *Manager) EgressPolicy() string {
72+
return scm.EgressPolicyVal
73+
}

protos/orderer/ab.pb.go

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/orderer/configuration.pb.go

+34-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protos/orderer/configuration.proto

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ message IngressPolicy {
6666
string name = 1;
6767
}
6868

69+
// EgressPolicy is the name of the policy which incoming Deliver messages are filtered against
70+
message EgressPolicy {
71+
string name = 1;
72+
}
73+
6974
message ChainCreators {
7075
// A list of policies, any of which may be specified as the chain creation
7176
// policy in a chain creation request

0 commit comments

Comments
 (0)