Permissions
Status | Accepted |
|---|---|
Stakeholders | @武宮誠 |
Outcome |
|
Due date | Dec 4, 2020 |
Owner | @Egor Ivkov |
Background
Iroha Special Instructions and Iroha Queries processing requires a permissions based security model.
Whitepaper and Iroha v1 documentation were researched.
Problem
The White Paper requires protection of data from unauthorized read and write access.
Iroha 1 documentation gives a Permission's definition:
A named rule that gives the privilege to perform a command. Permission cannot be granted to an account directly, instead, account has roles, which are collections of permissions. Although, there is an exception, see Grantable Permission.
and Grant-able Permission:
Only grantable permission is given to an account directly. An account that holds grantable permission is allowed to perform some particular action on behalf of another account. For example, if account a@domain1 gives the account b@domain2 a permission that it can transfer assets — then b@domain2 can transfer assets of a@domain1 to anyone.
As you can see permissions were a first-level entities in Iroha 1 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
Customizable permissions check logic
Customizable permission type
Permission check logic is written in pure rust - which is a turing complete and convenient language while ISIs are not yet there.
Faster than WASM
Does not introduce additional complexity as WASM does.
Cons
Can be customized only at compile time, can not be stored in genesis
Alternatives
Use Iroha 1 approach with roles and grantable permissions and do hardcoded permissions checks inside instructions
Pros:
Tested in already running blockchains like Bakong and Byacco
Cons:
Hardcoded permission model - not possible to suit to different types of blockchains
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.
Pros:
Customizable permissions check logic
Can be changed at runtime and stored in file
Cons:
ISIs and Queries are not mature enough to write complex logic that might be needed for permission checks
Triggers design is not finalized and they are not implemented.
Use WASM permission check functions
Pros:
Customizable permissions check logic
Can be changed at runtime and stored in file
Can be written in any language that can be compiled to WASM
Cons:
WASM execution is in general slower
Types through all the codebase will need to be adapted to be compatible with WASM
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