Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: Implement standard rbac.Subject to be reused everywhere#5881

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 4 commits intomainfromstevenmasley/standard_rbac_subject
Jan 26, 2023

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedJan 26, 2023
edited
Loading

This is purely a type refactor, and does not change any behavior

What this does

Before this PR, the rbac package expected the caller to hold the variousSubject fields, and pass them in as individual arguments:(subjectID string, roleNames ExpandableRoles, scope ScopeName, groups []string). This was ok in the beginning when it was just(ID, Roles), but it has grown toscope andgroups as well.

This change ensures all subject fields are tightly coupled, and less likely to be mistakenly used. It also simplifies usingrbac since the arguments are nowAutorize(ctx, subject, action, object).

The only downside is that logging still requires poking into the subject struct. But usage of the rbac package now takes less arguments.

What this enables

Forauthquerier interface we wanted to enable the use of aSystem actor. This actor needs to have custom roles that should not be available to the user. This newSubject struct accepts both user defined roles,RoleNames and explicitRoles.

This allows us to create custom roles that will never be returned via an api or any other exporting of roles (docs, enums, etc).

Minor bonus, this allows unit tests to call theAuthorize directly as it was using explicit Roles.

An rbac subject is created in multiple spots because of the way weexpand roles, scopes, etc. This difference in use creates a listof arguments which is unwieldy.Use of the expander interface lets us conform to a single subjectin every case
Comment on lines +22 to +27
type Subject struct {
ID string
Roles ExpandableRoles
Groups []string
Scope ExpandableScope
}
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This is the added type shared by all callers now.

Comment on lines +46 to +47
Authorize(ctx context.Context,subject Subject, action Action, object Object) error
Prepare(ctx context.Context,subject Subject, action Action, objectType string) (PreparedAuthorized, error)
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

This is the interface of the package changing to use less arguments.

return err
}
err := a.authorize(ctx, subject, action, object)
span.SetAttributes(attribute.Bool("authorized", err == nil))
Copy link
MemberAuthor

@EmyrkEmyrkJan 26, 2023
edited
Loading

Choose a reason for hiding this comment

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

This is better than an event, learned I can add attributes to a span after I started it. So it allows filtering the parent span on this attribute, which is what I want.

@@ -217,7 +219,7 @@ func (api *API) checkAuthorization(rw http.ResponseWriter, r *http.Request) {
obj = dbObj.RBACObject()
}

err := api.Authorizer.ByRoleName(ctx, auth.ID.String(), auth.Roles, auth.Scope.ToRBAC(), auth.Groups, rbac.Action(v.Action), obj)
err := api.Authorizer.Authorize(ctx, auth.Actor, rbac.Action(v.Action), obj)
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 so much nicer and more readable ❤️


// SafeScopeName prevent nil pointer dereference.
func (s Subject) SafeScopeName() string {
if s.Scope == nil {
Copy link
Member

Choose a reason for hiding this comment

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

Looking at RegoAuthorizer.Authorize, wouldn't this be a developer error?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

It would be a developer error.

Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

👍

@EmyrkEmyrk merged commitb0a1615 intomainJan 26, 2023
@EmyrkEmyrk deleted the stevenmasley/standard_rbac_subject branchJanuary 26, 2023 20:42
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJan 26, 2023
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

@kylecarbskylecarbsAwaiting requested review from kylecarbs

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Emyrk@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp