Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: RBAC authentication contract and role library #580

Merged
merged 5 commits into from
Dec 4, 2017

Conversation

shrugs
Copy link
Contributor

@shrugs shrugs commented Nov 24, 2017

  • Roles.sol is a library for convenience functions on the Role struct that maps addresses to whether or not they have this role
  • RBAC.sol is a contract providing storage and accessors for the roles, indexed by strings (which are compacted in memory)

Questions

  • is it worth indexing roles by an Enum instead? This would require some casting to uints
  • are events something RBAC.sol should be concerned with?

@shrugs
Copy link
Contributor Author

shrugs commented Nov 27, 2017

looks like a flaky test. is there a re-run option?

@frangio
Copy link
Contributor

frangio commented Nov 27, 2017

Thanks @shrugs!

I was thinking of having RBAC be Ownable and exposing admin functionality to the owner. I feel like it will always be needed and we should aim to reduce boilerplate. What do you think?

is it worth indexing roles by an Enum instead? This would require some casting to uints

I understand the motivation, but I think I prefer strings to uints. They both have issues though... If we go with strings we should probably recommend that users of the library define constant variables with their role names.

@frangio
Copy link
Contributor

frangio commented Nov 27, 2017

are events something RBAC.sol should be concerned with?

Do you mean events as in e.g. RoleAssigned(string, address)? Yes, absolutely. I think RBAC should be like a more general Ownable.

@shrugs
Copy link
Contributor Author

shrugs commented Nov 28, 2017

@frangio what do you think about making RBAC ownable, but using its own access control scheme? i.e., not using Ownable, but providing a default "owner" role and making msg.sender owner by default, and providing an onlyOwner modifier and transferOwnership method? I think it'd be weird if RBAC depended on Ownership.sol.

I'll add the events 👍

@shrugs
Copy link
Contributor Author

shrugs commented Nov 28, 2017

Although, how important is the owner public variable? If we want to match the Ownable interface, we'd need an owner() getter, which requires storing the current owner address.

We can either keep track of the owner (in which case we just inherit from Ownable and call it a day) or we can deviate from the interface and end up with something like:

// should we prefix this with Log to match current standards, or keep it as it is to match the previous interface? if we're going to deviate from the ownable interface at all, I'd prefer to update this to include Log as well.
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
function isOwner(address addr) external returns (bool);
function transferOwnership(address addr) onlyOwner public;
modifier onlyOwner();

and users can see if a specific address is owner by calling isOwner(address).

@frangio
Copy link
Contributor

frangio commented Nov 30, 2017

Hm, okay, it might be a bit weird/confusing to have two different permission mechanisms in one contract (Ownable + RBAC).

Let's not worry about matching the Ownable interface, and just have a specific role who can add and remove addresses from roles. Since we're deviating from Ownable, how about calling the role:
const ADMIN_ROLE = "admin";

I'm guessing this means making RBAC#addRole (etc.) not internal but public and only callable by an "admin". The view functions should also be public IMO. This makes it very easy to use I think.

@shrugs
Copy link
Contributor Author

shrugs commented Dec 1, 2017

If we're going to bake in the ability for admin's to add/remove roles, there are two api surfaces; the internal, no-constraint CRUD operations and the onlyAdmin management operations.

So I've added adminAddRole and adminRemoveRole which are onlyAdmin public, which should cover most usecases.

I also rebased on master.

@chuawengkwong
Copy link

chuawengkwong commented Dec 1, 2017 via email

@shrugs
Copy link
Contributor Author

shrugs commented Dec 4, 2017

@frangio I've updated the event names and tested them, as well as rebasing on master to include the recent changes

@frangio
Copy link
Contributor

frangio commented Dec 4, 2017

Great! I'm ready to merge once the linter errors are fixed. 😃

@shrugs
Copy link
Contributor Author

shrugs commented Dec 4, 2017

😅 good catch; I should set up a precommit hook instead of hoping my editor catches it.

@frangio
Copy link
Contributor

frangio commented Dec 4, 2017

Hehe. We should look into how to make that easy for other developers too. 🙂

Thanks @shrugs!

@frangio frangio merged commit 83b941c into OpenZeppelin:master Dec 4, 2017
@shrugs shrugs deleted the feat/rbac branch December 4, 2017 15:36
@chuawengkwong
Copy link

chuawengkwong commented Dec 4, 2017 via email

ProphetDaniel pushed a commit to classicdelta/Smart-Contracts that referenced this pull request Mar 9, 2018
feat: RBAC authentication contract and role library
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants