Skip to content

feat: Implied 'member' roles for site and organization #1917

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 9 commits into from
Jun 1, 2022

Conversation

Emyrk
Copy link
Member

@Emyrk Emyrk commented May 31, 2022

What this does

This modifies the sql query that fetchs roles for authorization to include 'member' and 'organization-member' automatically. This implication means you can never be a user of the platform, and not be a member. And if you are in an organization, you are a organization-member of that org.

This just makes sense, as a user with no roles doesn't make much sense. This just makes sure a user with "no roles" never exists. An organization-member always implies they have their member role. It was weird you could have a user/member with no roles.

UI implications

'member' is never shown on the ui anymore. TBD if that is good UX

As an admin

Screenshot from 2022-05-31 09-56-06

As a member

Screenshot from 2022-05-31 09-55-03

UX implications

You can never assign or remove any 'member' roles. They are automatic

@Emyrk Emyrk requested review from kylecarbs and johnstcn May 31, 2022 14:57
@Emyrk Emyrk marked this pull request as ready for review May 31, 2022 14:57
@Emyrk Emyrk requested a review from spikecurtis May 31, 2022 22:59
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.

I was worried initially that this concept of "implied roles" makes things too complicated.

As the whole organization-member:<org_id> is just an internal implementation detail of the Rego, I had wondered if we could just stuff that whole issue inside the rbac package and keep it locked away in there.

But we still need to handle cases where users are a member of an org but do not have any additional roles in the org, just their membership.

We don't want to introduce any database dependencies in the rbac package at all, so the rbac package has no real way of just "magically" fetching the user org memberships.

I then thought about passing in the organization IDs of which the subject is a member into authz.Authorize as another argument, but then you can get into weird situations where a user does not have membership of an org but still has roles in that org.

So the solution here makes sense to me.

@@ -69,7 +69,7 @@ type UpdateUserPasswordRequest struct {
}

type UpdateRoles struct {
Roles []string `json:"roles" validate:"required"`
Roles []string `json:"roles" validate:""`
Copy link
Member

Choose a reason for hiding this comment

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

Does sending { "roles": [] } now mean "remove all roles assigned to the user but keep their membership"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. The UI and user will never see the member role. That role is only fetched for authorization.

Comment on lines +20 to 23
Name string `json:"name"`
// DisplayName is used for UI purposes. If the role has no display name,
// that means the UI should never display it.
DisplayName string `json:"display_name"`
Copy link
Member

Choose a reason for hiding this comment

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

Can we just not send this role to the UI at all? I think the whole org-member: thing is just the Rego leaking out a bit.

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 don't send it to the UI. I just use the DisplayName to indicate that.

Pretty much in the current form all role lists are compiled from the builtin const. So that list needs to be filtered for the UI. I thought it was easy to just use this field, since it has no purpose for the member roles now

Copy link
Member

Choose a reason for hiding this comment

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

Ah gotcha.

@Emyrk
Copy link
Member Author

Emyrk commented Jun 1, 2022

I was worried initially that this concept of "implied roles" makes things too complicated.

As the whole organization-member:<org_id> is just an internal implementation detail of the Rego, I had wondered if we could just stuff that whole issue inside the rbac package and keep it locked away in there.

But we still need to handle cases where users are a member of an org but do not have any additional roles in the org, just their membership.

We don't want to introduce any database dependencies in the rbac package at all, so the rbac package has no real way of just "magically" fetching the user org memberships.

I then thought about passing in the organization IDs of which the subject is a member into authz.Authorize as another argument, but then you can get into weird situations where a user does not have membership of an org but still has roles in that org.

So the solution here makes sense to me.

Pretty much had a similar thought process.

Comment on lines 37 to 39
// UserAuthorizationRoles returns the roles used for authorization.
// Comes from the ExtractAPIKey handler.
func UserAuthorizationRoles(r *http.Request) database.GetAuthorizationUserRolesRow {
Copy link
Member Author

Choose a reason for hiding this comment

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

These roles are only to be used for authorization now. (they already were, this is just different then the UI displayed roles now)

@@ -69,7 +69,7 @@ type UpdateUserPasswordRequest struct {
}

type UpdateRoles struct {
Roles []string `json:"roles" validate:"required"`
Roles []string `json:"roles" validate:""`
Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. The UI and user will never see the member role. That role is only fetched for authorization.

@Emyrk Emyrk merged commit cc87a0c into main Jun 1, 2022
@Emyrk Emyrk deleted the stevenmasley/implied_member branch June 1, 2022 14:07
kylecarbs pushed a commit that referenced this pull request Jun 10, 2022
* feat: Member roles are implied and never exlpicitly added
* Rename "GetAllUserRoles" to "GetAuthorizationRoles"
* feat: Add migration to remove implied roles
* rename user auth role middleware
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants