All Products
Search
Document Center

Attribute-Based Access Control

Last Updated: Aug 12, 2019

User Access Control

Access control decisions can be made by chaincode (and by the Hyperledger Fabric runtime) based upon an identity’s attributes. This is called Attribute-Based Access Control, or ABAC for short.When enrolling a user identity, the certificate (ECert) may contain one or more attribute name and value. The chaincode then extracts an attribute’s value to make an access control decision.

For example, suppose that you are developing application app1 and want a particular chaincode operation to be accessible only by app1 administrators. Your chaincode could verify that the caller’s certificate (which was issued by a CA trusted for the channel) contains an attribute named app1Admin with a value of true.

More information about Hyperledger Fabric ABAC, please refer: Attribute-Based Access Control

Attribute Setting

When you create an organization user in the console, you can click “Superior” and set the user attributes.

abac-1

After creating the user, you can check the user attributes.abac-2

Attribute Setting Specification

  • Use delimiter “,” to split into different attributes
  • Use delimiter “=” to split into attribute name and value
  • Attribute name and value must consist of English letters or numbers
  • Attribute name and value are all string types

For example:

The attributes for “app1Admin=true,permissions=7” in user enrollment certificate will be:

  1. {"attrs":{"app1Admin":"true","permissions":"7","hf.Affiliation":"","hf.EnrollmentID":"abacUser1","hf.Type":"client"}}

Tips: The attributes hf.EnrollmentID, hf.Type and hf.Affiliation are automatically registered for every identity.

Extract user attributes in chaincode

More information, please refer: chaincode/shim/ext/cid

  1. id, err := cid.New(stub)
  2. fmt.Println("client ID object:")
  3. fmt.Println(id)
  4. if err != nil {
  5. return shim.Error(err.Error())
  6. }
  7. val, ok, err = cid.GetAttributeValue(stub, "permissions")
  8. if err != nil {
  9. return shim.Error(err.Error())
  10. }
  11. if !ok {
  12. return shim.Error("The client identity does not possess the attribute:permissions")
  13. }
  14. err := cid.AssertAttributeValue(stub, "permissions", "7")
  15. if err != nil {
  16. return shim.Error("The client identity does not have the permissions")
  17. }
  18. fmt.Println("permissions:")
  19. fmt.Println(val)