Skip to content
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

Merged
merged 5 commits into from
Dec 6, 2023

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Dec 5, 2023

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

  • Documentation updated
  • Covered by unit tests
  • Covered by integration tests

Copy link
Collaborator

@alesstimec alesstimec left a 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

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 {
Copy link
Collaborator

@alesstimec alesstimec Dec 5, 2023

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) :)

Copy link
Contributor Author

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

Copy link
Collaborator

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)

Copy link
Contributor Author

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.

Copy link
Collaborator

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 :)

Copy link
Contributor Author

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) {
Copy link
Collaborator

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

@kian99 kian99 merged commit fcf1880 into canonical:v3 Dec 6, 2023
4 checks passed
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.

3 participants