Hyperledger Fabric:是否有一种方法可以阻止组织成员访问通道上链码内的特定智能合约?



假设我在同一通道上有两个组织,A和B,以及包含以下方法的链码:

  • queryA;
  • queryB(返回与queryA不同的数据集作为输出);
  • 创建;
  • 更新;
  • submitNewData。

如何限制对单个方法的访问,例如,a的成员只能访问create, update和queryA;B的成员只能访问submitNewData和queryB。因此,a的成员可以创建资产并修改字段的子集(使用"update"), B的成员只能修改字段的另一个子集(根据"submitNewData)而不能创建资产。

如果B的对等体执行了"对等链码调用";

我应该使用acl吗?但是我如何在链码中引用特定的智能合约呢?

你开始说"成员",后来又说"同伴"。

不能限制每个对等体的操作。每个安装了链码的连接到通道的对等端必须以相同的方式进行,以便链码以确定性的方式工作。

但是,当然,您可以通过评估请求者的用户ID、MSP ID、证书属性或任何您想要的东西来限制请求者的操作。例如,在Go链码中,它通常在BeforeTransaction函数中求值:


type SmartContract struct {
contractapi.Contract
}
func checkACL(ctx contractapi.TransactionContextInterface) error {
// Read incoming data from stub
stub := ctx.GetStub()
// Extract operation name
operation, parameters := stub.GetFunctionAndParameters()
operationSplitted := strings.Split(operation, ":")
operationName := operationSplitted[len(operationSplitted)-1]
// Get requestor info from stub
mspID, err := cid.GetMSPID(stub)
userID, err := cid.GetID(stub)
value, found, err := cid.GetAttributeValue(stub, "role")
// Evaluate your ACLs by contrasting the operation and the requestor your own way
// ...
// Return error when disallowed
// Operation allowed
return nil
}
func BeforeTransaction(ctx contractapi.TransactionContextInterface) error {
return checkACL(ctx)
}
func NewSmartContract() *SmartContract {
sc := new(SmartContract)
sc.BeforeTransaction = BeforeTransaction
// ...
return sc
}

最新更新