-
Notifications
You must be signed in to change notification settings - Fork 373
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: p/demo/accesscontrol & p/demo/timelock #2307
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great stuff -- looks pretty good overall. There are some things that I think need to be changed and a bunch of other comments asking questions about why something is the way it is.
Co-authored-by: deelawn <[email protected]>
Co-authored-by: deelawn <[email protected]>
Co-authored-by: Manfred Touron <[email protected]>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2307 +/- ##
==========================================
- Coverage 63.32% 63.23% -0.09%
==========================================
Files 548 548
Lines 78511 80400 +1889
==========================================
+ Hits 49715 50841 +1126
- Misses 25443 26136 +693
- Partials 3353 3423 +70
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love the direction of this, thank you for the contribution 🙏
However, there are some things that need a bit more tweaking so we can get it just right 👌
Please check the comments and let me know 🙏
…rantRole functions
const ( | ||
RoleName = "roleName" | ||
Sender = "sender" | ||
Account = "account" | ||
NewAdminRole = "newAdminRole" | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we just place this directly in the events, and instead have as exported constants the events, in the format RoleCreatedEvent = "RoleCreated"
?
I suggest you put information about the keys of each event in the godoc of each event name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed it will bring more clarity
3b4c63a
} | ||
|
||
func validRoleName(name string) error { | ||
if len(name) > 30 || name == "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The limit on 30 seems kind of arbitrary for a package; more like a kind of validation that should be done, if anything, on the side of a realm (as an end-user application). But I don't expect many realms to publicly allow adding roles, anyway.
|
||
// Roles struct to store all Roles information | ||
type Roles struct { | ||
AllRoles []*Role |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AllRoles []*Role | |
Roles []*Role | |
UserToRoles avl.Tree // std.Address -> []*Role |
A suggestion. You'd then need to add the code to manage UserToRoles, but I think we should support being able to map a user to the roles they have.
(Of course, there should be a related function to modify it.)
// HasRole check if an account has a specific role | ||
func (r *Role) HasRole(account std.Address) bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't make sense. It should be Role.HasAccount
.
// RenounceRole allows an account to renounce a role it holds | ||
func (rs *Roles) RenounceRole(name string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say we remove this.
- Roles is not likely to be publicly exposed in a realm, anyway.
- But if it was, exposing
RenounceRole
means that theRoles
cannot be used for a role likebanned
; because the user can "renounce it".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make a case for how this is different / better than p/demo/acl
?
I'm not saying it's perfect, just that demo/
should probably contain one preferred ACL implementation. We can decide to move this one to p/<name>/accesscontrol
, or that one to p/nt/acl
. (cc'ing also @moul for an opinion on what to do here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although acl
and accesscontrol
may seem similar at first glance, accesscontrol
stands out due to its ability to implement role hierarchies as well as dynamic permission options
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you give an example? Namely, of where this distinction is useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see we're using std.PrevRealm()
to determine the owner and generally the "sender". This assumes there's an admin user doing management, and everyone else just following suit.
However, I think an equally possible flow is that of having a realm which has an access control list. In this case, actually, we shouldn't do any checks on PrevRealm(); the realm can just use it unexported. But I suggest you have an option for the ACL to not have a "owner"; in which case the PrevRealm checks are simply not performed. Allows someone else to compose other rules on top as well.
Btw if Roles is meant to be exposed in a realm, then its fields should be unexported.
} | ||
|
||
// TimeLockUtil stores the necessary parameters for the timelock operations | ||
type TimeLockUtil struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why Util?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Util
to represent a "toolbox" of essential parameters and methods needed for managing locking operations
You don't find the word explicit enough ? @thehowl
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it just seems redundant. Also, these "toolboxes" are generally discouraged in Go (and Gno): https://dave.cheney.net/2019/01/08/avoid-package-names-like-base-util-or-common
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank for shared the article on avoid-package-names
.
As a result changed TimelockUtil
to Timelock
0ced75a
We have developed two packages:
accesscontrol
andtimelock
inspired by openzeppelin contracts. These packages were created in collaboration with @mous1985 , @DIGIX666 , and myself.The
accesscontrol
package was primarily designed to support the development of thetimelock
package, but it can also be used independently for many other use cases.Features
Accesscontrol
The
accesscontrol
package provides a library for managing roles and permissions within Gno. It allows for the creation, assignment, and management of roles with specific administrative privileges, ensuring that only authorized accounts can perform certain actions.Timelock
The
timelock
package offers a library for scheduling, canceling, and executing time-locked operations in Gno. It ensures that operations are only carried out after a specified delay and provides mechanisms to manage and verify the status of these operations. The creation of theaccesscontrol
package was necessary to provide role and permission management required for the administrative tasks oftimelock
.Use Cases
Accesscontrol
Timelock
These examples of use cases are not exhaustive, and many other things are possible with these packages.
Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description