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

Improve the management of permissions #855

Closed
RiccardoM opened this issue May 5, 2022 · 1 comment · Fixed by #886
Closed

Improve the management of permissions #855

RiccardoM opened this issue May 5, 2022 · 1 comment · Fixed by #886
Assignees
Labels
kind/new-feature Propose the addition of a new feature that does not yet exist x/subspaces Issue on the x/subspaces module

Comments

@RiccardoM
Copy link
Contributor

Feature description

Currently when handling permissions inside a subspace, we use the same method that is used inside Linux-based systems: permissions are managed using a single uint value which bytes are read individually. Although this system works properly and allows us to store a single uint value per user/group, it has some downsides:

  1. permissions need to be sanitized before being stored, to make sure there are no collisions with values that might be added in the future;
  2. each time there is a new value to be added, the PermissionEverything needs to be updated accordingly. An example of this can be seen here: two permissions where added (PermissionInteractWithContent and PermissionEditOwnContent) and thus the PermissionEverything had to be updated as well;
  3. every time a module needs a permission that's specific for it, we need to update the subspaces module to include that permission as well.

Instead of doing this, I think we can have a better way of managing permissions that allows each module to register their own permissions without having to always modify the subspaces module each time there is a new one.

Implementation proposal

I suggest to create the following code

// Permission contains the details of a permission
type Permission struct {
  // Identifies the module which the permission is related to
  Module string 
  
  // Identifies the unique code of this permission within the module 
  Code uint16
}


// RegisterPermission allows to register the permission having the given code within the 
// provided module inside the list of supported permissions
func RegisterPermission(code uint16, module string) Permission {
  // ...
}

This way we could store a user permissions as follows:

PermissionPrefix | SubspaceID | UserAddress | -> ProtocolBuffer([]Permission)

Then, modules external to the subspaces one can simply register their custom permissions just like this:

var (
  PermissionCreateContent = subspacestypes.RegisterPermission(1, types.ModuleName)
  PermissionEditContent   = subspacestypes.RegisterPermission(2, types.ModuleName)
)

And use them as follows:

k.HasPermission(ctx, userAddress, 1, PermissionCreateContent)

Please let me know what you think about this. I will write an ADR if you think this change should be implemented @bragaz @dadamu

@RiccardoM RiccardoM added the kind/new-feature Propose the addition of a new feature that does not yet exist label May 5, 2022
@RiccardoM RiccardoM self-assigned this May 5, 2022
@RiccardoM RiccardoM added the x/subspaces Issue on the x/subspaces module label May 5, 2022
@leobragaz
Copy link
Contributor

This is a smart approach as it will allows to upgrade the permissions easily and require an on-chain upgrade each time the subspaces module is edited.

mergify bot pushed a commit that referenced this issue May 27, 2022
## Description

This ADR contains the details of how the current permission system can be improved, based on #855.



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html)
- [ ] included the necessary unit and integration [tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing)
- [ ] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
@mergify mergify bot closed this as completed in #886 Jun 8, 2022
mergify bot pushed a commit that referenced this issue Jun 8, 2022
## Description
This PR improves the permissions systems as described on [ADR-014](https://github.com/desmos-labs/desmos/blob/master/docs/architecture/adr-014-improve-permissions.md).

Closes: #855 



---

### Author Checklist

*All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.*

I have...

- [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [x] added `!` to the type prefix if API or client breaking change
- [x] targeted the correct branch (see [PR Targeting](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] provided a link to the relevant issue or specification
- [ ] followed the guidelines for [building modules](https://docs.cosmos.network/v0.44/building-modules/intro.html)
- [x] included the necessary unit and integration [tests](https://github.com/desmos-labs/desmos/blob/master/CONTRIBUTING.md#testing)
- [x] added a changelog entry to `CHANGELOG.md`
- [ ] included comments for [documenting Go code](https://blog.golang.org/godoc)
- [ ] updated the relevant documentation or specification
- [x] reviewed "Files changed" and left comments if necessary
- [x] confirmed all CI checks have passed

### Reviewers Checklist

*All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.*

I have...

- [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title
- [ ] confirmed `!` in the type prefix if API or client breaking change
- [ ] confirmed all author checklist items have been addressed
- [ ] reviewed state machine logic
- [ ] reviewed API design and naming
- [ ] reviewed documentation is accurate
- [ ] reviewed tests and test coverage
- [ ] manually tested (if applicable)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/new-feature Propose the addition of a new feature that does not yet exist x/subspaces Issue on the x/subspaces module
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants