Skip to content

Commit f519714

Browse files
author
Jason Yellick
committed
[FAB-9254] Specify policies in configtx.yaml
This CR adds the ability to specify policies in configtx.yaml. It is one half of two required for users to specify their own policies. The second half is in FAB-9255 (submitted together) which takes these additional config file options and encodes them into channel config. Change-Id: I7ba264a7554d4e3656bf13f2191bd871ba401e21 Signed-off-by: Jason Yellick <jyellick@us.ibm.com>
1 parent a003298 commit f519714

File tree

2 files changed

+123
-28
lines changed

2 files changed

+123
-28
lines changed

common/tools/configtxgen/localconfig/config.go

+30-16
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ type Profile struct {
9595
Orderer *Orderer `yaml:"Orderer"`
9696
Consortiums map[string]*Consortium `yaml:"Consortiums"`
9797
Capabilities map[string]bool `yaml:"Capabilities"`
98+
Policies map[string]*Policy `yaml:"Policies"`
99+
}
100+
101+
// Policy encodes a channel config policy
102+
type Policy struct {
103+
Type string `yaml:"Type"`
104+
Rule string `yaml:"Rule"`
98105
}
99106

100107
// Consortium represents a group of organizations which may create channels with eachother
@@ -104,9 +111,10 @@ type Consortium struct {
104111

105112
// Application encodes the application-level configuration needed in config transactions.
106113
type Application struct {
107-
Organizations []*Organization `yaml:"Organizations"`
108-
Capabilities map[string]bool `yaml:"Capabilities"`
109-
Resources *Resources `yaml:"Resources"`
114+
Organizations []*Organization `yaml:"Organizations"`
115+
Capabilities map[string]bool `yaml:"Capabilities"`
116+
Resources *Resources `yaml:"Resources"`
117+
Policies map[string]*Policy `yaml:"Policies"`
110118
}
111119

112120
// Resouces encodes the application-level resources configuration needed to seed the resource tree
@@ -116,16 +124,21 @@ type Resources struct {
116124

117125
// Organization encodes the organization-level configuration needed in config transactions.
118126
type Organization struct {
119-
Name string `yaml:"Name"`
120-
ID string `yaml:"ID"`
121-
MSPDir string `yaml:"MSPDir"`
122-
MSPType string `yaml:"MSPType"`
123-
AdminPrincipal string `yaml:"AdminPrincipal"`
127+
Name string `yaml:"Name"`
128+
ID string `yaml:"ID"`
129+
MSPDir string `yaml:"MSPDir"`
130+
MSPType string `yaml:"MSPType"`
131+
Policies map[string]*Policy `yaml:"Policies"`
124132

125133
// Note: Viper deserialization does not seem to care for
126134
// embedding of types, so we use one organization struct
127135
// for both orderers and applications.
128136
AnchorPeers []*AnchorPeer `yaml:"AnchorPeers"`
137+
138+
// AdminPrincipal is deprecated and may be removed in a future release
139+
// it was used for modifying the default policy generation, but policies
140+
// may now be specified explicitly so it is redundant and unnecessary
141+
AdminPrincipal string `yaml:"AdminPrincipal"`
129142
}
130143

131144
// AnchorPeer encodes the necessary fields to identify an anchor peer.
@@ -137,14 +150,15 @@ type AnchorPeer struct {
137150
// Orderer contains configuration which is used for the
138151
// bootstrapping of an orderer by the provisional bootstrapper.
139152
type Orderer struct {
140-
OrdererType string `yaml:"OrdererType"`
141-
Addresses []string `yaml:"Addresses"`
142-
BatchTimeout time.Duration `yaml:"BatchTimeout"`
143-
BatchSize BatchSize `yaml:"BatchSize"`
144-
Kafka Kafka `yaml:"Kafka"`
145-
Organizations []*Organization `yaml:"Organizations"`
146-
MaxChannels uint64 `yaml:"MaxChannels"`
147-
Capabilities map[string]bool `yaml:"Capabilities"`
153+
OrdererType string `yaml:"OrdererType"`
154+
Addresses []string `yaml:"Addresses"`
155+
BatchTimeout time.Duration `yaml:"BatchTimeout"`
156+
BatchSize BatchSize `yaml:"BatchSize"`
157+
Kafka Kafka `yaml:"Kafka"`
158+
Organizations []*Organization `yaml:"Organizations"`
159+
MaxChannels uint64 `yaml:"MaxChannels"`
160+
Capabilities map[string]bool `yaml:"Capabilities"`
161+
Policies map[string]*Policy `yaml:"Policies"`
148162
}
149163

150164
// BatchSize contains configuration affecting the size of batches.

sampleconfig/configtx.yaml

+93-12
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,26 @@ Profiles:
7979
<<: *OrdererDefaults
8080
Organizations:
8181
- <<: *SampleOrg
82-
AdminPrincipal: Role.MEMBER
82+
Policies:
83+
Admins:
84+
Type: Signature
85+
Rule: "OR('SampleOrg.member')"
8386
Application:
8487
<<: *ApplicationDefaults
8588
Organizations:
8689
- <<: *SampleOrg
87-
AdminPrincipal: Role.MEMBER
90+
Policies:
91+
Admins:
92+
Type: Signature
93+
Rule: "OR('SampleOrg.member')"
8894
Consortiums:
8995
SampleConsortium:
9096
Organizations:
9197
- <<: *SampleOrg
92-
AdminPrincipal: Role.MEMBER
98+
Policies:
99+
Admins:
100+
Type: Signature
101+
Rule: "OR('SampleOrg.member')"
93102

94103
# SampleDevModeKafka defines a configuration that differs from the
95104
# SampleDevModeSolo one only in that it uses the Kafka-based orderer.
@@ -100,17 +109,26 @@ Profiles:
100109
OrdererType: kafka
101110
Organizations:
102111
- <<: *SampleOrg
103-
AdminPrincipal: Role.MEMBER
112+
Policies:
113+
Admins:
114+
Type: Signature
115+
Rule: "OR('SampleOrg.member')"
104116
Application:
105117
<<: *ApplicationDefaults
106118
Organizations:
107119
- <<: *SampleOrg
108-
AdminPrincipal: Role.MEMBER
120+
Policies:
121+
Admins:
122+
Type: Signature
123+
Rule: "OR('SampleOrg.member')"
109124
Consortiums:
110125
SampleConsortium:
111126
Organizations:
112127
- <<: *SampleOrg
113-
AdminPrincipal: Role.MEMBER
128+
Policies:
129+
Admins:
130+
Type: Signature
131+
Rule: "OR('SampleOrg.member')"
114132

115133
# SampleSingleMSPChannel defines a channel with only the sample org as a
116134
# member. It is designed to be used in conjunction with SampleSingleMSPSolo
@@ -149,11 +167,25 @@ Organizations:
149167
# MSPDir is the filesystem path which contains the MSP configuration.
150168
MSPDir: msp
151169

152-
# AdminPrincipal dictates the type of principal used for an
153-
# organization's Admins policy. Today, only the values of Role.ADMIN and
154-
# Role.MEMBER are accepted, which indicates a principal of role type
155-
# ADMIN and role type MEMBER respectively.
156-
AdminPrincipal: Role.ADMIN
170+
# Policies defines the set of policies at this level of the config tree
171+
# For organization policies, their canonical path is usually
172+
# /Channel/<Application|Orderer>/<OrgName>/<PolicyName>
173+
Policies:
174+
Readers:
175+
Type: Signature
176+
Rule: "OR('SampleOrg.member')"
177+
# If your MSP is configured with the new NodeOUs, you might
178+
# want to use a more specific rule like the following:
179+
# Rule: "OR('SampleOrg.admin', 'SampleOrg.peer')"
180+
Writers:
181+
Type: Signature
182+
Rule: "OR('SampleOrg.member')"
183+
# If your MSP is configured with the new NodeOUs, you might
184+
# want to use a more specific rule like the following:
185+
# Rule: "OR('SampleOrg.admin', 'SampleOrg.client'')"
186+
Admins:
187+
Type: Signature
188+
Rule: "OR('SampleOrg.admin')"
157189

158190
# AnchorPeers defines the location of peers which can be used for
159191
# cross-org gossip communication. Note, this value is only encoded in
@@ -171,6 +203,23 @@ Organizations:
171203
#
172204
################################################################################
173205
Channel: &ChannelDefaults
206+
# Policies defines the set of policies at this level of the config tree
207+
# For Channel policies, their canonical path is
208+
# /Channel/<PolicyName>
209+
Policies:
210+
# Who may invoke the 'Deliver' API
211+
Readers:
212+
Type: ImplicitMeta
213+
Rule: "ANY Readers"
214+
# Who may invoke the 'Broadcast' API
215+
Writers:
216+
Type: ImplicitMeta
217+
Rule: "ANY Writers"
218+
# By default, who may modify elements at this config level
219+
Admins:
220+
Type: ImplicitMeta
221+
Rule: "MAJORITY Admins"
222+
174223

175224
# Capabilities describes the channel level capabilities, see the
176225
# dedicated Capabilities section elsewhere in this file for a full
@@ -238,13 +287,31 @@ Orderer: &OrdererDefaults
238287
# network.
239288
Organizations:
240289

290+
# Policies defines the set of policies at this level of the config tree
291+
# For Orderer policies, their canonical path is
292+
# /Channel/Orderer/<PolicyName>
293+
Policies:
294+
Readers:
295+
Type: ImplicitMeta
296+
Rule: "ANY Readers"
297+
Writers:
298+
Type: ImplicitMeta
299+
Rule: "ANY Writers"
300+
Admins:
301+
Type: ImplicitMeta
302+
Rule: "MAJORITY Admins"
303+
# BlockValidation specifies what signatures must be included in the block
304+
# from the orderer for the peer to validate it.
305+
BlockValidation:
306+
Type: ImplicitMeta
307+
Rule: "ANY Writers"
308+
241309
# Capabilities describes the orderer level capabilities, see the
242310
# dedicated Capabilities section elsewhere in this file for a full
243311
# description
244312
Capabilities:
245313
<<: *OrdererCapabilities
246314

247-
248315
################################################################################
249316
#
250317
# APPLICATION
@@ -259,6 +326,20 @@ Application: &ApplicationDefaults
259326
# network.
260327
Organizations:
261328

329+
# Policies defines the set of policies at this level of the config tree
330+
# For Application policies, their canonical path is
331+
# /Channel/Application/<PolicyName>
332+
Policies:
333+
Readers:
334+
Type: ImplicitMeta
335+
Rule: "ANY Readers"
336+
Writers:
337+
Type: ImplicitMeta
338+
Rule: "ANY Writers"
339+
Admins:
340+
Type: ImplicitMeta
341+
Rule: "MAJORITY Admins"
342+
262343
# Capabilities describes the application level capabilities, see the
263344
# dedicated Capabilities section elsewhere in this file for a full
264345
# description

0 commit comments

Comments
 (0)