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

Return the group name when listing a user's groups. #1422

Merged
merged 3 commits into from
Nov 11, 2024

Conversation

kian99
Copy link
Contributor

@kian99 kian99 commented Nov 6, 2024

Description

This PR fixes the response from the rebac admin's "GetIdentityGroups" endpoint. Currently we return a group name in place of the group ID. One issue we face is that the group name may no longer exist in the DB but an OpenFGA may still exist. To handle this case I considered:

  • Returning an error
  • Dropping the offending result
  • Returning the group with a name of "removed"

I've opted for option 3. The first would prevent the user from viewing their groups and the second would hide the issue.
Changed to option 2 to drop the result since it is not useful to the user.

Fixes #1418.

Engineering checklist

Check only items that apply

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

@kian99 kian99 requested a review from a team as a code owner November 6, 2024 07:39
@kian99 kian99 force-pushed the fix-identity-groups-response branch from bed2563 to 27253b5 Compare November 6, 2024 10:47
internal/jimmhttp/rebac_admin/identities.go Show resolved Hide resolved
if err != nil {
// Handle the case where the group was removed from the DB but a lingering OpenFGA tuple still exists.
// Don't return an error as that would prevent a user from viewing their groups, instead show the group as "removed".
dbGroup.Name = "(removed)"
Copy link
Contributor

Choose a reason for hiding this comment

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

thinking out loud...
if the group is missing from the db it won't be listed in the /groups | group/{id} endpoint, so showing the id in this endpoint doesn't make sense, because it can't be resolved if the user clicks on it.

So I would remove these entries missing from postgres, so the user doesn't see "dangling" uuid.
Just a continue without returning any error is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, dropping the result does seem like the better thing to do. I'll wait for another review to chime in and if we agree, I'll change it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it.

internal/jimmhttp/rebac_admin/identities.go Show resolved Hide resolved
dbGroup, err := s.jimm.GetGroupByUUID(ctx, user, t.Target.ID)
if err != nil {
// Handle the case where the group was removed from the DB but a lingering OpenFGA tuple still exists.
// Don't return an error as that would prevent a user from viewing their groups, instead show the group as "removed".
Copy link
Contributor

Choose a reason for hiding this comment

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

How is the group shown as "removed"? We just call .First

Copy link
Collaborator

Choose a reason for hiding this comment

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

i think cleanup could possibly be a topic in its own right. we leave a lot of tuples in openfga that refer to a deleted entity in jimm. i think a spec on this would be very welcome, if anybody has time.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comment was outdated, we just drop the group from the result.

if err != nil {
// Handle the case where the group was removed from the DB but a lingering OpenFGA tuple still exists.
// Don't return an error as that would prevent a user from viewing their groups, instead show the group as "removed".
if errors.ErrorCode(err) == errors.CodeNotFound {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be leaving lingering tuples? Or would .GetGroupsByUUIDs be better in the JIMM layer with tuple cleanup? (Really not sure here just opening up for discussion)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We shouldn't be leaving lingering tuples, but that's a separate issue. This is just handling the case that, for some reason, there is a leftover tuple but no group in the database.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure what you mean here but perhaps explain in tomorrows standup or offline in element?

Copy link
Contributor

@ale8k ale8k left a comment

Choose a reason for hiding this comment

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

Requesting changes on test name and some comments need answering before I'm comfortable to approve.

alesstimec
alesstimec previously approved these changes Nov 8, 2024
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 comments addressed

internal/jimmhttp/rebac_admin/identities.go Show resolved Hide resolved
dbGroup, err := s.jimm.GetGroupByUUID(ctx, user, t.Target.ID)
if err != nil {
// Handle the case where the group was removed from the DB but a lingering OpenFGA tuple still exists.
// Don't return an error as that would prevent a user from viewing their groups, instead show the group as "removed".
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think cleanup could possibly be a topic in its own right. we leave a lot of tuples in openfga that refer to a deleted entity in jimm. i think a spec on this would be very welcome, if anybody has time.

c.Assert(err, gc.IsNil)
c.Assert(groups.Data, gc.HasLen, 2)

groupToDelete := dbmodel.GroupEntry{Name: "group2"}
Copy link
Collaborator

Choose a reason for hiding this comment

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

i don't think you need to get group2 again.. you have its tag on L126 (which contains the id).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought so too, but the delete method requires the ID or UUID.

dbGroup, err := s.jimm.GetGroupByUUID(ctx, user, t.Target.ID)
if err != nil {
// Handle the case where the group was removed from the DB but a lingering OpenFGA tuple still exists.
// Don't return an error as that would prevent a user from viewing their groups, instead drop the group from the result.
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to handle the lingering tuples... Should have a discussion on this

@kian99 kian99 added this pull request to the merge queue Nov 11, 2024
Copy link
Contributor

@ale8k ale8k left a comment

Choose a reason for hiding this comment

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

lgtm bar our lingering naughty tuple issues

Merged via the queue into canonical:v3 with commit 064976f Nov 11, 2024
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.

ReBAC: User's group names are ids
4 participants