参照
https://hyperledger-fabric-cn.readthedocs.io/zh/1.3.0_zh-cn/access_control.html
https://hyperledger-fabric-cn.readthedocs.io/zh/1.3.0_zh-cn/policies.html?highlight=ImplicitMeta
1.定义策有两种方法
- Signature
- ImplicitMeta
第一种 Signature
Policies:
MyPolicy:
Type: Signature
Rule: "Org1.Peer OR Org2.Peer"
策略的意思是,定义名称为 MyPolicy的Signature 策略,规则是只能是组织1或组织2的身份。Rule 可以是 AND, OR, NOutOf ,也可以定义成 [An admin of org A and two other admins, or 11 of 20 org admins] 这么复杂的。
第二种 ImplicitMeta
ImplicitMeta是一种聚合策略,没有Signature灵活,其最终使用的还是Signature策略。
它主要使用 ALL|ANY|MAJORITY + sub_policy这样的形式定义,
例如:
Policies:
AnotherPolicy:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
目前策略的定义最初是在configtx.yaml里面,然后可以在channel configuration 里面进行修改
2.ACLs在configtx.yaml中的定义
ACLs以key-value的形式定义在configtx.yaml的[Application: ACLs]中。key代表访问资源的类型,value代表访问资源的身份(策略)。
# ACL policy for invoking chaincodes on peer
peer/Propose: /Channel/Application/Writers
# ACL policy for sending block events
event/Block: /Channel/Application/Readers
key : [peer/Propose],[event/Block]资源分别代表执行chaindoce和发送块事件。
value:[peer/Propose: /Channel/Application/Writers],[/Channel/Application/Readers]代表的是身份存储路径。
3.变更策略
第一种,在网络创建之前,修改configtx.yaml
假如我们将策略[peer/Propose]的value变更成[MyPolicy],首先我们需要在[Application.Policies]里面定义[MyPolicy].
Policies: &ApplicationDefaultPolicies
Readers:
Type: ImplicitMeta
Rule: "ANY Readers"
Writers:
Type: ImplicitMeta
Rule: "ANY Writers"
Admins:
Type: ImplicitMeta
Rule: "MAJORITY Admins"
MyPolicy:
Type: Signature
Rule: "OR('SampleOrg.admin')"
然后修改[Application: ACLs]
peer/Propose: /Channel/Application/Writers
→
peer/Propose: /Channel/Application/MyPolicy
第二种,对运行中的网络重新配置
具体动作参照下面链接,获得配置区块的内容。
https://hyperledger-fabric-cn.readthedocs.io/zh/1.3.0_zh-cn/channel_update_tutorial.html
在配置区块的[Application: policies]里面追加[MyPolicy],和configtx.yaml最初的配置一下,[Admins, Writers, Readers]已经存在区块里面了。
需要特别注意的是[msp_identifier]和[role]的设定值。
然后找到[peer/Propose]的定义位置,进行修改。
"peer/Propose": {
"policy_ref": "/Channel/Application/Writers"
→
"peer/Propose": {
"policy_ref": "/Channel/Application/MyPolicy"