基于某些第三资源的参与者的超级账本交易许可

时间:2018-09-10 03:56:38

标签: hyperledger-fabric hyperledger hyperledger-composer

我正在研究Hyperledger的一些权限逻辑,当需要出现一种情况时,我需要在permission.acl条件下使用3个资源。

关于场景的简介让我们假设资源事务是t,需要为其授予读取权限,参与者是P,谁需要读取事务t。

现在,事务t包含资产A的标识符名称。 因此,我想提出一个条件,例如,如果资产A的Identifier(name)等于交易T名称,则将资产A注册器(将保留参与者名称)与参与者P标识符进行比较。如果比较成功,则向参与者P授予Resource(事务T)的读取权限。

例如代码段。

Asset ABC identified by name{
    o String name;
    --> Company registrar; (Company is type of participant)

}

Transaction CreateABC{
     o String name;
}

因此,如果包含createABC.name的资产具有等于P.getIdenitifer()的资产,则类型为Company的参与者P应当具有读取事务CreateABC的权限。

我已经阅读到我们可以在js文件中创建单独的函数,并从Permission.acl调用它,但是我还无法实现这种情况。

1 个答案:

答案 0 :(得分:1)

  1. 使用3种资源的示例如下(示例):

//首先,访问调用事务资源本身

rule Transaction_access {
    description: "Can generate transaction"
    participant: "org.acme.account.AccountTrader"
    operation: CREATE
    resource: "org.acme.account.TransferAmount"
    action: ALLOW
}

//接下来,是(示例)动态ACL规则,用于评估谁在完成交易之间

rule BiTrade_betweenTraders_only {
    description: "Only Allow Updatee between Transferor/Transferee via named transaction"
    participant(p): "org.acme.account.AccountTrader"
    operation: ALL
    resource(v): "org.acme.account.BankAccount"
    transaction(tx): "org.acme.account.TransferAmount"
  condition: ( p.getIdentifier() === v.owner.getIdentifier()  && v.getIdentifier() === tx.targetAccount.getIdentifier() )
    action: ALLOW
}

已更新项目2:

  1. 基于参与者(均来自交易对象)的资产所有权来授予对交易资源的访问权限的示例可能是:
rule my_restricted_Transaction_access {
           description: "as per description above"
           participant(p): "org.acme.account.AccountTrader"
           operation: CREATE
           resource(v): "org.acme.account.TransferAmount"
           condition: ( p.getIdentifier() === v.account.owner.getIdentifier() )
           action: ALLOW
}

其中TransferAmount可以定义为:

transaction TransferAmount {
   --> Account account   // asset
}

account有一个--> owner字段,该字段指向AccountTrader(在我的原始示例中为参与者,依此类推)等-请记住,您的ACL必须允许参与者访问相关资产和资产所有者也以资源为目标。

显然,这是一个简单的示例-但您可以在condition部分中定义函数(对模型进行等效检查)。如果您已将JavaScript脚本添加到/lib下的BNA中(并升级了Fabric上的业务网络以使其生效)-那么您只需要担心函数名称是否就是您所说的名称(同样,我发送给您的链接应提供使用中的清晰示例)。

  1. 将函数作为ACL条件的一部分很简单-在此github测试文件中可以看到一个示例->函数(JS)在https://github.com/hyperledger/composer/blob/master/packages/composer-tests-functional/systest/data/accesscontrols.js#L23,相应的(调用)ACL规则集是此处-> https://github.com/hyperledger/composer/blob/master/packages/composer-tests-functional/systest/data/accesscontrols.acl#L124

更新项目3:

例如在您的Permissions.acl文件中使用以下规则:

rule rule_func_condition {
    description: "Allow all participants access to all resources"
    participant(p): "org.acme.account.AccountTrader"
    operation: CREATE
    resource(a): "org.example.account.TransferAmount"
    condition: (testOwnership(a, p))
    action: ALLOW
}

放在/lib文件夹中的functions.js(或其他任何文件)中(或者,如果愿意,也可以将其作为您现有的logic.js使用):

/**
 * Test that the specified asset is owned by the specified participant.
 * @param {Resource} asset The asset.
 * @param {Resource} participant The participant.
 * @return {boolean} True if yes, false if no.
 */
function testOwnership(asset, participant) {
    return asset.owner.getIdentifier() === participant.getIdentifier();
}

其中assetparticipant对象传递到此特定函数示例中。

相关问题