温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Hyperledger composer访问控制语言怎么用

发布时间:2021-12-06 15:10:13 来源:亿速云 阅读:169 作者:小新 栏目:互联网科技

这篇文章主要为大家展示了“Hyperledger composer访问控制语言怎么用”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“Hyperledger composer访问控制语言怎么用”这篇文章吧。

    Hyperledger Composer包含访问控制语言(ACL),它提供对域模型元素的声明式访问控制。通过定义ACL规则,您可以确定允许哪些用户/角色在业务网络的域模型中创建,读取,更新或删除元素。

    1、授予网络访问控制权

     使用系统命名空间授予网络访问权限。系统名称空间始终org.hyperledger.composer.system.Network用于网络访问和org.hyperledger.composer.system所有访问。以下访问控制规则为NetworkControl参与者授予对网络命令使用所有操作的权限。

rule NetworkControlPermission {
  description:  "NetworkControl can access network commands"
  participant: "org.example.basic.NetworkControl"
  operation: ALL
  resource: "org.hyperledger.composer.system.Network"
  action: ALLOW
}

以下访问控制规则将允许所有参与者访问业务网络中的所有操作和命令,包括网络访问和业务访问。

rule AllAccess {
  description: "AllAccess - grant everything to everybody"
  participant: "org.hyperledger.composer.system.Participant"
  operation: ALL
  resource: "org.hyperledger.composer.system.**"
  action: ALLOW
}

    2、访问控制规则的评估

    业务网络的访问控制由一组有序的ACL规则来定义。规则按顺序进行评估,条件匹配的第一条规则决定访问是被授予还是拒绝。如果没有规则匹配,则访问被拒绝

    ACL规则是在permissions.acl业务网络的根目录中调用的文件中定义的。如果该业务网络中缺少该文件,则允许所有访问。

    3、访问控制规则语法

    有两种类型的ACL规则:简单ACL规则和条件ACL规则。简单规则用于控制参与者类型或参与者实例对名称空间或资产的访问。例如,下面的规则指出任何org.example.SampleParticipant类型的实例都可以对所有实例执行所有操作org.example.SampleAsset

rule SimpleRule {
    description: "Description of the ACL rule"
    participant: "org.example.SampleParticipant"
    operation: ALL
    resource: "org.example.SampleAsset"
    action: ALLOW
}

有条件的ACL规则为参与者和被访问的资源引入变量绑定,以及布尔型JavaScript表达式,如果为true,则参与者可以允许或拒绝资源访问。例如,下面的规则指出,任何org.example.SampleParticipant类型的实例都可以在org.example.SampleAssetIF的所有实例上执行ALL操作,参与者是资产的所有者。

rule SampleConditionalRule {
    description: "Description of the ACL rule"
    participant(m): "org.example.SampleParticipant"
    operation: ALL
    resource(v): "org.example.SampleAsset"
    condition: (v.owner.getIdentifier() == m.getIdentifier())
    action: ALLOW
}

有条件的ACL规则也可以指定一个可选的事务子句。当指定事务子句时,如果参与者提交了事务,并且该事务是指定类型,则ACL规则仅允许参与者访问资源。例如,下面的规则指出,任何org.example.SampleParticipant类型的实例都可以对org.example.SampleAssetIF的所有实例执行ALL操作,参与者是资产的所有者,并且参与者提交了该org.example.SampleTransaction类型的事务以执行操作。

rule SampleConditionalRuleWithTransaction {
    description: "Description of the ACL rule"
    participant(m): "org.example.SampleParticipant"
    operation: READ, CREATE, UPDATE
    resource(v): "org.example.SampleAsset"
    transaction(tx): "org.example.SampleTransaction"
    condition: (v.owner.getIdentifier() == m.getIdentifier())
    action: ALLOW
}

可以定义多个ACL规则,从概念上定义决策表。决策树的行为定义访问控制决策(ALLOW或DENY)。如果决策表无法匹配,默认情况下,访问被拒绝。

资源定义了ACL规则适用的内容。这可以是一个类,名称空间内的所有类或名称空间下的所有类。它也可以是一个类的实例。

资源示例:

  • 命名空间:org.example。*

  • 命名空间(递归):org.example。**

  • 命名空间中的类:org.example.Car

  • 类的实例:org.example.Car#ABC123

操作标识规则管理的操作。支持四种操作:CREATE,READ,UPDATE和DELETE。您可以使用ALL指定规则管理所有支持的操作。或者,您可以使用逗号分隔列表来指定规则管理一组支持的操作。

参与者定义已提交交易进行处理的个人或实体。如果指定了参与者,他们必须存在于参与者注册表中。PARTICIPANT可以选择性地绑定到一个变量以用于PREDICATE。特殊值“ANY”可以用来表示参与者类型检查没有针对规则执行。

事务定义了参与者为了对指定资源执行指定操作而必须提交的事务。如果指定了此子句,并且参与者未提交此类型的事务 - 例如,他们正在使用CRUD API - 则ACL规则不允许访问。

条件是绑定变量上的布尔型JavaScript表达式。任何在表达式中合法的JavaScript表达式都if(...)可以在这里使用。用于ACL规则条件的JavaScript表达式可以引用脚本文件中的JavaScript实用程序函数。这允许用户轻松实现复杂的访问控制逻辑,并在多个ACL规则中重复使用相同的访问控制逻辑功能。

行动确定规则的行为。它必须是:允许,拒绝。

    4、举例

    示例ACL规则(按评估顺序):

rule R1 {
    description: "Fred can DELETE the car ABC123"
    participant: "org.example.Driver#Fred"
    operation: DELETE
    resource: "org.example.Car#ABC123"
    action: ALLOW
}

rule R2 {
    description: "regulator with ID Bill can not update a Car if they own it"
    participant(r): "org.example.Regulator#Bill"
    operation: UPDATE
    resource(c): "org.example.Car"
    condition: (c.owner == r)
    action: DENY
}

rule R3 {
    description: "regulators can perform all operations on Cars"
    participant: "org.example.Regulator"
    operation: ALL
    resource: "org.example.Car"
    action: ALLOW
}

rule R4 {
    description: "Everyone can read all resources in the org.example namespace"
    participant: "ANY"
    operation: READ
    resource: "org.example.*"
    action: ALLOW
}

rule R5 {
    description: "Everyone can read all resources under the org.example namespace"
    participant: "ANY"
    operation: READ
    resource: "org.example.**"
    action: ALLOW
}

规则从顶部(最具体)到底部(最不具体)进行评估。一旦参与者,操作和资源匹配规则,则不评估后续规则。

这种排序使决策表更快地扫描人类和计算机。如果没有ACL规则触发,则访问控制决策是拒绝。

以上是“Hyperledger composer访问控制语言怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI