Repository navigation
fix(fga): raise engine list caps so list_permissions reports truncation - #903
Merged
Merged
Conversation
The embedded OpenFGA server was built without WithListObjectsMaxResults / WithListUsersMaxResults, so OpenFGA v1.22.1's defaults (1000) applied per call. That equals service.maxFgaListResults, so a single (type, relation) pair with more than 1000 matches came back as exactly 1000 and the service never saw a 1001st result: list_permissions returned truncated=false while silently dropping results. Set both engine caps to maxListResults = 1001 (service cap + 1) so the service-side cap is the one that bites and truncated is reported. Regression tests: engine-level ListObjects/ListUsers above the cap, and an integration test asserting list_permissions returns 1000 with truncated=true for 1050 grants (fails without the fix).
For a delegated caller, list_permissions enumerates each subject (agent and user) separately and intersects the results. Each per-subject slice is capped by the engine before the intersection, and OpenFGA returns objects unordered, so two capped slices of large sets overlap far less than the true intersection. The folded result could fall under the service cap and be reported as truncated=false while most reachable objects were dropped. Mark the response truncated when any raw per-subject slice exceeds maxFgaListResults (i.e. the engine hit its maxFgaListResults+1 cap), before intersecting. Aggregation still stops at the service cap. Regression test: user grants on 3000 documents, agent on 3000 with a 2000-document overlap; truncated must be true (failed 3/3 before).
Merged
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.
Problem
The embedded OpenFGA server is built without
WithListObjectsMaxResults/WithListUsersMaxResults, so OpenFGA v1.22.1'sDefaultListObjectsMaxResults/DefaultListUsersMaxResults(both 1000) apply per call. That equalsservice.maxFgaListResults(1000).A single
(type, relation)pair with, say, 5,000 matches came back from the engine as exactly 1000.ListPermissionsappended all 1000, never saw a 1001st, and returnedtruncated: false, so results were dropped with no signal to the caller.Fix
internal/authorization/engine/openfga/openfga.go: configure the server withWithListObjectsMaxResults(maxListResults)andWithListUsersMaxResults(maxListResults), wheremaxListResults = 1001(service cap + 1). The service-side cap is now the one that applies, sotruncatedis set correctly. Kept as a literal likemaxBatchCheckSize, so the engine doesn't importservice; a comment documents the coupling.Delegated callers (second commit)
For an RFC 8693 delegated caller,
ListPermissionsenumerates the agent and the user separately and intersects the results. Each per-subject slice is capped by the engine before the intersection, and OpenFGA returns objects unordered, so two capped slices of large sets overlap far less than the true intersection. The folded result could fall under the cap and be reported astruncated: falsewhile most reachable objects were dropped. This was already the case before this PR.internal/service/list_permissions.go: mark the response truncated when any raw per-subject slice exceedsmaxFgaListResults(meaning the engine hit itsmaxFgaListResults + 1cap), before intersecting. Aggregation still stops at the service cap.Tests
TestOpenFGAEngine_ListAboveServiceCap: 1,050 grants;ListObjectsandListUsersmust each return 1001 (both returned 1000 before).TestFGAListPermissionsTruncated: end-to-endlist_permissionswith 1,050 grants on one pair → 1000 permissions,truncated: true. Verified failing without the fix.TestAgentIntersectionListPermissionsTruncated: delegated token; user grants ondocument:0..2999, agent ondocument:1000..3999(true intersection 2000).truncatedmust be true. Failed 3/3 runs before the second commit.go build ./...,go vet ./...,make test,make lint-gopass locally.Not covered (follow-ups)
No pagination upstream: OpenFGA v1.22.1 (latest) has no continuation token on ListObjects/ListUsers, and maintainers have said paging is not planned (openfga#2828). A truncated response is an arbitrary 1000 objects, not the first 1000.
Deadline truncation:
DefaultListObjectsDeadline(3s) returns partial results with no error, sotruncatedcan still be a false negative on slow queries._fga_list_users: its 1000 cap now actually applies, but the response has notruncatedfield, so callers can't detect truncation (needs a GraphQL + proto schema change).