Skip to content

Commit 6c28c83

Browse files
author
Jason Yellick
committed
[FAB-2615] Remove Ingress/EgressPolicyNames refs
https://jira.hyperledger.org/browse/FAB-2615 Now that the hierarchical config and policies are in place, the old style of specifying ingress and egress policies is wrong. This CR switches the orderer to use the ChannelReaders and ChannelWriters policies instead of the Ingress/Egress policy names and removes the references to those now removed config policies. Change-Id: Ie818bfc37bb5d2b4eb55addaf76ac510a2fdfd4b Signed-off-by: Jason Yellick <[email protected]>
1 parent 2a6a7b5 commit 6c28c83

File tree

15 files changed

+57
-165
lines changed

15 files changed

+57
-165
lines changed

common/configtx/tool/provisional/provisional.go

-2
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ func New(conf *genesisconfig.Profile) Generator {
107107
PreferredMaxBytes: conf.Orderer.BatchSize.PreferredMaxBytes,
108108
}),
109109
configtxorderer.TemplateBatchTimeout(conf.Orderer.BatchTimeout.String()),
110-
configtxorderer.TemplateIngressPolicyNames([]string{AcceptAllPolicyKey}),
111-
configtxorderer.TemplateEgressPolicyNames([]string{AcceptAllPolicyKey}),
112110

113111
// Initialize the default Reader/Writer/Admins orderer policies, as well as block validation policy
114112
policies.TemplateImplicitMetaPolicyWithSubPolicy([]string{configtxorderer.GroupKey}, BlockValidationPolicyKey, configvaluesmsp.WritersPolicyKey, cb.ImplicitMetaPolicy_ANY),

common/configvalues/api.go

-6
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ type Orderer interface {
6868
// Kafka brokers, i.e. this is not necessarily the entire set of Kafka brokers
6969
// used for ordering
7070
KafkaBrokers() []string
71-
72-
// IngressPolicyNames returns the name of the policy to validate incoming broadcast messages against
73-
IngressPolicyNames() []string
74-
75-
// EgressPolicyNames returns the name of the policy to validate incoming broadcast messages against
76-
EgressPolicyNames() []string
7771
}
7872

7973
type ValueProposer interface {

common/configvalues/channel/orderer/sharedconfig.go

-32
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,6 @@ var Schema = &cb.ConfigGroupSchema{
5858
BatchTimeoutKey: nil,
5959
ChainCreationPolicyNamesKey: nil,
6060
KafkaBrokersKey: nil,
61-
IngressPolicyNamesKey: nil,
62-
EgressPolicyNamesKey: nil,
6361
},
6462
Policies: map[string]*cb.ConfigPolicySchema{
6563
// TODO, set appropriately once hierarchical policies are implemented
@@ -81,12 +79,6 @@ const (
8179

8280
// KafkaBrokersKey is the cb.ConfigItem type key name for the KafkaBrokers message
8381
KafkaBrokersKey = "KafkaBrokers"
84-
85-
// IngressPolicyNamesKey is the cb.ConfigItem type key name for the IngressPolicyNames message
86-
IngressPolicyNamesKey = "IngressPolicyNames"
87-
88-
// EgressPolicyNamesKey is the cb.ConfigItem type key name for the EgressPolicyNames message
89-
EgressPolicyNamesKey = "EgressPolicyNames"
9082
)
9183

9284
var logger = logging.MustGetLogger("configtx/handlers/orderer")
@@ -97,8 +89,6 @@ type ordererConfig struct {
9789
batchTimeout time.Duration
9890
chainCreationPolicyNames []string
9991
kafkaBrokers []string
100-
ingressPolicyNames []string
101-
egressPolicyNames []string
10292
orgs map[string]*organization.OrgConfig
10393
}
10494

@@ -146,16 +136,6 @@ func (pm *ManagerImpl) KafkaBrokers() []string {
146136
return pm.config.kafkaBrokers
147137
}
148138

149-
// IngressPolicyNames returns the name of the policy to validate incoming broadcast messages against
150-
func (pm *ManagerImpl) IngressPolicyNames() []string {
151-
return pm.config.ingressPolicyNames
152-
}
153-
154-
// EgressPolicyNames returns the name of the policy to validate incoming deliver seeks against
155-
func (pm *ManagerImpl) EgressPolicyNames() []string {
156-
return pm.config.egressPolicyNames
157-
}
158-
159139
// BeginValueProposals is used to start a new config proposal
160140
func (pm *ManagerImpl) BeginValueProposals(groups []string) ([]api.ValueProposer, error) {
161141
logger.Debugf("Beginning a possible new orderer shared config")
@@ -255,18 +235,6 @@ func (pm *ManagerImpl) ProposeValue(key string, configValue *cb.ConfigValue) err
255235
} else {
256236
pm.pendingConfig.chainCreationPolicyNames = chainCreationPolicyNames.Names
257237
}
258-
case IngressPolicyNamesKey:
259-
ingressPolicyNames := &ab.IngressPolicyNames{}
260-
if err := proto.Unmarshal(configValue.Value, ingressPolicyNames); err != nil {
261-
return fmt.Errorf("Unmarshaling error for IngressPolicyNames: %s", err)
262-
}
263-
pm.pendingConfig.ingressPolicyNames = ingressPolicyNames.Names
264-
case EgressPolicyNamesKey:
265-
egressPolicyNames := &ab.EgressPolicyNames{}
266-
if err := proto.Unmarshal(configValue.Value, egressPolicyNames); err != nil {
267-
return fmt.Errorf("Unmarshaling error for EgressPolicyNames: %s", err)
268-
}
269-
pm.pendingConfig.egressPolicyNames = egressPolicyNames.Names
270238
case KafkaBrokersKey:
271239
kafkaBrokers := &ab.KafkaBrokers{}
272240
if err := proto.Unmarshal(configValue.Value, kafkaBrokers); err != nil {

common/configvalues/channel/orderer/sharedconfig_test.go

-10
Original file line numberDiff line numberDiff line change
@@ -310,16 +310,6 @@ func testPolicyNames(m *ManagerImpl, key string, initializer func(val []string)
310310
}
311311
}
312312

313-
func TestIngressPolicyNames(t *testing.T) {
314-
m := NewManagerImpl(nil)
315-
testPolicyNames(m, IngressPolicyNamesKey, TemplateIngressPolicyNames, m.IngressPolicyNames, t)
316-
}
317-
318-
func TestEgressPolicyNames(t *testing.T) {
319-
m := NewManagerImpl(nil)
320-
testPolicyNames(m, EgressPolicyNamesKey, TemplateEgressPolicyNames, m.EgressPolicyNames, t)
321-
}
322-
323313
func TestChainCreationPolicyNames(t *testing.T) {
324314
m := NewManagerImpl(nil)
325315
testPolicyNames(m, ChainCreationPolicyNamesKey, TemplateChainCreationPolicyNames, m.ChainCreationPolicyNames, t)

common/configvalues/channel/orderer/sharedconfig_util.go

-10
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,6 @@ func TemplateChainCreationPolicyNames(names []string) *cb.ConfigGroup {
5151
return configGroup(ChainCreationPolicyNamesKey, utils.MarshalOrPanic(&ab.ChainCreationPolicyNames{Names: names}))
5252
}
5353

54-
// TemplateIngressPolicyNames creates a headerless config item representing the ingress policy names
55-
func TemplateIngressPolicyNames(names []string) *cb.ConfigGroup {
56-
return configGroup(IngressPolicyNamesKey, utils.MarshalOrPanic(&ab.IngressPolicyNames{Names: names}))
57-
}
58-
59-
// TemplateEgressPolicyNames creates a headerless config item representing the egress policy names
60-
func TemplateEgressPolicyNames(names []string) *cb.ConfigGroup {
61-
return configGroup(EgressPolicyNamesKey, utils.MarshalOrPanic(&ab.EgressPolicyNames{Names: names}))
62-
}
63-
6454
// TemplateKafkaBrokers creates a headerless config item representing the kafka brokers
6555
func TemplateKafkaBrokers(brokers []string) *cb.ConfigGroup {
6656
return configGroup(KafkaBrokersKey, utils.MarshalOrPanic(&ab.KafkaBrokers{Brokers: brokers}))

common/policies/policy.go

+14
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ const (
3838
// OrdererPrefix is used in the path of standard orderer policy paths
3939
OrdererPrefix = "Orderer"
4040

41+
// ChannelReaders is the label for the channel's readers policy (encompassing both orderer and application readers)
42+
ChannelReaders = PathSeparator + ChannelPrefix + PathSeparator + "Readers"
43+
44+
// ChannelWriters is the label for the channel's writers policy (encompassing both orderer and application writers)
45+
ChannelWriters = PathSeparator + ChannelPrefix + PathSeparator + "Writers"
46+
4147
// ChannelApplicationReaders is the label for the channel's application readers policy
4248
ChannelApplicationReaders = PathSeparator + ChannelPrefix + PathSeparator + ApplicationPrefix + PathSeparator + "Readers"
4349

@@ -266,6 +272,14 @@ func (pm *ManagerImpl) CommitProposals() {
266272
pm.pendingConfig = nil
267273

268274
if pm.parent == nil && pm.basePath == ChannelPrefix {
275+
for _, policyName := range []string{ChannelReaders, ChannelWriters} {
276+
_, ok := pm.GetPolicy(policyName)
277+
if !ok {
278+
logger.Warningf("Current configuration has no policy '%s', this will likely cause problems in production systems", policyName)
279+
} else {
280+
logger.Debugf("As expected, current configuration has policy '%s'", policyName)
281+
}
282+
}
269283
if _, ok := pm.config.managers[ApplicationPrefix]; ok {
270284
// Check for default application policies if the application component is defined
271285
for _, policyName := range []string{

orderer/common/deliver/deliver.go

+1-5
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package deliver
1919
import (
2020
"fmt"
2121

22-
configvaluesapi "github.com/hyperledger/fabric/common/configvalues"
2322
"github.com/hyperledger/fabric/common/policies"
2423
"github.com/hyperledger/fabric/orderer/common/filter"
2524
"github.com/hyperledger/fabric/orderer/common/sigfilter"
@@ -51,9 +50,6 @@ type Support interface {
5150

5251
// Reader returns the chain Reader for the chain
5352
Reader() ledger.Reader
54-
55-
// SharedConfig returns the shared config manager for this chain
56-
SharedConfig() configvaluesapi.Orderer
5753
}
5854

5955
type deliverServer struct {
@@ -99,7 +95,7 @@ func (ds *deliverServer) Handle(srv ab.AtomicBroadcast_DeliverServer) error {
9995
return sendStatusReply(srv, cb.Status_NOT_FOUND)
10096
}
10197

102-
sf := sigfilter.New(chain.SharedConfig().EgressPolicyNames, chain.PolicyManager())
98+
sf := sigfilter.New(policies.ChannelReaders, chain.PolicyManager())
10399
result, _ := sf.Apply(envelope)
104100
if result != filter.Forward {
105101
return sendStatusReply(srv, cb.Status_FORBIDDEN)

orderer/common/deliver/deliver_test.go

-8
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ import (
2222
"time"
2323

2424
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
25-
configvaluesapi "github.com/hyperledger/fabric/common/configvalues"
26-
mockconfigvaluesorderer "github.com/hyperledger/fabric/common/mocks/configvalues/channel/orderer"
2725
mockpolicies "github.com/hyperledger/fabric/common/mocks/policies"
2826
"github.com/hyperledger/fabric/common/policies"
2927
"github.com/hyperledger/fabric/orderer/ledger"
@@ -82,7 +80,6 @@ func (mm *mockSupportManager) GetChain(chainID string) (Support, bool) {
8280

8381
type mockSupport struct {
8482
ledger ledger.ReadWriter
85-
sharedConfig *mockconfigvaluesorderer.SharedConfig
8683
policyManager *mockpolicies.Manager
8784
}
8885

@@ -101,18 +98,13 @@ func NewRAMLedger() ledger.ReadWriter {
10198
return rl
10299
}
103100

104-
func (mcs *mockSupport) SharedConfig() configvaluesapi.Orderer {
105-
return mcs.sharedConfig
106-
}
107-
108101
func newMockMultichainManager() *mockSupportManager {
109102
rl := NewRAMLedger()
110103
mm := &mockSupportManager{
111104
chains: make(map[string]*mockSupport),
112105
}
113106
mm.chains[systemChainID] = &mockSupport{
114107
ledger: rl,
115-
sharedConfig: &mockconfigvaluesorderer.SharedConfig{EgressPolicyNamesVal: []string{"somePolicy"}},
116108
policyManager: &mockpolicies.Manager{Policy: &mockpolicies.Policy{}},
117109
}
118110
return mm

orderer/common/sigfilter/sigfilter.go

+13-15
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
var logger = logging.MustGetLogger("orderer/common/sigfilter")
2828

2929
type sigFilter struct {
30-
policySource func() []string
30+
policySource string
3131
policyManager policies.Manager
3232
}
3333

@@ -36,7 +36,7 @@ type sigFilter struct {
3636
// In general, both the policy name and the policy itself are mutable, this is why
3737
// not only the policy is retrieved at each invocation, but also the name of which
3838
// policy to retrieve
39-
func New(policySource func() []string, policyManager policies.Manager) filter.Rule {
39+
func New(policySource string, policyManager policies.Manager) filter.Rule {
4040
return &sigFilter{
4141
policySource: policySource,
4242
policyManager: policyManager,
@@ -54,24 +54,22 @@ func (sf *sigFilter) Apply(message *cb.Envelope) (filter.Action, filter.Committe
5454
return filter.Reject, nil
5555
}
5656

57-
for _, policy := range sf.policySource() {
58-
policy, ok := sf.policyManager.GetPolicy(policy)
59-
if !ok {
60-
logger.Debugf("Could not find policy %s", policy)
61-
continue
57+
policy, ok := sf.policyManager.GetPolicy(sf.policySource)
58+
if !ok {
59+
if logger.IsEnabledFor(logging.DEBUG) {
60+
logger.Debugf("Could not find policy %s", sf.policySource)
6261
}
62+
return filter.Reject, nil
63+
}
6364

64-
err = policy.Evaluate(signedData)
65+
err = policy.Evaluate(signedData)
6566

66-
if err == nil {
67-
logger.Debugf("Accepting validly signed message for policy %s", policy)
68-
return filter.Forward, nil
67+
if err == nil {
68+
if logger.IsEnabledFor(logging.DEBUG) {
69+
logger.Debugf("Forwarding validly signed message for policy %s", policy)
6970
}
70-
71+
return filter.Forward, nil
7172
}
7273

73-
if logger.IsEnabledFor(logging.DEBUG) {
74-
logger.Debugf("Rejecting message because it was not appropriately signed for any allowed policy among %s", sf.policySource())
75-
}
7674
return filter.Reject, nil
7775
}

orderer/common/sigfilter/sigfilter_test.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,9 @@ func makeEnvelope() *cb.Envelope {
4242
}
4343
}
4444

45-
func fooSource() []string {
46-
return []string{"foo"}
47-
}
48-
4945
func TestAccept(t *testing.T) {
5046
mpm := &mockpolicies.Manager{Policy: &mockpolicies.Policy{}}
51-
sf := New(fooSource, mpm)
47+
sf := New("foo", mpm)
5248
result, _ := sf.Apply(makeEnvelope())
5349
if result != filter.Forward {
5450
t.Fatalf("Should have accepted envelope")
@@ -57,7 +53,7 @@ func TestAccept(t *testing.T) {
5753

5854
func TestMissingPolicy(t *testing.T) {
5955
mpm := &mockpolicies.Manager{}
60-
sf := New(fooSource, mpm)
56+
sf := New("foo", mpm)
6157
result, _ := sf.Apply(makeEnvelope())
6258
if result != filter.Reject {
6359
t.Fatalf("Should have rejected when missing policy")
@@ -66,7 +62,7 @@ func TestMissingPolicy(t *testing.T) {
6662

6763
func TestEmptyPayload(t *testing.T) {
6864
mpm := &mockpolicies.Manager{Policy: &mockpolicies.Policy{}}
69-
sf := New(fooSource, mpm)
65+
sf := New("foo", mpm)
7066
result, _ := sf.Apply(&cb.Envelope{})
7167
if result != filter.Reject {
7268
t.Fatalf("Should have rejected when payload empty")
@@ -75,7 +71,7 @@ func TestEmptyPayload(t *testing.T) {
7571

7672
func TestErrorOnPolicy(t *testing.T) {
7773
mpm := &mockpolicies.Manager{Policy: &mockpolicies.Policy{Err: fmt.Errorf("Error")}}
78-
sf := New(fooSource, mpm)
74+
sf := New("foo", mpm)
7975
result, _ := sf.Apply(makeEnvelope())
8076
if result != filter.Reject {
8177
t.Fatalf("Should have rejected when policy evaluated to err")

orderer/multichain/chainsupport.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ func createStandardFilters(ledgerResources *ledgerResources) *filter.RuleSet {
145145
return filter.NewRuleSet([]filter.Rule{
146146
filter.EmptyRejectRule,
147147
sizefilter.MaxBytesRule(ledgerResources.SharedConfig().BatchSize().AbsoluteMaxBytes),
148-
sigfilter.New(ledgerResources.SharedConfig().IngressPolicyNames, ledgerResources.PolicyManager()),
148+
sigfilter.New(policies.ChannelWriters, ledgerResources.PolicyManager()),
149149
configtxfilter.NewFilter(ledgerResources),
150150
filter.AcceptRule,
151151
})
@@ -157,7 +157,7 @@ func createSystemChainFilters(ml *multiLedger, ledgerResources *ledgerResources)
157157
return filter.NewRuleSet([]filter.Rule{
158158
filter.EmptyRejectRule,
159159
sizefilter.MaxBytesRule(ledgerResources.SharedConfig().BatchSize().AbsoluteMaxBytes),
160-
sigfilter.New(ledgerResources.SharedConfig().IngressPolicyNames, ledgerResources.PolicyManager()),
160+
sigfilter.New(policies.ChannelWriters, ledgerResources.PolicyManager()),
161161
newSystemChainFilter(ledgerResources, ml),
162162
configtxfilter.NewFilter(ledgerResources),
163163
filter.AcceptRule,

orderer/multichain/manager_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
"time"
2323

2424
"github.com/hyperledger/fabric/common/configtx"
25-
configtxtest "github.com/hyperledger/fabric/common/configtx/test"
2625
genesisconfig "github.com/hyperledger/fabric/common/configtx/tool/localconfig"
2726
"github.com/hyperledger/fabric/common/configtx/tool/provisional"
2827
mockcrypto "github.com/hyperledger/fabric/common/mocks/crypto"
@@ -241,7 +240,7 @@ func TestNewChain(t *testing.T) {
241240

242241
newChainID := "TestNewChain"
243242

244-
configEnv, err := configtx.NewChainCreationTemplate(provisional.AcceptAllPolicyKey, configtxtest.CompositeTemplate()).Envelope(newChainID)
243+
configEnv, err := configtx.NewChainCreationTemplate(provisional.AcceptAllPolicyKey, provisional.New(conf).ChannelTemplate()).Envelope(newChainID)
245244
if err != nil {
246245
t.Fatalf("Error constructing configtx")
247246
}

protos/orderer/ab.pb.go

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

0 commit comments

Comments
 (0)