Skip to content

chore: implement databased backend for custom roles #13295

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

Merged
merged 4 commits into from
May 16, 2024

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented May 16, 2024

Includes db schema and dbauthz layer for upserting custom roles. Unit test in customroles_test.go verify against escalating permissions through this feature.

Copy link
Member Author

Emyrk commented May 16, 2024

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @Emyrk and the rest of your teammates on Graphite Graphite

@Emyrk Emyrk force-pushed the stevenmasley/custom_site_db branch from a75d657 to 2187c33 Compare May 16, 2024 14:51
@Emyrk Emyrk changed the base branch from main to stevenmasley/custom_role_prep May 16, 2024 14:51
@Emyrk Emyrk force-pushed the stevenmasley/custom_site_db branch from 2187c33 to 1674885 Compare May 16, 2024 15:02
@Emyrk Emyrk marked this pull request as ready for review May 16, 2024 15:02
@Emyrk Emyrk force-pushed the stevenmasley/custom_site_db branch from 4060c07 to c58a6fd Compare May 16, 2024 15:26
@Emyrk Emyrk force-pushed the stevenmasley/custom_role_prep branch from 3b8ae70 to 65ec798 Compare May 16, 2024 15:30
@Emyrk Emyrk force-pushed the stevenmasley/custom_site_db branch 2 times, most recently from 88ca559 to 96d1527 Compare May 16, 2024 15:44
@Emyrk Emyrk requested a review from johnstcn May 16, 2024 15:56
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

Just a few nits / comments, but I don't think I need to review again.

Mainly unsure of stuffing the OrgID into the role name in the DB.

Comment on lines +2 to +4
-- name is globally unique. Org scoped roles have their orgid appended
-- like: "name":"organization-admin:bbe8c156-c61e-4d36-b91e-697c6b1477e8"
name text primary key,
Copy link
Member

Choose a reason for hiding this comment

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

What's the benefit of squashing the OrgID into the name?
Will this not make it more difficult if we want to filter roles by org?
Why not have it as a separate column?

Copy link
Member Author

Choose a reason for hiding this comment

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

I was thinking about this, and I'm not 100% sure at present. Maybe another column is better.

This PR only addresses site wide permissions, and once multi-org is a bit farther, I will add org permissions. When I get to that step 2, I feel I'll be able to make a better judgement call.

Regardless, the name will likely include the org id even if there is an org column. Because that is the name of the role. Even our builtins have the org appended, and the ui just ignores it.

Comment on lines +212 to +213
ActionDelete: actDef("ability to unassign roles"),
ActionCreate: actDef("ability to create/delete/edit custom roles"),
Copy link
Member

Choose a reason for hiding this comment

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

Suggestion, probably out of scope: should we have a separate RBAC resource UserRoleAssignment instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we can have 1 resource for site role assignment and create, and 1 resource for org assignment and create. But I am going to push this until I do the UX imo

Comment on lines +252 to +258
Name: "CreateCustomRole",
Actions: []policy.Action{policy.ActionCreate},
Resource: rbac.ResourceAssignRole,
AuthorizeMap: map[bool][]authSubject{
true: {owner},
false: {userAdmin, orgAdmin, orgMemberMe, otherOrgAdmin, otherOrgMember, memberMe, templateAdmin},
},
Copy link
Member

Choose a reason for hiding this comment

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

👍 This is fine for now, but I can potentially see folks wanting to allow UserAdmins / OrgAdmins some level of control in future...

...maybe they just need to make a custom role? 😄

Copy link
Member Author

Choose a reason for hiding this comment

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

Lol, yea I'm going to push this until I get to the UX. For this PR stack, I'm just getting custom roles to work.

Once I start building UX, I will revist who exactly should have this permission. But it could just be a custom role too as you said 🤷‍♂️

@Emyrk Emyrk force-pushed the stevenmasley/custom_site_db branch from 96d1527 to 992c845 Compare May 16, 2024 17:07
Base automatically changed from stevenmasley/custom_role_prep to main May 16, 2024 17:07
Emyrk and others added 3 commits May 16, 2024 12:08
Includes db schema and dbauthz layer for upserting custom roles.
For now, only owners can assign custom roles
@Emyrk Emyrk force-pushed the stevenmasley/custom_site_db branch from 992c845 to a6996f6 Compare May 16, 2024 17:09
@Emyrk Emyrk merged commit cf91eff into main May 16, 2024
27 checks passed
@Emyrk Emyrk deleted the stevenmasley/custom_site_db branch May 16, 2024 18:11
@github-actions github-actions bot locked and limited conversation to collaborators May 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants