Skip to content

Commit 5435d21

Browse files
author
Jason Yellick
committed
[FAB-4418] Fix confusing policy naming
When traversing the JSON tree as generated by configtxlator, the following list of elements is encountered: policies -> <name> -> policy -> policy -> policy -> n_out_of -> policies This is understandably very confusing for users, as so many different elements claim to represent a policy. This CR modifies the policy definitions so that instead that same list of elements becomes: policies -> <name> -> policy -> value -> rule -> n_out_of -> rules This makes it much more clear that the third element is a named policy, and that the policy has a value, consisting of a rule, which itself may be composed of other rules. The consumers of the existing name scheme are restricted to those users of configtxlator or those who have manually attempted to build these messages (I am unaware of any). This is not an ABI breakage, although because of the nature of the bug it is an API breakage. Change-Id: Ia0d99f6e08ce43bc2563dc2caf9de9fd512af191 Signed-off-by: Jason Yellick <[email protected]>
1 parent c2d3898 commit 5435d21

22 files changed

+283
-138
lines changed

common/cauthdsl/cauthdsl.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ var cauthdslLogger = flogging.MustGetLogger("cauthdsl")
3131
func compile(policy *cb.SignaturePolicy, identities []*mb.MSPPrincipal, deserializer msp.IdentityDeserializer) (func([]*cb.SignedData, []bool) bool, error) {
3232
switch t := policy.Type.(type) {
3333
case *cb.SignaturePolicy_NOutOf_:
34-
policies := make([]func([]*cb.SignedData, []bool) bool, len(t.NOutOf.Policies))
35-
for i, policy := range t.NOutOf.Policies {
34+
policies := make([]func([]*cb.SignedData, []bool) bool, len(t.NOutOf.Rules))
35+
for i, policy := range t.NOutOf.Rules {
3636
compiledPolicy, err := compile(policy, identities, deserializer)
3737
if err != nil {
3838
return nil, err

common/cauthdsl/cauthdsl_builder.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func Envelope(policy *cb.SignaturePolicy, identities [][]byte) *cb.SignaturePoli
6363

6464
return &cb.SignaturePolicyEnvelope{
6565
Version: 0,
66-
Policy: policy,
66+
Rule: policy,
6767
Identities: ids,
6868
}
6969
}
@@ -88,7 +88,7 @@ func SignedByMspMember(mspId string) *cb.SignaturePolicyEnvelope {
8888
// create the policy: it requires exactly 1 signature from the first (and only) principal
8989
p := &cb.SignaturePolicyEnvelope{
9090
Version: 0,
91-
Policy: NOutOf(1, []*cb.SignaturePolicy{SignedBy(0)}),
91+
Rule: NOutOf(1, []*cb.SignaturePolicy{SignedBy(0)}),
9292
Identities: []*msp.MSPPrincipal{principal},
9393
}
9494

@@ -106,7 +106,7 @@ func SignedByMspAdmin(mspId string) *cb.SignaturePolicyEnvelope {
106106
// create the policy: it requires exactly 1 signature from the first (and only) principal
107107
p := &cb.SignaturePolicyEnvelope{
108108
Version: 0,
109-
Policy: NOutOf(1, []*cb.SignaturePolicy{SignedBy(0)}),
109+
Rule: NOutOf(1, []*cb.SignaturePolicy{SignedBy(0)}),
110110
Identities: []*msp.MSPPrincipal{principal},
111111
}
112112

@@ -130,7 +130,7 @@ func signedByAnyOfGivenRole(role msp.MSPRole_MSPRoleType, ids []string) *cb.Sign
130130
// create the policy: it requires exactly 1 signature from any of the principals
131131
p := &cb.SignaturePolicyEnvelope{
132132
Version: 0,
133-
Policy: NOutOf(1, sigspolicy),
133+
Rule: NOutOf(1, sigspolicy),
134134
Identities: principals,
135135
}
136136

@@ -166,8 +166,8 @@ func NOutOf(n int32, policies []*cb.SignaturePolicy) *cb.SignaturePolicy {
166166
return &cb.SignaturePolicy{
167167
Type: &cb.SignaturePolicy_NOutOf_{
168168
NOutOf: &cb.SignaturePolicy_NOutOf{
169-
N: n,
170-
Policies: policies,
169+
N: n,
170+
Rules: policies,
171171
},
172172
},
173173
}

common/cauthdsl/cauthdsl_test.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ var moreMsgs = [][]byte{nil, nil, nil}
9797
func TestSimpleSignature(t *testing.T) {
9898
policy := Envelope(SignedBy(0), signers)
9999

100-
spe, err := compile(policy.Policy, policy.Identities, &mockDeserializer{})
100+
spe, err := compile(policy.Rule, policy.Identities, &mockDeserializer{})
101101
if err != nil {
102102
t.Fatalf("Could not create a new SignaturePolicyEvaluator using the given policy, crypto-helper: %s", err)
103103
}
@@ -116,7 +116,7 @@ func TestSimpleSignature(t *testing.T) {
116116
func TestMultipleSignature(t *testing.T) {
117117
policy := Envelope(And(SignedBy(0), SignedBy(1)), signers)
118118

119-
spe, err := compile(policy.Policy, policy.Identities, &mockDeserializer{})
119+
spe, err := compile(policy.Rule, policy.Identities, &mockDeserializer{})
120120
if err != nil {
121121
t.Fatalf("Could not create a new SignaturePolicyEvaluator using the given policy, crypto-helper: %s", err)
122122
}
@@ -135,7 +135,7 @@ func TestMultipleSignature(t *testing.T) {
135135
func TestComplexNestedSignature(t *testing.T) {
136136
policy := Envelope(And(Or(And(SignedBy(0), SignedBy(1)), And(SignedBy(0), SignedBy(0))), SignedBy(0)), signers)
137137

138-
spe, err := compile(policy.Policy, policy.Identities, &mockDeserializer{})
138+
spe, err := compile(policy.Rule, policy.Identities, &mockDeserializer{})
139139
if err != nil {
140140
t.Fatalf("Could not create a new SignaturePolicyEvaluator using the given policy, crypto-helper: %s", err)
141141
}
@@ -159,11 +159,11 @@ func TestComplexNestedSignature(t *testing.T) {
159159

160160
func TestNegatively(t *testing.T) {
161161
rpolicy := Envelope(And(SignedBy(0), SignedBy(1)), signers)
162-
rpolicy.Policy.Type = nil
162+
rpolicy.Rule.Type = nil
163163
b, _ := proto.Marshal(rpolicy)
164164
policy := &cb.SignaturePolicyEnvelope{}
165165
_ = proto.Unmarshal(b, policy)
166-
_, err := compile(policy.Policy, policy.Identities, &mockDeserializer{})
166+
_, err := compile(policy.Rule, policy.Identities, &mockDeserializer{})
167167
if err == nil {
168168
t.Fatal("Should have errored compiling because the Type field was nil")
169169
}

common/cauthdsl/policy.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (pr *provider) NewPolicy(data []byte) (policies.Policy, proto.Message, erro
4949
return nil, nil, fmt.Errorf("This evaluator only understands messages of version 0, but version was %d", sigPolicy.Version)
5050
}
5151

52-
compiled, err := compile(sigPolicy.Policy, sigPolicy.Identities, pr.deserializer)
52+
compiled, err := compile(sigPolicy.Rule, sigPolicy.Identities, pr.deserializer)
5353
if err != nil {
5454
return nil, nil, err
5555
}

common/cauthdsl/policy_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func makePolicySource(policyResult bool) *cb.Policy {
5151
policyData = RejectAllPolicy
5252
}
5353
return &cb.Policy{
54-
Type: int32(cb.Policy_SIGNATURE),
55-
Policy: marshalOrPanic(policyData),
54+
Type: int32(cb.Policy_SIGNATURE),
55+
Value: marshalOrPanic(policyData),
5656
}
5757
}
5858

common/cauthdsl/policy_util.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func TemplatePolicy(key string, sigPolicyEnv *cb.SignaturePolicyEnvelope) *cb.Co
2626
configGroup := cb.NewConfigGroup()
2727
configGroup.Policies[key] = &cb.ConfigPolicy{
2828
Policy: &cb.Policy{
29-
Type: int32(cb.Policy_SIGNATURE),
30-
Policy: utils.MarshalOrPanic(sigPolicyEnv),
29+
Type: int32(cb.Policy_SIGNATURE),
30+
Value: utils.MarshalOrPanic(sigPolicyEnv),
3131
},
3232
}
3333
return configGroup

common/cauthdsl/policyparser.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ func FromString(policy string) (*common.SignaturePolicyEnvelope, error) {
272272
p := &common.SignaturePolicyEnvelope{
273273
Identities: ctx.principals,
274274
Version: 0,
275-
Policy: res.(*common.SignaturePolicy),
275+
Rule: res.(*common.SignaturePolicy),
276276
}
277277

278278
return p, nil

common/cauthdsl/policyparser_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func TestAnd(t *testing.T) {
4242

4343
p2 := &common.SignaturePolicyEnvelope{
4444
Version: 0,
45-
Policy: And(SignedBy(0), SignedBy(1)),
45+
Rule: And(SignedBy(0), SignedBy(1)),
4646
Identities: principals,
4747
}
4848

@@ -65,7 +65,7 @@ func TestOr(t *testing.T) {
6565

6666
p2 := &common.SignaturePolicyEnvelope{
6767
Version: 0,
68-
Policy: Or(SignedBy(0), SignedBy(1)),
68+
Rule: Or(SignedBy(0), SignedBy(1)),
6969
Identities: principals,
7070
}
7171

@@ -92,7 +92,7 @@ func TestComplex1(t *testing.T) {
9292

9393
p2 := &common.SignaturePolicyEnvelope{
9494
Version: 0,
95-
Policy: Or(SignedBy(2), And(SignedBy(0), SignedBy(1))),
95+
Rule: Or(SignedBy(2), And(SignedBy(0), SignedBy(1))),
9696
Identities: principals,
9797
}
9898

@@ -123,7 +123,7 @@ func TestComplex2(t *testing.T) {
123123

124124
p2 := &common.SignaturePolicyEnvelope{
125125
Version: 0,
126-
Policy: Or(And(SignedBy(0), SignedBy(1)), Or(SignedBy(2), SignedBy(3))),
126+
Rule: Or(And(SignedBy(0), SignedBy(1)), Or(SignedBy(2), SignedBy(3))),
127127
Identities: principals,
128128
}
129129

common/config/msp/config_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func TestTemplates(t *testing.T) {
9595

9696
configGroup = TemplateGroupMSPWithAdminRolePrincipal([]string{"TestPath"}, mspConf, false)
9797
expectedPolicyValue := utils.MarshalOrPanic(cauthdsl.SignedByMspMember("DEFAULT"))
98-
actualPolicyValue := configGroup.Groups["TestPath"].Policies[AdminsPolicyKey].Policy.Policy
98+
actualPolicyValue := configGroup.Groups["TestPath"].Policies[AdminsPolicyKey].Policy.Value
9999
assert.Equal(t, expectedPolicyValue, actualPolicyValue, "Expected SignedByMspMemberPolicy")
100100

101101
mspConf = &mspprotos.MSPConfig{}

common/config/msp/config_util.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func TemplateGroupMSPWithAdminRolePrincipal(configPath []string, mspConfig *mspp
6767

6868
memberPolicy := &cb.ConfigPolicy{
6969
Policy: &cb.Policy{
70-
Type: int32(cb.Policy_SIGNATURE),
71-
Policy: utils.MarshalOrPanic(cauthdsl.SignedByMspMember(mspID)),
70+
Type: int32(cb.Policy_SIGNATURE),
71+
Value: utils.MarshalOrPanic(cauthdsl.SignedByMspMember(mspID)),
7272
},
7373
}
7474

@@ -81,8 +81,8 @@ func TemplateGroupMSPWithAdminRolePrincipal(configPath []string, mspConfig *mspp
8181

8282
adminPolicy := &cb.ConfigPolicy{
8383
Policy: &cb.Policy{
84-
Type: int32(cb.Policy_SIGNATURE),
85-
Policy: adminSigPolicy,
84+
Type: int32(cb.Policy_SIGNATURE),
85+
Value: adminSigPolicy,
8686
},
8787
}
8888

common/configtx/compare.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ func equalConfigPolicies(lhs, rhs *cb.ConfigPolicy) bool {
9898
}
9999

100100
return lhs.Policy.Type == rhs.Policy.Type &&
101-
bytes.Equal(lhs.Policy.Policy, rhs.Policy.Policy)
101+
bytes.Equal(lhs.Policy.Value, rhs.Policy.Value)
102102
}
103103

104104
// The subset functions check if inner is a subset of outer

common/configtx/compare_test.go

+24-24
Original file line numberDiff line numberDiff line change
@@ -94,16 +94,16 @@ func TestCompareConfigPolicy(t *testing.T) {
9494
Version: 0,
9595
ModPolicy: "foo",
9696
Policy: &cb.Policy{
97-
Type: 1,
98-
Policy: []byte("foo"),
97+
Type: 1,
98+
Value: []byte("foo"),
9999
},
100100
}}.equals(comparable{
101101
ConfigPolicy: &cb.ConfigPolicy{
102102
Version: 0,
103103
ModPolicy: "foo",
104104
Policy: &cb.Policy{
105-
Type: 1,
106-
Policy: []byte("foo"),
105+
Type: 1,
106+
Value: []byte("foo"),
107107
},
108108
}}), "Should have found identical config policies to be identical")
109109

@@ -113,16 +113,16 @@ func TestCompareConfigPolicy(t *testing.T) {
113113
Version: 0,
114114
ModPolicy: "foo",
115115
Policy: &cb.Policy{
116-
Type: 1,
117-
Policy: []byte("foo"),
116+
Type: 1,
117+
Value: []byte("foo"),
118118
},
119119
}}.equals(comparable{
120120
ConfigPolicy: &cb.ConfigPolicy{
121121
Version: 0,
122122
ModPolicy: "bar",
123123
Policy: &cb.Policy{
124-
Type: 1,
125-
Policy: []byte("foo"),
124+
Type: 1,
125+
Value: []byte("foo"),
126126
},
127127
}}), "Should have detected different mod policy")
128128

@@ -132,16 +132,16 @@ func TestCompareConfigPolicy(t *testing.T) {
132132
Version: 0,
133133
ModPolicy: "foo",
134134
Policy: &cb.Policy{
135-
Type: 1,
136-
Policy: []byte("foo"),
135+
Type: 1,
136+
Value: []byte("foo"),
137137
},
138138
}}.equals(comparable{
139139
ConfigPolicy: &cb.ConfigPolicy{
140140
Version: 1,
141141
ModPolicy: "foo",
142142
Policy: &cb.Policy{
143-
Type: 1,
144-
Policy: []byte("foo"),
143+
Type: 1,
144+
Value: []byte("foo"),
145145
},
146146
}}), "Should have detected different version")
147147

@@ -151,16 +151,16 @@ func TestCompareConfigPolicy(t *testing.T) {
151151
Version: 0,
152152
ModPolicy: "foo",
153153
Policy: &cb.Policy{
154-
Type: 1,
155-
Policy: []byte("foo"),
154+
Type: 1,
155+
Value: []byte("foo"),
156156
},
157157
}}.equals(comparable{
158158
ConfigPolicy: &cb.ConfigPolicy{
159159
Version: 0,
160160
ModPolicy: "foo",
161161
Policy: &cb.Policy{
162-
Type: 2,
163-
Policy: []byte("foo"),
162+
Type: 2,
163+
Value: []byte("foo"),
164164
},
165165
}}), "Should have detected different policy type")
166166

@@ -170,16 +170,16 @@ func TestCompareConfigPolicy(t *testing.T) {
170170
Version: 0,
171171
ModPolicy: "foo",
172172
Policy: &cb.Policy{
173-
Type: 1,
174-
Policy: []byte("foo"),
173+
Type: 1,
174+
Value: []byte("foo"),
175175
},
176176
}}.equals(comparable{
177177
ConfigPolicy: &cb.ConfigPolicy{
178178
Version: 0,
179179
ModPolicy: "foo",
180180
Policy: &cb.Policy{
181-
Type: 1,
182-
Policy: []byte("bar"),
181+
Type: 1,
182+
Value: []byte("bar"),
183183
},
184184
}}), "Should have detected different policy value")
185185

@@ -189,8 +189,8 @@ func TestCompareConfigPolicy(t *testing.T) {
189189
Version: 0,
190190
ModPolicy: "foo",
191191
Policy: &cb.Policy{
192-
Type: 1,
193-
Policy: []byte("foo"),
192+
Type: 1,
193+
Value: []byte("foo"),
194194
},
195195
}}.equals(comparable{}), "Should have detected one nil value")
196196

@@ -200,8 +200,8 @@ func TestCompareConfigPolicy(t *testing.T) {
200200
Version: 0,
201201
ModPolicy: "foo",
202202
Policy: &cb.Policy{
203-
Type: 1,
204-
Policy: []byte("foo"),
203+
Type: 1,
204+
Value: []byte("foo"),
205205
},
206206
}}.equals(comparable{
207207
ConfigPolicy: &cb.ConfigPolicy{

common/configtx/tool/provisional/provisional.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,8 @@ func New(conf *genesisconfig.Profile) Generator {
191191
// is not AcceptAll
192192
tcg.Groups[config.ConsortiumsGroupKey].Policies[configvaluesmsp.AdminsPolicyKey] = &cb.ConfigPolicy{
193193
Policy: &cb.Policy{
194-
Type: int32(cb.Policy_SIGNATURE),
195-
Policy: utils.MarshalOrPanic(cauthdsl.AcceptAllPolicy),
194+
Type: int32(cb.Policy_SIGNATURE),
195+
Value: utils.MarshalOrPanic(cauthdsl.AcceptAllPolicy),
196196
},
197197
}
198198

common/policies/implicitmeta_util.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func ImplicitMetaPolicyWithSubPolicy(subPolicyName string, rule cb.ImplicitMetaP
2626
return &cb.ConfigPolicy{
2727
Policy: &cb.Policy{
2828
Type: int32(cb.Policy_IMPLICIT_META),
29-
Policy: utils.MarshalOrPanic(&cb.ImplicitMetaPolicy{
29+
Value: utils.MarshalOrPanic(&cb.ImplicitMetaPolicy{
3030
Rule: rule,
3131
SubPolicy: subPolicyName,
3232
}),

common/policies/policy.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ func (pm *ManagerImpl) ProposePolicy(tx interface{}, key string, configPolicy *c
345345
var deserialized proto.Message
346346

347347
if policy.Type == int32(cb.Policy_IMPLICIT_META) {
348-
imp, err := newImplicitMetaPolicy(policy.Policy)
348+
imp, err := newImplicitMetaPolicy(policy.Value)
349349
if err != nil {
350350
return nil, err
351351
}
@@ -359,7 +359,7 @@ func (pm *ManagerImpl) ProposePolicy(tx interface{}, key string, configPolicy *c
359359
}
360360

361361
var err error
362-
cPolicy, deserialized, err = provider.NewPolicy(policy.Policy)
362+
cPolicy, deserialized, err = provider.NewPolicy(policy.Value)
363363
if err != nil {
364364
return nil, err
365365
}

0 commit comments

Comments
 (0)