Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.


Status
IN PROGRESS

Status
titleAccepted

Stakeholders
 Egor Ivkov Andrei Lebedev Mikhail Boldyrev 

Outcome

Jira
serverHyperledger JIRA
serverId6326cb0b-65b2-38fd-a82c-67a89277103b
keyIR-934

Due date
21 Aug
Owner
Nikita Puzankov 

Background

Iroha Special Instructions and Iroha Queries processing requires a permissions based security model.

Whitepaper and Iroha v1 documentation were researched. The proposal is to use already existing Iroha Special Instructions + Assets mechanisms for Permissions implementation. 

Problem

The White Paper requires protection of data from unauthorized read and write access.

...

As you can see permissions were a first-level entities in Iroha 1 while they can be easily implemented by Iroha Special Instructions + Assets.

Solution

Permissions can be implemented as Iroha 2 Module and stored as assets under account that "owns" them. Then all out-of-the-box Iroha Special Instructions and Iroha Queries will trigger execution of permission check.

Permission check is an execution of `FindAssetsByAccountIdAndAssetDefinitionId` Iroha Query result and check that set of assets is not empty (containing permission needed).

Additionally to solving the problem it brings interesting advantages:

  • we do not need to worry about Genesis Block and Network Setup problems (manual initial state configuration vs disabled state during genesis block commit) - we can place permissions module related entities (domains, asset definitions, triggers) commit after basic entities (root account, etc.) commit
  • usage of Iroha Queries as a declarative API gives an ability for performance improvements (caches, batch executions, etc.)
  • Iroha modules and users can "deploy" own permissions and checks without a need to compile them or to restart Iroha Peers
  • private blockchains that do not need permissions module can remove it from the Genesis Block
    • `+` growth in performance
    • `-` additional client-side security checks needed

Decisions

...

and had a strict hardcoded verification logic. Iroha1 was mainly planned to be used as a private blockchain and this system would work there. Yet Iroha2 is planned to be used in both private and public blockchains and therefore needs some degree of customization on how permissions are checked to implement some more complex cases.

Solution

As the Iroha project progresses towards being able to be used in different types of blockchains. It would be good to give more powers to developers. Therefore this RFC introduces a minimal Permission framework, which let's the developers of each blockchain have the power to set up their permission checks accordingly. Of course there will be an out of box implementations provided which can be used for simple blockchains, for more complex logic the developers will be able to define their completely own Permission checks implementation that would suit their needs.

TL;DR

  • Introduce Permission Checker trait
  • Make Iroha generic over `PermissionChecker` and `Permission` types
  • Implement out of box `IrohaPermissionChecker` with minimal checks and the ability to tweak it through the `IrohaPermissionCheckerBuilder`

Code Example


trait PermissionChecker<Permission> {
    pub fn check_permissions(instruction: ISI, authority: Id) -> Result<(), String>
}

Register<Permission, Account>: ISI #[derive(Encode, Decode, Serialize, Deserialize)] struct Account<Permission> { permissions: Vec<Permission>,
account_data: // .. other fields } struct Iroha<Permission, PC: PermissionChecker<Permission>> { pub checker: PC, // .. other fields }

Iroha<Iroha1Permission, Iroha1PermissionChecker>

enum Iroha1Permission {

}

Pros

  1. Customizable permissions check logic
  2. Customizable permission type
  3. Permission check logic is written in pure rust - which is a turing complete and convenient language while ISIs are not yet there.
  4. Faster than WASM
  5. Does not introduce additional complexity as WASM does.

Cons

  1. Can be customized only at compile time, can not be stored in genesis

...

Alternatives

  1. Use Iroha 1 approach with roles and grantable permissions and do hardcoded permissions :
    1. `+` Out-of-the-Box permissions grouping by roles
    2.  `-` hardcoded permissions checks and additional low-level logic
  2. Use assets, but do hardcoded permissions checks inside instructions
    1. `+` less client-side actions needed
    2. `-` no ability to clean genesis block  processing and configuration

Concerns

Assumptions

  • Iroha Triggers support pre-instruction hooks because it will be more effective to check permissions before instructions execution

Risks

...

  1. checks inside instructions
    1. Pros:
      1. Tested in already running blockchains like Bakong and Byacco
    2. Cons:
      1. Hardcoded permission model - not possible to suit to different types of blockchains
  2. Use Iroha Special Instructions as scripting for checking permissions + Assets mechanisms to store. With two options: implement permission checks as triggers, or simply another part of validation pipeline.
    1. Pros:
      1. Customizable permissions check logic
      2. Can be changed at runtime and stored in file
    2. Cons:
      1. ISIs and Queries are not mature enough to write complex logic that might be needed for permission checks
      2. Triggers design is not finalized and they are not implemented.
  3. Use WASM permission check functions
    1. Pros:
      1. Customizable permissions check logic
      2. Can be changed at runtime and stored in file
      3. Can be written in any language that can be compiled to WASM
    2. Cons:
      1. WASM execution is in general slower
      2. Types through all the codebase will need to be adapted to be compatible with WASM
      3. More research about the WASM libraries and execution is needed

Additional Information

  • This solution impacts the Genesis Block design
  • This makes Iroha closer to a framework