【问题标题】:How to restrict function calls to certain 'type' of users in Fabric?如何限制对 Fabric 中某些“类型”用户的函数调用?
【发布时间】:2019-07-16 02:26:30
【问题描述】:

我最近从使用 Composer 转向用 Go 编写 ChainCode。在 Composer 中,使用 ACL,我可以将某些事务限制为特定的 participant 类型。

我正在尝试构建一个多组织网络,其中用户“类型”被定义为 Go 中的结构 -- Client AgentManager

我希望Client 可以访问某些交易,Agent 可以访问一组不同的交易,而Manager 可以访问所有Agent 和更多交易。

如何使用 Fabric Go 链码实现这一点?感谢任何帮助!

谢谢

【问题讨论】:

标签: hyperledger-fabric hyperledger-fabric-sdk-go


【解决方案1】:

好吧,让我们假设 Alice 是一个代理。有一个函数 onlyAgent() 您要确保只能由 Alice 调用。会是这样的

func (t *SimpleChaincode) createParticipant (stub shim.ChaincodeStubInterface, args []string) pb.Response {
    username := args[0]; // This would be Alice
    type := args[1]; // This should be Agent
    user := &marble{type , username }
    userAsJsonBues, err := json.Marshal(user )
    err = stub.PutState(marbleName, userAsJsonBues);
    return shim.Success(nil);
}

func (t *SimpleChaincode) onlyAgent(stub shim.ChaincodeStubInterface, args []string) pb.Response {
    username := args[0]; // Expects to be Alice
    aliceAsBytes, err := stub.GetState(username)
    alice:= User{}
    err = json.Unmarshal(aliceAsBytes, &alice)
    // alice.user should return Agent. Perform whatever checks you want
}

这应该让您大致了解如何进行操作,以及需要记住的几件事

  1. 此示例要求将名称 Alice 作为onlyAgent 中的参数传递。我这样做是出于演示目的,从技术上讲,您可能希望提取 Alice 的证书,然后直接从中查询 Alice(我可以在 nodejs 链码中执行此操作,但似乎无法在 go 中找到确切的 API 调用)李>

【讨论】:

  • 谢谢。该代码不一定对我有用,但从您的评论中我能够进一步研究并发现 ABAC,将对其进行更深入的研究。
  • 是的,这是一个更好的例子,事情是我记得看到一个问题为此打开,但不确定该功能是否已推出/合并。在客户端证书中使用 attributes 可能是更好的方法,但我现在一直在使用我提到的方法。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-23
  • 1970-01-01
  • 2021-09-04
  • 1970-01-01
  • 2015-11-22
  • 1970-01-01
相关资源
最近更新 更多