Skip to content

Commit

Permalink
[FAB-1575] Add orderer egress policy shared config
Browse files Browse the repository at this point in the history
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 <jyellick@us.ibm.com>
  • Loading branch information
Jason Yellick committed Jan 11, 2017
1 parent 1bf6190 commit 3737e31
Show file tree
Hide file tree
Showing 10 changed files with 170 additions and 27 deletions.
49 changes: 44 additions & 5 deletions bddtests/orderer/configuration_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions bddtests/steps/bootstrap_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ class BootstrapHelper:
KEY_CHAIN_CREATORS = "ChainCreators"
KEY_ACCEPT_ALL_POLICY = "AcceptAllPolicy"
KEY_INGRESS_POLICY = "IngressPolicy"
KEY_EGRESS_POLICY = "EgressPolicy"
KEY_BATCH_SIZE = "BatchSize"

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

def encodeEgressPolicy(self):
configItem = self.getConfigItem(
commonConfigType=common_dot_configuration_pb2.ConfigurationItem.ConfigurationType.Value("Orderer"),
key=BootstrapHelper.KEY_EGRESS_POLICY,
value=orderer_dot_configuration_pb2.EgressPolicy(name=BootstrapHelper.KEY_ACCEPT_ALL_POLICY).SerializeToString())
return self.signConfigItem(configItem)

def encodeIngressPolicy(self):
configItem = self.getConfigItem(
commonConfigType=common_dot_configuration_pb2.ConfigurationItem.ConfigurationType.Value("Orderer"),
Expand Down
2 changes: 2 additions & 0 deletions orderer/common/bootstrap/provisional/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (cbs *commonBootstrapper) makeGenesisConfigEnvelope() *cb.ConfigurationEnve
cbs.encodeChainCreators(),
cbs.encodeAcceptAllPolicy(),
cbs.encodeIngressPolicy(),
cbs.encodeEgressPolicy(),
cbs.lockDefaultModificationPolicy(),
)
}
Expand All @@ -42,6 +43,7 @@ func (kbs *kafkaBootstrapper) makeGenesisConfigEnvelope() *cb.ConfigurationEnvel
kbs.encodeChainCreators(),
kbs.encodeAcceptAllPolicy(),
kbs.encodeIngressPolicy(),
kbs.encodeEgressPolicy(),
kbs.lockDefaultModificationPolicy(),
)
}
10 changes: 10 additions & 0 deletions orderer/common/bootstrap/provisional/item.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ func (cbs *commonBootstrapper) encodeIngressPolicy() *cb.SignedConfigurationItem
return &cb.SignedConfigurationItem{ConfigurationItem: utils.MarshalOrPanic(configItem), Signatures: nil}
}

func (cbs *commonBootstrapper) encodeEgressPolicy() *cb.SignedConfigurationItem {
configItemKey := sharedconfig.EgressPolicyKey
configItemValue := utils.MarshalOrPanic(&ab.EgressPolicy{Name: AcceptAllPolicyKey})
modPolicy := configtx.DefaultModificationPolicyID

configItemChainHeader := utils.MakeChainHeader(cb.HeaderType_CONFIGURATION_ITEM, msgVersion, cbs.chainID, epoch)
configItem := utils.MakeConfigurationItem(configItemChainHeader, cb.ConfigurationItem_Orderer, lastModified, modPolicy, configItemKey, configItemValue)
return &cb.SignedConfigurationItem{ConfigurationItem: utils.MarshalOrPanic(configItem), Signatures: nil}
}

func (cbs *commonBootstrapper) lockDefaultModificationPolicy() *cb.SignedConfigurationItem {
// Lock down the default modification policy to prevent any further policy modifications
configItemKey := configtx.DefaultModificationPolicyID
Expand Down
18 changes: 18 additions & 0 deletions orderer/common/sharedconfig/sharedconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ const (

// IngressPolicyKey is the cb.ConfigurationItem type key name for the IngressPolicy message
IngressPolicyKey = "IngressPolicy"

// EgressPolicyKey is the cb.ConfigurationItem type key name for the EgressPolicy message
EgressPolicyKey = "EgressPolicy"
)

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

// IngressPolicy returns the name of the policy to validate incoming broadcast messages against
IngressPolicy() string

// EgressPolicy returns the name of the policy to validate incoming broadcast messages against
EgressPolicy() string
}

type ordererConfig struct {
Expand All @@ -86,6 +92,7 @@ type ordererConfig struct {
chainCreators []string
kafkaBrokers []string
ingressPolicy string
egressPolicy string
}

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

// EgressPolicy returns the name of the policy to validate incoming deliver seeks against
func (pm *ManagerImpl) EgressPolicy() string {
return pm.config.egressPolicy
}

// BeginConfig is used to start a new configuration proposal
func (pm *ManagerImpl) BeginConfig() {
if pm.pendingConfig != nil {
Expand Down Expand Up @@ -212,6 +224,12 @@ func (pm *ManagerImpl) ProposeConfig(configItem *cb.ConfigurationItem) error {
return fmt.Errorf("Unmarshaling error for IngressPolicy: %s", err)
}
pm.pendingConfig.ingressPolicy = ingressPolicy.Name
case EgressPolicyKey:
egressPolicy := &ab.EgressPolicy{}
if err := proto.Unmarshal(configItem.Value, egressPolicy); err != nil {
return fmt.Errorf("Unmarshaling error for EgressPolicy: %s", err)
}
pm.pendingConfig.egressPolicy = egressPolicy.Name
case KafkaBrokersKey:
kafkaBrokers := &ab.KafkaBrokers{}
if err := proto.Unmarshal(configItem.Value, kafkaBrokers); err != nil {
Expand Down
41 changes: 41 additions & 0 deletions orderer/common/sharedconfig/sharedconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,44 @@ func TestIngressPolicy(t *testing.T) {
t.Fatalf("IngressPolicy should have ended as %s but was %s", endPolicy, nowPolicy)
}
}

func TestEgressPolicy(t *testing.T) {
endPolicy := "foo"
invalidMessage :=
&cb.ConfigurationItem{
Type: cb.ConfigurationItem_Orderer,
Key: EgressPolicyKey,
Value: []byte("Garbage Data"),
}
validMessage := &cb.ConfigurationItem{
Type: cb.ConfigurationItem_Orderer,
Key: EgressPolicyKey,
Value: utils.MarshalOrPanic(&ab.EgressPolicy{Name: endPolicy}),
}
m := NewManagerImpl()
m.BeginConfig()

err := m.ProposeConfig(validMessage)
if err != nil {
t.Fatalf("Error applying valid config: %s", err)
}

m.CommitConfig()
m.BeginConfig()

err = m.ProposeConfig(invalidMessage)
if err == nil {
t.Fatalf("Should have failed on invalid message")
}

err = m.ProposeConfig(validMessage)
if err != nil {
t.Fatalf("Error re-applying valid config: %s", err)
}

m.CommitConfig()

if nowPolicy := m.EgressPolicy(); nowPolicy != endPolicy {
t.Fatalf("EgressPolicy should have ended as %s but was %s", endPolicy, nowPolicy)
}
}
7 changes: 7 additions & 0 deletions orderer/mocks/sharedconfig/sharedconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type Manager struct {
KafkaBrokersVal []string
// IngressPolicyVal is returned as the result of IngressPolicy()
IngressPolicyVal string
// EgressPolicyVal is returned as the result of EgressPolicy()
EgressPolicyVal string
}

// ConsensusType returns the ConsensusTypeVal
Expand Down Expand Up @@ -64,3 +66,8 @@ func (scm *Manager) KafkaBrokers() []string {
func (scm *Manager) IngressPolicy() string {
return scm.IngressPolicyVal
}

// EgressPolicy returns the EgressPolicyVal
func (scm *Manager) EgressPolicy() string {
return scm.EgressPolicyVal
}
1 change: 1 addition & 0 deletions protos/orderer/ab.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 34 additions & 22 deletions protos/orderer/configuration.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions protos/orderer/configuration.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ message IngressPolicy {
string name = 1;
}

// EgressPolicy is the name of the policy which incoming Deliver messages are filtered against
message EgressPolicy {
string name = 1;
}

message ChainCreators {
// A list of policies, any of which may be specified as the chain creation
// policy in a chain creation request
Expand Down

0 comments on commit 3737e31

Please sign in to comment.