Skip to content

Commit d0eb668

Browse files
Jason Yellickyacovm
authored andcommitted
[FAB-7322] configtxgen set default res mod_policy
In v1.0, chaincode instantiation was always controlled by a policy which required a single signature. By default, we wish for chaincode instantiation to require a quorum of administrators to sign off, but doing so may break existing workflows. This CR adds a field to configtx.yaml which specifies the default mod_policy to use throughout the resources tree. If set to a single signature policy like /Channel/Application/Writers, then the old workflow of a single signer is still possible. If set to a multi-sig policy like /Channel/Application/Admins, then the user's workflow will need to be changed to accomodate the additional signing requirements. Change-Id: I021801f1540ee5ee25d110682852564650421dbd Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent 500d3de commit d0eb668

File tree

4 files changed

+45
-4
lines changed

4 files changed

+45
-4
lines changed

common/tools/configtxgen/encoder/encoder.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -370,22 +370,26 @@ func NewChannelCreateConfigUpdate(channelID string, orderingSystemChannelGroup *
370370

371371
// If this channel uses the new lifecycle config, specify the seed data
372372
if agc.Capabilities().LifecycleViaConfig() {
373+
defaultModPolicy := policies.ChannelApplicationAdmins
374+
if conf.Application.Resources != nil {
375+
defaultModPolicy = conf.Application.Resources.DefaultModPolicy
376+
}
373377
updt.IsolatedData = map[string][]byte{
374378
pb.RSCCSeedDataKey: utils.MarshalOrPanic(&cb.Config{
375379
Type: int32(cb.ConfigType_RESOURCE),
376380
ChannelGroup: &cb.ConfigGroup{
377381
Groups: map[string]*cb.ConfigGroup{
378382
resourcesconfig.ChaincodesGroupKey: &cb.ConfigGroup{
379-
ModPolicy: policies.ChannelApplicationAdmins,
383+
ModPolicy: defaultModPolicy,
380384
},
381385
resourcesconfig.PeerPoliciesGroupKey: &cb.ConfigGroup{
382-
ModPolicy: policies.ChannelApplicationAdmins,
386+
ModPolicy: defaultModPolicy,
383387
},
384388
resourcesconfig.APIsGroupKey: &cb.ConfigGroup{
385-
ModPolicy: policies.ChannelApplicationAdmins,
389+
ModPolicy: defaultModPolicy,
386390
},
387391
},
388-
ModPolicy: policies.ChannelApplicationAdmins,
392+
ModPolicy: defaultModPolicy,
389393
},
390394
}),
391395
}

common/tools/configtxgen/localconfig/config.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"time"
1414

1515
"github.com/hyperledger/fabric/common/flogging"
16+
"github.com/hyperledger/fabric/common/policies"
1617
"github.com/hyperledger/fabric/common/viperutil"
1718
logging "github.com/op/go-logging"
1819

@@ -93,6 +94,7 @@ type TopLevel struct {
9394
Application *Application `yaml:"Application"`
9495
Orderer *Orderer `yaml:"Orderer"`
9596
Capabilities map[string]map[string]bool `yaml:"Capabilities"`
97+
Resources *Resources `yaml:"Resources"`
9698
}
9799

98100
// Profile encodes orderer/application configuration combinations for the configtxgen tool.
@@ -113,6 +115,12 @@ type Consortium struct {
113115
type Application struct {
114116
Organizations []*Organization `yaml:"Organizations"`
115117
Capabilities map[string]bool `yaml:"Capabilities"`
118+
Resources *Resources `yaml:"Resources"`
119+
}
120+
121+
// Resouces encodes the application-level resources configuration needed to seed the resource tree
122+
type Resources struct {
123+
DefaultModPolicy string
116124
}
117125

118126
// Organization encodes the organization-level configuration needed in config transactions.
@@ -268,6 +276,9 @@ func (p *Profile) completeInitialization(configDir string) {
268276
for _, org := range p.Application.Organizations {
269277
org.completeInitialization(configDir)
270278
}
279+
if p.Application.Resources != nil {
280+
p.Application.Resources.completeInitialization()
281+
}
271282
}
272283

273284
if p.Consortiums != nil {
@@ -284,6 +295,17 @@ func (p *Profile) completeInitialization(configDir string) {
284295
}
285296
}
286297

298+
func (r *Resources) completeInitialization() {
299+
for {
300+
switch {
301+
case r.DefaultModPolicy == "":
302+
r.DefaultModPolicy = policies.ChannelApplicationAdmins
303+
default:
304+
return
305+
}
306+
}
307+
}
308+
287309
func (org *Organization) completeInitialization(configDir string) {
288310
// set the MSP type; if none is specified we assume BCCSP
289311
if org.MSPType == "" {

examples/e2e_cli/configtx.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ Profiles:
3737
- *Org2
3838
Capabilities:
3939
<<: *ApplicationCapabilities
40+
Resources:
41+
DefaultModPolicy: /Channel/Application/Writers
4042

4143
################################################################################
4244
#

sampleconfig/configtx.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,3 +357,16 @@ Capabilities:
357357
# modification of which would cause imcompatibilities. Users should
358358
# leave this flag set to true.
359359
V1_1: true
360+
361+
################################################################################
362+
#
363+
# SECTION: Resources
364+
#
365+
# - This section defines the peer resources for a fabric network. These
366+
# resources include chaincode definitions, as well as policies for how those
367+
# resources can be modified. Note, this section is only applicable if the V1_1
368+
# application capability is enabled.
369+
#
370+
################################################################################
371+
Resources:
372+
DefaultModPolicy: /Channel/Application/Admins

0 commit comments

Comments
 (0)