-
Notifications
You must be signed in to change notification settings - Fork 8
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
Allow non-admins to use the checkRelation #1111
Conversation
…r own permissions
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.
LGTM with a comment
internal/jujuapi/access_control.go
Outdated
parsedTuple, err := r.parseTuple(ctx, req.Tuple) | ||
if err != nil { | ||
return checkResp, errors.E(op, errors.CodeFailedToParseTupleKey, err) | ||
} | ||
|
||
userCheckingSelf := parsedTuple.Object.Kind == openfga.UserType && parsedTuple.Object.ID == r.user.Username | ||
|
||
if !r.user.JimmAdmin && !userCheckingSelf { |
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.
a more readable form is
if !(r.user.JimmAdmin || userCheckingSelf)
(according to boolean logic, at least) :)
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.
Definitely and I would've preferred that but then I don't think I can return early with that logic. Unless I'm mistaken
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.
it is literally an equivalent statement
!a && !b <=> !(a || b)
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.
Oh I completely missed the !
in the front of your statement. I read if r.user.JimmAdmin || userCheckingSelf
woops! Will change.
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.
no no.. you didn't misread.. i had a typo :)
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.
Sneaky xD
parsedTuple, err := r.parseTuple(ctx, req.Tuple) | ||
if err != nil { | ||
return checkResp, errors.E(op, errors.CodeFailedToParseTupleKey, err) | ||
} | ||
|
||
userCheckingSelf := parsedTuple.Object.Kind == openfga.UserType && parsedTuple.Object.ID == r.user.Username | ||
|
||
if !(r.user.JimmAdmin || userCheckingSelf) { |
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.
perhaps a comment that:
- admins are allowed to check any relations
- users are only allowed to check relations of themselves to any resource
Description
Allow non-admins to use the checkRelation function when checking their own permissions.
This change was prompted by the fact that the Juju-dashboard is checking the user's permission to read audit logs to determine whether to display the "Audit Logs" tab in the dashboard.
Beyond the dashboard however, it seems like a reasonable change to allow users to call this facade to check their own permissions.
Engineering checklist