-
Notifications
You must be signed in to change notification settings - Fork 23
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
Discord permissions system example #145
Closed
Closed
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c01ec20
add basic discord example
oflatt 3bda1a5
simplify discord policies.cedar
oflatt 4472038
in-progress generalization of discord permission system
oflatt f1f0366
add oflatt as owner
oflatt cda0c7f
test case for announcements channel
oflatt 6bd9dc4
working on readme
oflatt d5590fd
visualization
oflatt 821dd67
more detailed readme
oflatt 6d16748
fix bug in owner role
oflatt fdb1e73
fix up
oflatt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
cedar-example-use-cases/discord/ALLOW/oflatt_manage_role.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"principal": "User::\"oflatt\"", | ||
"action": "Action::\"ManageRole\"", | ||
"resource": "Role::\"everyone\"", | ||
"context": {} | ||
} |
6 changes: 6 additions & 0 deletions
6
cedar-example-use-cases/discord/ALLOW/yihong_send_message.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"principal": "User::\"yihong\"", | ||
"action": "Action::\"SendMessage\"", | ||
"resource": "Server::\"test\"", | ||
"context": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"principal": "User::\"yihong\"", | ||
"action": "Action::\"KickMember\"", | ||
"resource": "Server::\"test\"", | ||
"context": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"principal": "User::\"yihong\"", | ||
"action": "Action::\"ManageRole\"", | ||
"resource": "Role::\"everyone\"", | ||
"context": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Cedar Discord Example | ||
|
||
This repository contains a limited model of the [discord permissions system](https://support.discord.com/hc/en-us/articles/206029707-Setting-Up-Permissions-FAQ). | ||
|
||
|
||
The file `src/main.rs` sets up example users and demonstrates they have different permissions based on the different roles. | ||
Discord is interesting because users may have multiple roles and some users may also set the permissions of other roles dynamically. | ||
In this example, we implement this functionality by using | ||
Cedar's parent system to build a DAG that looks something like this: | ||
|
||
``` | ||
Permission::"SendMessage" Permission::"KickMember" | ||
▲ ▲ ▲ | ||
│ └───────────────────┐ │ | ||
│ │ │ | ||
Role::"everyone" Role::"admin" | ||
▲ ▲ | ||
│ │ | ||
User::"yihong" User::"oflatt" | ||
``` | ||
|
||
|
||
We can then user Cedar's `in` construct to check if the permission | ||
is reachable from a given user. | ||
Note that it's currently unclear if this is the best way to use | ||
Cedar for discord's permissions model. Another approach is to generate | ||
many Cedar policies, one per role and permission pair. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
[ | ||
{ | ||
"uid": { | ||
"type": "Server", | ||
"id": "general" | ||
}, | ||
"attrs": {}, | ||
"parents": [] | ||
}, | ||
{ | ||
"uid": { | ||
"type": "Permission", | ||
"id": "SendMessage" | ||
}, | ||
"attrs": {}, | ||
"parents": [] | ||
}, | ||
{ | ||
"uid": { | ||
"type": "Role", | ||
"id": "everyone" | ||
}, | ||
"attrs": {}, | ||
"parents": [ | ||
{ | ||
"type": "Permission", | ||
"id": "SendMessage" | ||
} | ||
] | ||
}, | ||
|
||
{ | ||
"uid": { | ||
"type": "User", | ||
"id": "yihong" | ||
}, | ||
"attrs": {}, | ||
"parents": [ | ||
{ | ||
"type": "Role", | ||
"id": "everyone" | ||
} | ||
] | ||
}, | ||
{ | ||
"uid": { | ||
"type": "User", | ||
"id": "oflatt" | ||
}, | ||
"attrs": {}, | ||
"parents": [ | ||
{ | ||
"type": "Role", | ||
"id": "owner" | ||
} | ||
] | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Allow SendMessage when the user has the SendMessage permission | ||
permit ( | ||
oflatt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
principal in Permission::"SendMessage", | ||
action == Action::"SendMessage", | ||
resource == Server::"test" | ||
); | ||
|
||
permit ( | ||
principal in Permission::"KickMember", | ||
action == Action::"KickMember", | ||
resource == Server::"test" | ||
); | ||
|
||
permit ( | ||
principal in Role::"owner", | ||
action == Action::"ManageRole", | ||
resource == Role::"everyone" | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// discord permissions, (e.g. SendMessage) | ||
entity Permission; | ||
|
||
// discord roles, (e.g. the default "everyone" role) | ||
// discord roles have user-configurable permissions | ||
entity Role in [Permission]; | ||
|
||
// discord users, the entity id being the user id | ||
// discord users may have multiple roles | ||
entity User in [Role]; | ||
|
||
// TODO: add Channels | ||
// permissions in discord are specific to channels | ||
|
||
// a discord server | ||
// currently, we only consider a single server "test" | ||
entity Server; | ||
|
||
|
||
action SendMessage, KickMember appliesTo { | ||
principal: [User], | ||
resource: [Server] | ||
}; | ||
|
||
action ManageRole appliesTo { | ||
principal: [User], | ||
resource: [Role] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
IIUC Discord correctly, a role is assigned permissions for a particular channel. So I don't see how it makes sense for the hierarchy to just relate
Role
toPermission
.I would think you need to set it up so that you have
Channel
resource, and that when the operator assigns permissions to a channel for a role, you basically create an ad hoc policy that expresses those permissions.You also seem to be missing the concepts of
Category
for channels (which can be "synced" or not), and the fact that permissions can apply to all channels (server wide). I would think you need aServer
object which channels arein
.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 ideas!
I suggest that we merge this PR without channels (I'll re-name Channel to Server for now)
I'll submit a follow-up PR that introduces channels, and another for categories.