Skip to content

Commit 8288a7f

Browse files
Jason Yellickkchristidis
Jason Yellick
authored andcommitted
[FAB-2783] (PA) configtxgen specify admin principl
Currently, the configtxgen tool automatically outputs admin policies which require the signature of an admin certificate in order to satisfy them. For some deployment scenarios, especially our current e2e scenarios, it's not possible to sign with an admin cert, so this CR adds an option to specify the admin principal to be of type Role.MEMBER. Change-Id: If0f05fde2f726b88c54d6bdbc81e210c63bfa959 Signed-off-by: Jason Yellick <[email protected]> Signed-off-by: Kostas Christidis <[email protected]>
1 parent f3da0ba commit 8288a7f

File tree

4 files changed

+79
-10
lines changed

4 files changed

+79
-10
lines changed

common/config/msp/config_util.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,9 @@ const (
4242
MSPKey = "MSP"
4343
)
4444

45-
// TemplateGroupMSP creates an MSP ConfigValue at the given configPath
46-
func TemplateGroupMSP(configPath []string, mspConfig *mspprotos.MSPConfig) *cb.ConfigGroup {
45+
// TemplateGroupMSPWithAdminRolePrincipal creates an MSP ConfigValue at the given configPath with Admin policy
46+
// of role type ADMIN if admin==true or MEMBER otherwise
47+
func TemplateGroupMSPWithAdminRolePrincipal(configPath []string, mspConfig *mspprotos.MSPConfig, admin bool) *cb.ConfigGroup {
4748
// check that the type for that MSP is supported
4849
if mspConfig.Type != int32(msp.FABRIC) {
4950
logger.Panicf("Setup error: unsupported msp type %d", mspConfig.Type)
@@ -74,10 +75,17 @@ func TemplateGroupMSP(configPath []string, mspConfig *mspprotos.MSPConfig) *cb.C
7475
},
7576
}
7677

78+
var adminSigPolicy []byte
79+
if admin {
80+
adminSigPolicy = utils.MarshalOrPanic(cauthdsl.SignedByMspAdmin(mspID))
81+
} else {
82+
adminSigPolicy = utils.MarshalOrPanic(cauthdsl.SignedByMspMember(mspID))
83+
}
84+
7785
adminPolicy := &cb.ConfigPolicy{
7886
Policy: &cb.Policy{
7987
Type: int32(cb.Policy_SIGNATURE),
80-
Policy: utils.MarshalOrPanic(cauthdsl.SignedByMspAdmin(mspID)),
88+
Policy: adminSigPolicy,
8189
},
8290
}
8391

@@ -96,3 +104,8 @@ func TemplateGroupMSP(configPath []string, mspConfig *mspprotos.MSPConfig) *cb.C
96104
intermediate.Policies[WritersPolicyKey] = memberPolicy
97105
return result
98106
}
107+
108+
// TemplateGroupMSP creates an MSP ConfigValue at the given configPath
109+
func TemplateGroupMSP(configPath []string, mspConfig *mspprotos.MSPConfig) *cb.ConfigGroup {
110+
return TemplateGroupMSPWithAdminRolePrincipal(configPath, mspConfig, true)
111+
}

common/configtx/tool/localconfig/config.go

+42-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ const (
6161
SampleSingleMSPSoloProfile = "SampleSingleMSPSolo"
6262
// SampleConsortiumName is the sample consortium from the sample configtx.yaml
6363
SampleConsortiumName = "SampleConsortium"
64+
65+
// AdminRoleAdminPrincipal is set as AdminRole to cause the MSP role of type Admin to be used as the admin principal default
66+
AdminRoleAdminPrincipal = "Role.ADMIN"
67+
// MemberRoleAdminPrincipal is set as AdminRole to cause the MSP role of type Member to be used as the admin principal default
68+
MemberRoleAdminPrincipal = "Role.MEMBER"
6469
)
6570

6671
// TopLevel consists of the structs used by the configtxgen tool.
@@ -73,6 +78,7 @@ type TopLevel struct {
7378

7479
// Profile encodes orderer/application configuration combinations for the configtxgen tool.
7580
type Profile struct {
81+
Consortium string `yaml:"Consortium"`
7682
Application *Application `yaml:"Application"`
7783
Orderer *Orderer `yaml:"Orderer"`
7884
Consortiums map[string]*Consortium `yaml:"Consortiums"`
@@ -90,10 +96,11 @@ type Application struct {
9096

9197
// Organization encodes the organization-level configuration needed in config transactions.
9298
type Organization struct {
93-
Name string `yaml:"Name"`
94-
ID string `yaml:"ID"`
95-
MSPDir string `yaml:"MSPDir"`
96-
BCCSP *bccsp.FactoryOpts `yaml:"BCCSP"`
99+
Name string `yaml:"Name"`
100+
ID string `yaml:"ID"`
101+
MSPDir string `yaml:"MSPDir"`
102+
AdminPrincipal string `yaml:"AdminPrincipal"`
103+
BCCSP *bccsp.FactoryOpts `yaml:"BCCSP"`
97104

98105
// Note: Viper deserialization does not seem to care for
99106
// embedding of types, so we use one organization struct
@@ -212,6 +219,37 @@ func (p *Profile) completeInitialization(configDir string) {
212219
}
213220

214221
func (p *Profile) initDefaults() {
222+
if p.Orderer != nil {
223+
for _, org := range p.Orderer.Organizations {
224+
if org.AdminPrincipal == "" {
225+
org.AdminPrincipal = AdminRoleAdminPrincipal
226+
}
227+
}
228+
}
229+
230+
if p.Application != nil {
231+
for _, org := range p.Application.Organizations {
232+
if org.AdminPrincipal == "" {
233+
org.AdminPrincipal = AdminRoleAdminPrincipal
234+
}
235+
}
236+
}
237+
238+
if p.Consortiums != nil {
239+
for _, consortium := range p.Consortiums {
240+
for _, org := range consortium.Organizations {
241+
if org.AdminPrincipal == "" {
242+
org.AdminPrincipal = AdminRoleAdminPrincipal
243+
}
244+
}
245+
}
246+
}
247+
248+
// Some profiles will not define orderer parameters
249+
if p.Orderer == nil {
250+
return
251+
}
252+
215253
for {
216254
switch {
217255
case p.Orderer.OrdererType == "":

common/configtx/tool/provisional/provisional.go

+16-3
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ func New(conf *genesisconfig.Profile) Generator {
134134
if err != nil {
135135
logger.Panicf("1 - Error loading MSP configuration for org %s: %s", org.Name, err)
136136
}
137-
bs.ordererGroups = append(bs.ordererGroups, configvaluesmsp.TemplateGroupMSP([]string{config.OrdererGroupKey, org.Name}, mspConfig))
137+
bs.ordererGroups = append(bs.ordererGroups,
138+
configvaluesmsp.TemplateGroupMSPWithAdminRolePrincipal([]string{config.OrdererGroupKey, org.Name},
139+
mspConfig, org.AdminPrincipal == genesisconfig.AdminRoleAdminPrincipal,
140+
),
141+
)
138142
}
139143

140144
switch conf.Orderer.OrdererType {
@@ -165,7 +169,11 @@ func New(conf *genesisconfig.Profile) Generator {
165169
logger.Panicf("2- Error loading MSP configuration for org %s: %s", org.Name, err)
166170
}
167171

168-
bs.applicationGroups = append(bs.applicationGroups, configvaluesmsp.TemplateGroupMSP([]string{config.ApplicationGroupKey, org.Name}, mspConfig))
172+
bs.applicationGroups = append(bs.applicationGroups,
173+
configvaluesmsp.TemplateGroupMSPWithAdminRolePrincipal([]string{config.ApplicationGroupKey, org.Name},
174+
mspConfig, org.AdminPrincipal == genesisconfig.AdminRoleAdminPrincipal,
175+
),
176+
)
169177
var anchorProtos []*pb.AnchorPeer
170178
for _, anchorPeer := range org.AnchorPeers {
171179
anchorProtos = append(anchorProtos, &pb.AnchorPeer{
@@ -195,7 +203,12 @@ func New(conf *genesisconfig.Profile) Generator {
195203
if err != nil {
196204
logger.Panicf("3 - Error loading MSP configuration for org %s: %s", org.Name, err)
197205
}
198-
bs.consortiumsGroups = append(bs.consortiumsGroups, configvaluesmsp.TemplateGroupMSP([]string{config.ConsortiumsGroupKey, consortiumName, org.Name}, mspConfig))
206+
bs.consortiumsGroups = append(bs.consortiumsGroups,
207+
configvaluesmsp.TemplateGroupMSPWithAdminRolePrincipal(
208+
[]string{config.ConsortiumsGroupKey, consortiumName, org.Name},
209+
mspConfig, org.AdminPrincipal == genesisconfig.AdminRoleAdminPrincipal,
210+
),
211+
)
199212
}
200213
}
201214
}

sampleconfig/configtx.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ Organizations:
7373
# MSPDir is the filesystem path which contains the MSP configuration.
7474
MSPDir: msp
7575

76+
# AdminPrincipal dictates the type of principal used for an organization's Admins policy
77+
# Today, only the values of Role.ADMIN ad Role.MEMBER are accepted, which indicates a principal
78+
# of role type ADMIN and role type MEMBER respectively
79+
AdminPrincipal: Role.ADMIN
80+
7681
# BCCSP: Select which crypto implementation or library to use for the
7782
# blockchain crypto service provider.
7883
BCCSP:

0 commit comments

Comments
 (0)