Comparing with public chain with open access and free transaction or query, consortium chain are required to have access control, diverse transactions, privacy protection in business level and high stability. Therefore, “permission” and “control” are strongly emphasized in the implementation of consortium chain.
In this case, FISCO BCOS has proposed a flexible and delicate permission control mechanism based on distributed storage, which performs fundamental technological supports for its governance. The permission control system manages permissions on contract deployment and table create/insert/update/delete operations (read is not included), based on the access mechanism of exterior accounts (tx.origin). In actual operations, each account owns one and only public and private key pair. Private key is for signature when sending transactions. The receiver will verify to know which account the transaction is from through the public key, helping the management and tracing back of transaction and regulation.
The rules of permission control include:
the minimum granularity of permission control is table, based on exterior accounts.
whitelist mechanism is adopted: all exterior accounts are default to have write/read permission.
permission table (_sys_table_access_) is used in permission control, if table name and account address are in the permission table, the account has write/read permission to the table; if not, account has only read permission.
Permission control based on distributed storage contains permissions of user table and sys table. User table is created by user contract. All user tables can set permissions. System table is built in FISCO BCOS network. The design of system table is introduced in Storage Documentation. Permission control of system table is as below:
|table name||data storage description||purpose of permission control|
||store all table structure||control contract deployment and table creation|
||store permission control information||control permission setting|
||store sealer and observer list||control node type setting|
||store cns list||control CNS using|
||store list of system config||control system config setting|
Targeting user table and each system table, SDK conducts permission management of three APIs:
public String grantUserTableManager(String tableName, String address)： set permission information according to user table name and exterior account address.
public String revokeUserTableManager(String tableName, String address)： remove permission information according to user table name and exterior account address.
public List<PermissionInfo> listUserTableManager(String tableName)： inquire permission information according to the user table name (each record contains exterior account address and valid block number).
public String grantDeployAndCreateManager(String address)： grant permission of contract deployment and user table creation to exterior account.
public String revokeDeployAndCreateManager(String address)： remove permission of contract deployment and user table creation of exterior account.
public List<PermissionInfo> listDeployAndCreateManager()： inquire permission records of contract deployment and user table creation.
public String grantPermissionManager(String address)： grant permission of management to exterior account.
public String revokePermissionManager(String address)： remove permission of management of exterior account.
public List<PermissionInfo> listPermissionManager()： inquire permission records of permission management.
public String grantNodeManager(String address)： grant node management permission to exterior account.
public String revokeNodeManager(String address)： remove node management permission of exterior account.
public List<PermissionInfo> listNodeManager()： inquire permission records of node management.
public String grantCNSManager(String address)： grant CNS permission of exterior account.
public String revokeCNSManager(String address)： remove CNS permission of exterior account.
public List<PermissionInfo> listCNSManager()： inquire CNS permission records.
public String grantSysConfigManager(String address)： grant system parameter management permission to exterior account.
public String revokeSysConfigManager(String address)： remove system parameter management permission of exterior account.
public List<PermissionInfo> listSysConfigManager()： inquire system parameter management permission records.
Set and remove permission API and return json string, containing code and msg fields. For operations with no permission, code is set to 50000 and msg defined as “permission denied”; for those granted with permission, code is 0 and msg “success”.
Permission information is stored in the form of system table, which is named sys_table_access with following fields:
The insertion or update to the permission table is validated in the next block instead of current block. When the state field is 0, it means that the permission record is in normal valid status; if 1, the permission record is removed and invalid.
Function design of permission control¶
Transaction information contains exterior account, pending table and operation methods. Pending table is user table or system table. As what shows below, system table manages system functions of blockchain; user table manages transactional function of blockchain. Exterior accounts can get permission information through permission table, and then manage system and transactional functions by operating user table and permission table.
The process of permission control: first, client end sends transaction request, node acquires transaction data to confirm exterior account, pending table and operation type; if it’s write operation, check the permission (from permission list), if it has permission, execute write operation; if not, reject write operation and return no permission; if it’s read operation, skip permission information check, execute read operation and return data. The process is shown below.
The operation methods of permission control in FISCO BCOS include:
non-developers can user permission function through console command, the detailed operation is introduced in Operation tutorial for permission control.
For developers, SDK has implemented 3 APIs (grant/remove/inquire) in light of user table and system table, so they can call PermissionService of SDK API to realize permission management.