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

#615 Use Casbin for the authorization layer #624

Merged

Conversation

mario-nt
Copy link
Contributor

@mario-nt mario-nt commented Jun 7, 2024

Resolves #615

@mario-nt mario-nt force-pushed the 615-implement-casbin-authorization-layer branch from bed7d63 to 67b979b Compare June 11, 2024 17:37
@josecelano josecelano added the Needs Rebase Base Branch has Incompatibilities label Jun 11, 2024
@mario-nt mario-nt force-pushed the 615-implement-casbin-authorization-layer branch from 4b9ed92 to b787304 Compare June 11, 2024 22:28
@mario-nt mario-nt force-pushed the 615-implement-casbin-authorization-layer branch from e9cd419 to fc886f9 Compare June 17, 2024 22:32
@mario-nt mario-nt force-pushed the 615-implement-casbin-authorization-layer branch from fc886f9 to 9d6f62e Compare June 18, 2024 13:20
@mario-nt mario-nt marked this pull request as ready for review June 18, 2024 13:39
@mario-nt mario-nt requested a review from josecelano June 18, 2024 13:39
Copy link
Member

@josecelano josecelano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mario-nt, I have some questions:

Policy

The policy

p, true, AddCategory
p, true, DeleteCategory
p, true, GetSettings
p, true, GetSettingsSecret
p, true, AddTag
p, true, DeleteTag
p, true, DeleteTorrent
p, true, BanUser

I was expecting something like this:

p, admin, AddCategory
p, admin, DeleteCategory
p, admin, GetSettings
p, admin, GetSettingsSecret
p, admin, AddTag
p, admin, DeleteTag
p, admin, DeleteTorrent
p, admin, BanUser

Missing cases

There are still some authorization points not included in casbin, like the one to update a torrent metadata:

// Check if user is owner or administrator
// todo: move this to an authorization service.
if !(torrent_listing.uploader == updater.username || updater.administrator) {
    return Err(ServiceError::Unauthorized);
}  

Load casbin config from string

As we discussed some weeks ago, it would be good to load the model.conf and policy.csvfrom strings. Otherwise, we have to include those files in the deployment/distribution/containerization of the app. I mean, when you only have the app binary those files should be moved to the storage folder like the config toml files. That would be a good solution if we want to let users to change permissions, but for the time being, we are not planning to do that. It will be a nice feature to add for the next version (v3.1.0)

Make the other public actions permissions explicit

There are other public actions like:

  • See the torrents list.
  • See a torrent details.
  • Etc.

They are now public, but they could require the user to be logged-in in the future.

Maybe we should include them in the policy:

p, guest, SearchTorrents
p, guest, SeeTorrentDetails
...

In fact, in the future we could implement the full-private mode by only changing the casbin model. We could allow the user to define their own model or we can keep casbin as a implementation detail and define to Index modes (public and private), and define a casbin model for each.

cc @da2ce7

Copy link
Member

@josecelano josecelano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mario-nt It looks very good now. The only thing I'm not sure is the roles names. In the future we could have more "registered" users. In fact, the admin is also a registered user. I had proposed this in my last review:

enum Role {
   Unknown, // We don't know the role because the user is not authenticated (guest).
   Member, // It's an uploader in the current version
   Admin,
}

What do you think? Anyway, the name you have used are the current names we are using in the code. We can open a new discussion to redefine those names.

@mario-nt mario-nt force-pushed the 615-implement-casbin-authorization-layer branch from d330a85 to 8d15a2f Compare July 3, 2024 12:10
@mario-nt mario-nt force-pushed the 615-implement-casbin-authorization-layer branch from 8d15a2f to 389acc4 Compare July 3, 2024 12:23
@mario-nt mario-nt marked this pull request as ready for review July 3, 2024 12:51
@mario-nt mario-nt requested a review from josecelano July 3, 2024 12:52
@josecelano
Copy link
Member

ACK 389acc4

@josecelano josecelano merged commit 2a3bd23 into torrust:develop Jul 3, 2024
10 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Rebase Base Branch has Incompatibilities
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use Casbin for the authorization layer
3 participants