9.3.3. Permissions

Hyperledger Iroha uses a role-based access control system to limit actions of its users. This system greatly helps to implement use cases involving user groups having different access levels — ranging from the weak users, who can’t even receive asset transfer to the super-users. The beauty of our permission system is that you don’t have to have a super-user in your Iroha setup or use all the possible permissions: you can create segregated and lightweight roles.

Maintenance of the system involves setting up roles and permissions, that are included in the roles. This might be done at the initial step of system deployment — in genesis block, or later when Iroha network is up and running, roles can be changed (if there is a role that can do that :)

This section will help you to understand permissions and give you an idea of how to create roles including certain permissions. Each permission is provided with an example written in Python that demonstrates the way of transaction or query creation, which require specific permission. Every example uses commons.py module, which listing is available at Supplementary Sources section.

9.3.4. List of Permissions

Permission Name

Category

Type

root

All Categories

Command and Query

can_create_account

Account

Command

can_set_detail

Account

Command

can_set_my_account_detail grantable

Account

Command

can_create_asset

Asset

Command

can_receive

Asset

Command

can_transfer

Asset

Command

can_transfer_my_assets grantable

Asset

Command

can_add_asset_qty

Asset Quantity

Command

can_subtract_asset_qty

Asset Quantity

Command

can_add_domain_asset_qty

Asset Quantity

Command

can_subtract_domain_asset_qty

Asset Quantity

Command

can_create_domain

Domain

Command

can_grant_can_add_my_signatory

Grant

Command

can_grant_can_remove_my_signatory

Grant

Command

can_grant_can_set_my_account_detail

Grant

Command

can_grant_can_set_my_quorum

Grant

Command

can_grant_can_transfer_my_assets

Grant

Command

can_add_peer

Peer

Command

can_remove_peer

Peer

Command

can_append_role

Role

Command

can_create_role

Role

Command

can_detach_role

Role

Command

can_add_my_signatory grantable

Signatory

Command

can_add_signatory

Signatory

Command

can_remove_my_signatory grantable

Signatory

Command

can_remove_signatory

Signatory

Command

can_set_my_quorum grantable

Signatory

Command

can_set_quorum

Signatory

Command

can_call_engine

Engine

Command

can_call_engine_on_my_behalf grantable

Engine

Command

can_grant_can_call_engine_on_my_behalf

Grant

Command

can_get_all_acc_detail

Account

Query

can_get_all_accounts

Account

Query

can_get_domain_acc_detail

Account

Query

can_get_domain_accounts

Account

Query

can_get_my_acc_detail

Account

Query

can_get_my_account

Account

Query

can_get_all_acc_ast

Account Asset

Query

can_get_domain_acc_ast

Account Asset

Query

can_get_my_acc_ast

Account Asset

Query

can_get_all_acc_ast_txs

Account Asset Transaction

Query

can_get_domain_acc_ast_txs

Account Asset Transaction

Query

can_get_my_acc_ast_txs

Account Asset Transaction

Query

can_get_all_acc_txs

Account Transaction

Query

can_get_domain_acc_txs

Account Transaction

Query

can_get_my_acc_txs

Account Transaction

Query

can_read_assets

Asset

Query

can_get_blocks

Block Stream

Query

can_get_roles

Role

Query

can_get_all_signatories

Signatory

Query

can_get_domain_signatories

Signatory

Query

can_get_my_signatories

Signatory

Query

can_get_all_txs

Transaction

Query

can_get_my_txs

Transaction

Query

can_get_peers

Peer

Query

can_get_my_engine_receipts

Engine receipts

Query

can_get_domain_engine_receipts

Engine receipts

Query

can_get_all_engine_receipts

Engine receipts

Query

9.3.5. Permissions Detailed

9.3.5.4. Supplementary Sources

commons.py
  1#
  2# Copyright Soramitsu Co., Ltd. All Rights Reserved.
  3# SPDX-License-Identifier: Apache-2.0
  4#
  5
  6from iroha import primitive_pb2
  7from iroha import Iroha, IrohaCrypto
  8import binascii
  9from time import time
 10
 11command = Iroha.command
 12
 13
 14def now():
 15    return int(time() * 1000)
 16
 17
 18def all_permissions():
 19    return [
 20        primitive_pb2.can_append_role,
 21        primitive_pb2.can_create_role,
 22        primitive_pb2.can_detach_role,
 23        primitive_pb2.can_add_asset_qty,
 24        primitive_pb2.can_subtract_asset_qty,
 25        primitive_pb2.can_add_peer,
 26        primitive_pb2.can_add_signatory,
 27        primitive_pb2.can_remove_signatory,
 28        primitive_pb2.can_set_quorum,
 29        primitive_pb2.can_create_account,
 30        primitive_pb2.can_set_detail,
 31        primitive_pb2.can_create_asset,
 32        primitive_pb2.can_transfer,
 33        primitive_pb2.can_receive,
 34        primitive_pb2.can_create_domain,
 35        primitive_pb2.can_read_assets,
 36        primitive_pb2.can_get_roles,
 37        primitive_pb2.can_get_my_account,
 38        primitive_pb2.can_get_all_accounts,
 39        primitive_pb2.can_get_domain_accounts,
 40        primitive_pb2.can_get_my_signatories,
 41        primitive_pb2.can_get_all_signatories,
 42        primitive_pb2.can_get_domain_signatories,
 43        primitive_pb2.can_get_my_acc_ast,
 44        primitive_pb2.can_get_all_acc_ast,
 45        primitive_pb2.can_get_domain_acc_ast,
 46        primitive_pb2.can_get_my_acc_detail,
 47        primitive_pb2.can_get_all_acc_detail,
 48        primitive_pb2.can_get_domain_acc_detail,
 49        primitive_pb2.can_get_my_acc_txs,
 50        primitive_pb2.can_get_all_acc_txs,
 51        primitive_pb2.can_get_domain_acc_txs,
 52        primitive_pb2.can_get_my_acc_ast_txs,
 53        primitive_pb2.can_get_all_acc_ast_txs,
 54        primitive_pb2.can_get_domain_acc_ast_txs,
 55        primitive_pb2.can_get_my_txs,
 56        primitive_pb2.can_get_all_txs,
 57        primitive_pb2.can_get_blocks,
 58        primitive_pb2.can_grant_can_set_my_quorum,
 59        primitive_pb2.can_grant_can_add_my_signatory,
 60        primitive_pb2.can_grant_can_remove_my_signatory,
 61        primitive_pb2.can_grant_can_transfer_my_assets,
 62        primitive_pb2.can_grant_can_set_my_account_detail
 63    ]
 64
 65
 66def genesis_block(admin, alice, test_permissions, multidomain=False):
 67    """
 68    Compose a set of common for all tests' genesis block transactions
 69    :param admin: dict of id and private key of admin
 70    :param alice: dict of id and private key of alice
 71    :param test_permissions: permissions for users in test domain
 72    :param multidomain: admin and alice accounts will be created in
 73    different domains and the first domain users will have admin right
 74    by default if True
 75    :return: a list of Iroha.command's
 76    """
 77    peer = primitive_pb2.Peer()
 78    peer.address = '127.0.0.1:50541'
 79    peer.peer_key = IrohaCrypto.derive_public_key(admin['key'])
 80    commands = [
 81        command('AddPeer', peer=peer),
 82        command('CreateRole', role_name='admin_role', permissions=all_permissions()),
 83        command('CreateRole', role_name='test_role', permissions=test_permissions)]
 84    if multidomain:
 85        commands.append(command('CreateDomain', domain_id='first', default_role='admin_role'))
 86    commands.extend([
 87        command('CreateDomain',
 88                domain_id='second' if multidomain else 'test',
 89                default_role='test_role'),
 90        command('CreateAccount',
 91                account_name='admin',
 92                domain_id='first' if multidomain else 'test',
 93                public_key=IrohaCrypto.derive_public_key(admin['key'])),
 94        command('CreateAccount',
 95                account_name='alice',
 96                domain_id='second' if multidomain else 'test',
 97                public_key=IrohaCrypto.derive_public_key(alice['key']))
 98    ])
 99    if not multidomain:
100        commands.append(command('AppendRole', account_id=admin['id'], role_name='admin_role'))
101    return commands
102
103
104def new_user(user_id):
105    private_key = IrohaCrypto.private_key()
106    if user_id.lower().startswith('admin'):
107        print('K{}'.format(private_key.decode('utf-8')))
108    return {
109        'id': user_id,
110        'key': private_key
111    }
112
113
114def hex(generator):
115    """
116    Decorator for transactions' and queries generators.
117
118    Allows preserving the type of binaries for Binary Testing Framework.
119    """
120    prefix = 'T' if generator.__name__.lower().endswith('tx') else 'Q'
121    print('{}{}'.format(prefix, binascii.hexlify(generator().SerializeToString()).decode('utf-8')))