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: allow overwriting casbin configuration #703

Conversation

josecelano
Copy link
Member

@josecelano josecelano commented Aug 7, 2024

This is an unstable feature. You can overwrite casbin configuration to change permissions for roles: guest, registered and admin.

You can do it by adding this new section to the TOML config file:

[unstable.auth.casbin]
model = """
[request_definition]
r = role, action

[policy_definition]
p = role, action

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = r.role == p.role && r.action == p.action
"""

policy = """
admin, GetAboutPage
admin, GetLicensePage
admin, AddCategory
admin, DeleteCategory
admin, GetCategories
admin, GetImageByUrl
admin, GetSettings
admin, GetSettingsSecret
admin, GetPublicSettings
admin, AddTag
admin, DeleteTag
admin, GetTags
admin, AddTorrent
admin, GetTorrent
admin, DeleteTorrent
admin, GetTorrentInfo
admin, GenerateTorrentInfoListing
admin, GetCanonicalInfoHash
admin, ChangePassword
admin, BanUser
registered, GetAboutPage
registered, GetLicensePage
registered, GetCategories
registered, GetImageByUrl
registered, GetPublicSettings
registered, GetTags
registered, AddTorrent
registered, GetTorrent
registered, GetTorrentInfo
registered, GenerateTorrentInfoListing
registered, GetCanonicalInfoHash
registered, ChangePassword
guest, GetAboutPage
guest, GetLicensePage
guest, GetCategories
guest, GetPublicSettings
guest, GetTags
guest, GetTorrent
guest, GetTorrentInfo
guest, GenerateTorrentInfoListing
guest, GetCanonicalInfoHash
"""

For example, if you want to force users to log in to see the torrent list, you can remove the following line from the policy:

guest, GenerateTorrentInfoListing

NOTICE: This is an unstable feature. It will panic with wrong casbin configuration, invalid roles, etcetera.

This is an unsatble feature. You can overwrite casbin configuration to
change permissions for roles:  guest, registered and admin.

You can do it by adding this toml file config section:

```toml
[unstable.auth.casbin]
model = """
[request_definition]
r = role, action

[policy_definition]
p = role, action

[policy_effect]
e = some(where (p.eft == allow))

[matchers]
m = r.role == p.role && r.action == p.action
"""

policy = """
admin, GetAboutPage
admin, GetLicensePage
admin, AddCategory
admin, DeleteCategory
admin, GetCategories
admin, GetImageByUrl
admin, GetSettings
admin, GetSettingsSecret
admin, GetPublicSettings
admin, AddTag
admin, DeleteTag
admin, GetTags
admin, AddTorrent
admin, GetTorrent
admin, DeleteTorrent
admin, GetTorrentInfo
admin, GenerateTorrentInfoListing
admin, GetCanonicalInfoHash
admin, ChangePassword
admin, BanUser
registered, GetAboutPage
registered, GetLicensePage
registered, GetCategories
registered, GetImageByUrl
registered, GetPublicSettings
registered, GetTags
registered, AddTorrent
registered, GetTorrent
registered, GetTorrentInfo
registered, GenerateTorrentInfoListing
registered, GetCanonicalInfoHash
registered, ChangePassword
guest, GetAboutPage
guest, GetLicensePage
guest, GetCategories
guest, GetPublicSettings
guest, GetTags
guest, GetTorrent
guest, GetTorrentInfo
guest, GenerateTorrentInfoListing
guest, GetCanonicalInfoHash
"""
```

For example, if you wnat to force users to login to see the torrent list
you can remove the following line from the policy:

```
guest, GenerateTorrentInfoListing
```

NOTICE: This is an unstable feature. It will panic with wrong
casbin configuration, invalid roles, etcetera.
@josecelano josecelano self-assigned this Aug 7, 2024
@josecelano josecelano requested a review from mario-nt August 7, 2024 10:17
@josecelano josecelano linked an issue Aug 7, 2024 that may be closed by this pull request
@josecelano josecelano requested a review from da2ce7 August 7, 2024 10:17
@josecelano josecelano added this to the v3.0.0 milestone Aug 7, 2024
@josecelano
Copy link
Member Author

ACK c1a5c25

@josecelano josecelano merged commit 469922e into torrust:develop Aug 7, 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow overwriting hardcoded casbin configuration
1 participant