Fix group issue - #641
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes admin REST API permission mutations so userset subjects preserve ref_relation when adding/removing permissions, preventing OpenFGA model rejections for valid subjects such as tenant#member and org#viewer.
Changes:
- Preserves
EntityRelation.RefRelationin all tenant, group, and feed version permission add/remove handlers. - Adds HTTP-level regression tests covering userset permission additions, invalid userset rejection, unauthorized mutation, and add/remove round-trip behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
server/auth/adminapi/server.go |
Carries ref_relation into permission subject EntityKeys for all permission mutation routes. |
server/auth/azchecker/server_test.go |
Adds regression coverage for add/remove permission API behavior with userset subjects. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The admin REST API returned
500 Internal Server Errorwhen adding an org or tenant as a member of another object (for example, a tenant's members as a group's viewers). The permission handlers dropped the request body'sref_relationwhen building the subject, so userset subjects were written as bare objects the authorization model does not allow.Root cause
All six permission handlers built the subject as
authz.NewEntityKey(er.Type, er.Id), discardinger.RefRelation. The FGA model only permits userset subjects for these relations — anorgviewer/editor accepts[user, tenant#member], and afeed_versioneditor/viewer accepts[user, org#viewer, tenant#member]— never a baretenant:1ororg:39. OpenFGA rejected the write:User subjects have no ref relation, so they were unaffected.
Fix
Carry the ref relation into the subject in all six handlers (POST and DELETE for tenants, groups, and feed versions):
authz.NewEntityKey(er.Type, er.Id).WithRefRel(er.RefRelation).WithRefRel(0)is a no-op for user subjects, so they are unchanged; org/tenant subjects are now written asorg:39#viewer/tenant:1#member, which the model accepts. This is the server-side counterpart to the frontend, which already sendsref_relation.Tests
Added
AddPermissionandRemovePermissionsubtests toTestServerinserver/auth/azchecker. They drive the real admin HTTP API through the realCheckeragainst the canned test database and an in-process in-memory OpenFGA server, so the production model validates the tuple each handler builds. Covered:tenant#memberadded as a group viewer (the reported case)org#vieweradded as a feed version editororgas a group viewer is rejected (the model disallows anorg#...subject for an org relation)Reverting the fix turns the two userset cases into
500s, confirming the test guards the regression.Test plan
go test ./server/auth/azchecker/ -run TestServer(requires the canned test DB and FGA, as provisioned in CI bytestdata/test_setup.sh)