github.com/defanghe/fabric@v2.1.1+incompatible/docs/source/access_control.md (about) 1 # Access Control Lists (ACL) 2 3 ## What is an Access Control List? 4 5 *Note: This topic deals with access control and policies on a channel 6 administration level. To learn about access control within a chaincode, check out 7 our [chaincode for developers tutorial](./chaincode4ade.html#Chaincode_API).* 8 9 Fabric uses access control lists (ACLs) to manage access to resources by associating 10 a [Policy](policies/policies.html) with a resource. Fabric contains a number of default ACLs. In this 11 document, we'll talk about how they're formatted and how the defaults can be overridden. 12 13 But before we can do that, it's necessary to understand a little about resources 14 and policies. 15 16 ### Resources 17 18 Users interact with Fabric by targeting a [user chaincode](./chaincode4ade.html), 19 or an [events stream source](./peer_event_services.html), or system chaincode that 20 are called in the background. As such, these endpoints are considered "resources" 21 on which access control should be exercised. 22 23 Application developers need to be aware of these resources and the default 24 policies associated with them. The complete list of these resources are found in 25 `configtx.yaml`. You can look at a [sample `configtx.yaml` file here](http://github.com/hyperledger/fabric/blob/release-2.0/sampleconfig/configtx.yaml). 26 27 The resources named in `configtx.yaml` is an exhaustive list of all internal resources 28 currently defined by Fabric. The loose convention adopted there is `<component>/<resource>`. 29 So `cscc/GetConfigBlock` is the resource for the `GetConfigBlock` call in the `CSCC` 30 component. 31 32 ### Policies 33 34 Policies are fundamental to the way Fabric works because they allow the identity 35 (or set of identities) associated with a request to be checked against the policy 36 associated with the resource needed to fulfill the request. Endorsement policies 37 are used to determine whether a transaction has been appropriately endorsed. The 38 policies defined in the channel configuration are referenced as modification policies 39 as well as for access control, and are defined in the channel configuration itself. 40 41 Policies can be structured in one of two ways: as `Signature` policies or as an 42 `ImplicitMeta` policy. 43 44 #### `Signature` policies 45 46 These policies identify specific users who must sign in order for a policy 47 to be satisfied. For example: 48 49 ``` 50 Policies: 51 MyPolicy: 52 Type: Signature 53 Rule: “Org1.Peer OR Org2.Peer” 54 55 ``` 56 57 This policy construct can be interpreted as: *the policy named `MyPolicy` can 58 only be satisfied by the signature of an identity with role of "a peer from 59 Org1" or "a peer from Org2"*. 60 61 Signature policies support arbitrary combinations of `AND`, `OR`, and `NOutOf`, 62 allowing the construction of extremely powerful rules like: "An admin of org A 63 and two other admins, or 11 of 20 org admins". 64 65 #### `ImplicitMeta` policies 66 67 `ImplicitMeta` policies aggregate the result of policies deeper in the 68 configuration hierarchy that are ultimately defined by `Signature` policies. They 69 support default rules like "A majority of the organization admins". These policies 70 use a different but still very simple syntax as compared to `Signature` policies: 71 `<ALL|ANY|MAJORITY> <sub_policy>`. 72 73 For example: `ANY` `Readers` or `MAJORITY` `Admins`. 74 75 *Note that in the default policy configuration `Admins` have an operational role. 76 Policies that specify that only Admins --- or some subset of Admins --- have access 77 to a resource will tend to be for sensitive or operational aspects of the network 78 (such as instantiating chaincode on a channel). `Writers` will tend to be able to 79 propose ledger updates, such as a transaction, but will not typically have 80 administrative permissions. `Readers` have a passive role. They can access 81 information but do not have the permission to propose ledger updates nor do can 82 they perform administrative tasks. These default policies can be added to, 83 edited, or supplemented, for example by the new `peer` and `client` roles (if you 84 have `NodeOU` support).* 85 86 Here's an example of an `ImplicitMeta` policy structure: 87 88 ``` 89 Policies: 90 AnotherPolicy: 91 Type: ImplicitMeta 92 Rule: "MAJORITY Admins" 93 ``` 94 95 Here, the policy `AnotherPolicy` can be satisfied by the `MAJORITY` of `Admins`, 96 where `Admins` is eventually being specified by lower level `Signature` policy. 97 98 ### Where is access control specified? 99 100 Access control defaults exist inside `configtx.yaml`, the file that `configtxgen` 101 uses to build channel configurations. 102 103 Access control can be updated in one of two ways, either by editing `configtx.yaml` 104 itself, which will be used when creating new channel configurations, or by updating 105 access control in the channel configuration of an existing channel. 106 107 ## How ACLs are formatted in `configtx.yaml` 108 109 ACLs are formatted as a key-value pair consisting of a resource function name 110 followed by a string. To see what this looks like, reference this [sample configtx.yaml file](https://github.com/hyperledger/fabric/blob/release-2.0/sampleconfig/configtx.yaml). 111 112 Two excerpts from this sample: 113 114 ``` 115 # ACL policy for invoking chaincodes on peer 116 peer/Propose: /Channel/Application/Writers 117 ``` 118 119 ``` 120 # ACL policy for sending block events 121 event/Block: /Channel/Application/Readers 122 ``` 123 124 These ACLs define that access to `peer/Propose` and `event/Block` resources 125 is restricted to identities satisfying the policy defined at the canonical path 126 `/Channel/Application/Writers` and `/Channel/Application/Readers`, respectively. 127 128 ### Updating ACL defaults in `configtx.yaml` 129 130 In cases where it will be necessary to override ACL defaults when bootstrapping 131 a network, or to change the ACLs before a channel has been bootstrapped, the 132 best practice will be to update `configtx.yaml`. 133 134 Let's say you want to modify the `peer/Propose` ACL default --- which specifies 135 the policy for invoking chaincodes on a peer -- from `/Channel/Application/Writers` 136 to a policy called `MyPolicy`. 137 138 This is done by adding a policy called `MyPolicy` (it could be called anything, 139 but for this example we'll call it `MyPolicy`). The policy is defined in the 140 `Application.Policies` section inside `configtx.yaml` and specifies a rule to be 141 checked to grant or deny access to a user. For this example, we'll be creating a 142 `Signature` policy identifying `SampleOrg.admin`. 143 144 ``` 145 Policies: &ApplicationDefaultPolicies 146 Readers: 147 Type: ImplicitMeta 148 Rule: "ANY Readers" 149 Writers: 150 Type: ImplicitMeta 151 Rule: "ANY Writers" 152 Admins: 153 Type: ImplicitMeta 154 Rule: "MAJORITY Admins" 155 MyPolicy: 156 Type: Signature 157 Rule: "OR('SampleOrg.admin')" 158 ``` 159 160 Then, edit the `Application: ACLs` section inside `configtx.yaml` to change 161 `peer/Propose` from this: 162 163 `peer/Propose: /Channel/Application/Writers` 164 165 To this: 166 167 `peer/Propose: /Channel/Application/MyPolicy` 168 169 Once these fields have been changed in `configtx.yaml`, the `configtxgen` tool 170 will use the policies and ACLs defined when creating a channel creation 171 transaction. When appropriately signed and submitted by one of the admins of the 172 consortium members, a new channel with the defined ACLs and policies is created. 173 174 Once `MyPolicy` has been bootstrapped into the channel configuration, it can also 175 be referenced to override other ACL defaults. For example: 176 177 ``` 178 SampleSingleMSPChannel: 179 Consortium: SampleConsortium 180 Application: 181 <<: *ApplicationDefaults 182 ACLs: 183 <<: *ACLsDefault 184 event/Block: /Channel/Application/MyPolicy 185 ``` 186 187 This would restrict the ability to subscribe to block events to `SampleOrg.admin`. 188 189 If channels have already been created that want to use this ACL, they'll have 190 to update their channel configurations one at a time using the following flow: 191 192 ### Updating ACL defaults in the channel config 193 194 If channels have already been created that want to use `MyPolicy` to restrict 195 access to `peer/Propose` --- or if they want to create ACLs they don't want 196 other channels to know about --- they'll have to update their channel 197 configurations one at a time through config update transactions. 198 199 *Note: Channel configuration transactions are an involved process we won't 200 delve into here. If you want to read more about them check out our document on 201 [channel configuration updates](./config_update.html) and our ["Adding an Org to a Channel" tutorial](./channel_update_tutorial.html).* 202 203 After pulling, translating, and stripping the configuration block of its metadata, 204 you would edit the configuration by adding `MyPolicy` under `Application: policies`, 205 where the `Admins`, `Writers`, and `Readers` policies already live. 206 207 ``` 208 "MyPolicy": { 209 "mod_policy": "Admins", 210 "policy": { 211 "type": 1, 212 "value": { 213 "identities": [ 214 { 215 "principal": { 216 "msp_identifier": "SampleOrg", 217 "role": "ADMIN" 218 }, 219 "principal_classification": "ROLE" 220 } 221 ], 222 "rule": { 223 "n_out_of": { 224 "n": 1, 225 "rules": [ 226 { 227 "signed_by": 0 228 } 229 ] 230 } 231 }, 232 "version": 0 233 } 234 }, 235 "version": "0" 236 }, 237 ``` 238 239 Note in particular the `msp_identifer` and `role` here. 240 241 Then, in the ACLs section of the config, change the `peer/Propose` ACL from 242 this: 243 244 ``` 245 "peer/Propose": { 246 "policy_ref": "/Channel/Application/Writers" 247 ``` 248 249 To this: 250 251 ``` 252 "peer/Propose": { 253 "policy_ref": "/Channel/Application/MyPolicy" 254 ``` 255 256 Note: If you do not have ACLs defined in your channel configuration, you will 257 have to add the entire ACL structure. 258 259 Once the configuration has been updated, it will need to be submitted by the 260 usual channel update process. 261 262 ### Satisfying an ACL that requires access to multiple resources 263 264 If a member makes a request that calls multiple system chaincodes, all of the ACLs 265 for those system chaincodes must be satisfied. 266 267 For example, `peer/Propose` refers to any proposal request on a channel. If the 268 particular proposal requires access to two system chaincodes that requires an 269 identity satisfying `Writers` and one system chaincode that requires an identity 270 satisfying `MyPolicy`, then the member submitting the proposal must have an identity 271 that evaluates to "true" for both `Writers` and `MyPolicy`. 272 273 In the default configuration, `Writers` is a signature policy whose `rule` is 274 `SampleOrg.member`. In other words, "any member of my organization". `MyPolicy`, 275 listed above, has a rule of `SampleOrg.admin`, or "any admin of my organization". 276 To satisfy these ACLs, the member would have to be both an administrator and a 277 member of `SampleOrg`. By default, all administrators are members (though not all 278 administrators are members), but it is possible to overwrite these policies to 279 whatever you want them to be. As a result, it's important to keep track of these 280 policies to ensure that the ACLs for peer proposals are not impossible to satisfy 281 (unless that is the intention). 282 283 <!--- Licensed under Creative Commons Attribution 4.0 International License 284 https://creativecommons.org/licenses/by/4.0/ -->