Skip to content

Commit 0ee18c2

Browse files
author
Jason Yellick
committed
FAB-10314 Hide ACLs behind capability
The ACLs function affects how channel config is parsed, and as such, it must be deterministic across versions. Channel config parsing should not allow the presence of ACLs until the corresponding capability has been enabled. Change-Id: Ie55a69b620d48198bc485cde820b5f03d6dd6c2d Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent c37715b commit 0ee18c2

File tree

10 files changed

+92
-43
lines changed

10 files changed

+92
-43
lines changed

common/capabilities/application.go

+7-9
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ const (
3535
// ApplicationProvider provides capabilities information for application level config.
3636
type ApplicationProvider struct {
3737
*registry
38-
v11 bool
39-
v12 bool
40-
v11PvtDataExperimental bool
41-
v11ResourcesTreeExperimental bool
42-
v12LifecycleExperimental bool
38+
v11 bool
39+
v12 bool
40+
v11PvtDataExperimental bool
41+
v12LifecycleExperimental bool
4342
}
4443

4544
// NewApplicationProvider creates a application capabilities provider.
@@ -49,7 +48,6 @@ func NewApplicationProvider(capabilities map[string]*cb.Capability) *Application
4948
_, ap.v11 = capabilities[ApplicationV1_1]
5049
_, ap.v12 = capabilities[ApplicationV1_2]
5150
_, ap.v11PvtDataExperimental = capabilities[ApplicationPvtDataExperimental]
52-
_, ap.v11ResourcesTreeExperimental = capabilities[ApplicationResourcesTreeExperimental]
5351
_, ap.v12LifecycleExperimental = capabilities[ApplicationChaincodeLifecycleExperimental]
5452
return ap
5553
}
@@ -59,9 +57,9 @@ func (ap *ApplicationProvider) Type() string {
5957
return applicationTypeName
6058
}
6159

62-
// ResourcesTree returns whether the experimental resources tree transaction processing should be enabled.
63-
func (ap *ApplicationProvider) ResourcesTree() bool {
64-
return ap.v11ResourcesTreeExperimental
60+
// ACLs returns whether ACLs may be specified in the channel application config
61+
func (ap *ApplicationProvider) ACLs() bool {
62+
return ap.v12
6563
}
6664

6765
// ForbidDuplicateTXIdInBlock specifies whether two transactions with the same TXId are permitted

common/capabilities/application_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ func TestApplicationPvtDataExperimental(t *testing.T) {
5252

5353
}
5454

55+
func TestApplicationACLs(t *testing.T) {
56+
ap := NewApplicationProvider(map[string]*cb.Capability{
57+
ApplicationV1_2: {},
58+
})
59+
assert.True(t, ap.ACLs())
60+
}
61+
5562
func TestApplicationCollectionUpgrade(t *testing.T) {
5663
op := NewApplicationProvider(map[string]*cb.Capability{
5764
ApplicationV1_2: {},

common/channelconfig/api.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,8 @@ type ApplicationCapabilities interface {
123123
// in the same block or whether we mark the second one as TxValidationCode_DUPLICATE_TXID
124124
ForbidDuplicateTXIdInBlock() bool
125125

126-
// ResourcesTree returns true if the peer should process the experimental resources transactions
127-
ResourcesTree() bool
126+
// ACLs returns true is ACLs may be specified in the Application portion of the config tree
127+
ACLs() bool
128128

129129
// PrivateChannelData returns true if support for private channel data (a.k.a. collections) is enabled.
130130
// In v1.1, the private channel data is experimental and has to be enabled explicitly.

common/channelconfig/application.go

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ func NewApplicationConfig(appGroup *cb.ConfigGroup, mspConfig *MSPConfigHandler)
4545
return nil, errors.Wrap(err, "failed to deserialize values")
4646
}
4747

48+
if !ac.Capabilities().ACLs() {
49+
if _, ok := appGroup.Values[ACLsKey]; ok {
50+
return nil, errors.New("ACLs may not be specified without the required capability")
51+
}
52+
}
53+
4854
var err error
4955
for orgName, orgGroup := range appGroup.Groups {
5056
ac.applicationOrgs[orgName], err = NewApplicationOrgConfig(orgName, orgGroup, mspConfig)

common/channelconfig/application_test.go

+39
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ package channelconfig
99
import (
1010
"testing"
1111

12+
"github.com/hyperledger/fabric/common/capabilities"
13+
cb "github.com/hyperledger/fabric/protos/common"
14+
"github.com/hyperledger/fabric/protos/utils"
15+
16+
"github.com/golang/protobuf/proto"
17+
. "github.com/onsi/gomega"
1218
logging "github.com/op/go-logging"
1319
)
1420

@@ -19,3 +25,36 @@ func init() {
1925
func TestApplicationInterface(t *testing.T) {
2026
_ = Application((*ApplicationConfig)(nil))
2127
}
28+
29+
func TestACL(t *testing.T) {
30+
g := NewGomegaWithT(t)
31+
cgt := &cb.ConfigGroup{
32+
Values: map[string]*cb.ConfigValue{
33+
ACLsKey: {
34+
Value: utils.MarshalOrPanic(
35+
ACLValues(map[string]string{}).Value(),
36+
),
37+
},
38+
CapabilitiesKey: {
39+
Value: utils.MarshalOrPanic(
40+
CapabilitiesValue(map[string]bool{
41+
capabilities.ApplicationV1_2: true,
42+
}).Value(),
43+
),
44+
},
45+
},
46+
}
47+
48+
t.Run("Success", func(t *testing.T) {
49+
cg := proto.Clone(cgt).(*cb.ConfigGroup)
50+
_, err := NewApplicationConfig(proto.Clone(cg).(*cb.ConfigGroup), nil)
51+
g.Expect(err).NotTo(HaveOccurred())
52+
})
53+
54+
t.Run("MissingCapability", func(t *testing.T) {
55+
cg := proto.Clone(cgt).(*cb.ConfigGroup)
56+
delete(cg.Values, CapabilitiesKey)
57+
_, err := NewApplicationConfig(cg, nil)
58+
g.Expect(err).To(MatchError("ACLs may not be specified without the required capability"))
59+
})
60+
}

common/mocks/config/application.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (m *MockApplication) APIPolicyMapper() channelconfig.PolicyMapper {
3838
type MockApplicationCapabilities struct {
3939
SupportedRv error
4040
ForbidDuplicateTXIdInBlockRv bool
41-
ResourcesTreeRv bool
41+
ACLsRv bool
4242
PrivateChannelDataRv bool
4343
CollectionUpgradeRv bool
4444
V1_1ValidationRv bool
@@ -55,8 +55,8 @@ func (mac *MockApplicationCapabilities) ForbidDuplicateTXIdInBlock() bool {
5555
return mac.ForbidDuplicateTXIdInBlockRv
5656
}
5757

58-
func (mac *MockApplicationCapabilities) ResourcesTree() bool {
59-
return mac.ResourcesTreeRv
58+
func (mac *MockApplicationCapabilities) ACLs() bool {
59+
return mac.ACLsRv
6060
}
6161

6262
func (mac *MockApplicationCapabilities) PrivateChannelData() bool {

core/committer/txvalidator/mocks/capabilities.go

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

core/handlers/validation/api/capabilities/capabilities.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ type Capabilities interface {
1919
// in the same block or whether we mark the second one as TxValidationCode_DUPLICATE_TXID
2020
ForbidDuplicateTXIdInBlock() bool
2121

22-
// ResourcesTree returns true if the peer should process the experimental resources transactions
23-
ResourcesTree() bool
22+
// ACLs returns true if the peer supports ACLs in the channel config
23+
ACLs() bool
2424

2525
// PrivateChannelData returns true if support for private channel data (a.k.a. collections) is enabled.
2626
PrivateChannelData() bool

core/handlers/validation/builtin/mocks/capabilities.go

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

core/peer/configtx_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func TestConfigTxCreateLedger(t *testing.T) {
6262
assert.Equal(t, proto.CompactTextString(chanConf), proto.CompactTextString(retrievedchanConf))
6363
}
6464

65-
func TestConfigTxUpdateResConfig(t *testing.T) {
65+
func TestConfigTxUpdateChanConfig(t *testing.T) {
6666
helper := &testHelper{t: t}
6767
cleanup := setupPeerFS(t)
6868
defer cleanup()
@@ -125,8 +125,7 @@ func (h *testHelper) sampleChannelConfig(sequence uint64, enableV11Capability bo
125125
profile.Orderer.Capabilities = make(map[string]bool)
126126
profile.Orderer.Capabilities[capabilities.ApplicationV1_1] = true
127127
profile.Application.Capabilities = make(map[string]bool)
128-
profile.Application.Capabilities[capabilities.ApplicationV1_1] = true
129-
profile.Application.Capabilities[capabilities.ApplicationResourcesTreeExperimental] = true
128+
profile.Application.Capabilities[capabilities.ApplicationV1_2] = true
130129
}
131130
channelGroup, _ := encoder.NewChannelGroup(profile)
132131
return &common.Config{

0 commit comments

Comments
 (0)