Skip to content

feat: add fine-grained authorization (FGA) support#16

Open
lakhansamani wants to merge 3 commits into
mainfrom
feat/fga-support
Open

feat: add fine-grained authorization (FGA) support#16
lakhansamani wants to merge 3 commits into
mainfrom
feat/fga-support

Conversation

@lakhansamani

Copy link
Copy Markdown
Contributor

Summary

Adds client-facing Fine-Grained Authorization (FGA) support to the Go SDK, mirroring the authorization API shipped on the Authorizer server. FGA was planned but not yet present in the SDK.

The server's FGA model is Keycloak-style (resources / scopes / policies / permissions). This PR wraps the two surfaces relevant to a client SDK; admin _authz_* CRUD is intentionally excluded to keep the SDK's client-only scope (it exposes no admin operations).

Changes

  • RequiredPermissions ([]*PermissionInput, AND semantics) added to SessionQueryRequest, ValidateJWTTokenRequest, and ValidateSessionRequest. If any required permission is denied, the result is unauthorized.
  • GetPermissions(headers) — new method wrapping the permissions query; returns the authenticated principal's granted resource:scope permissions.
  • Permission / PermissionInput types and PermissionFragment added to common.go.
  • Integration tests: TestGetPermissions and TestValidateJWTTokenWithRequiredPermissions (skip-tolerant, matching existing test style).
  • README: new "Fine-grained authorization (FGA)" usage section.

Verification

  • go build ./...
  • go vet ./... (incl. tests) ✅
  • Integration tests compile; they require a running FGA-enabled Authorizer instance to execute.

Add client-facing FGA capabilities mirroring the server's authorization API:

- RequiredPermissions ([]*PermissionInput, AND semantics) on
  SessionQueryRequest, ValidateJWTTokenRequest and ValidateSessionRequest
- GetPermissions(headers) wrapping the permissions query, returning the
  authenticated principal's granted resource:scope permissions
- Permission / PermissionInput types and PermissionFragment
- Integration tests for GetPermissions and required-permissions validation
- README usage section
Expose the three public (non-admin) FGA GraphQL operations of the
Authorizer server, backed by its embedded OpenFGA engine:

- FgaCheck      -> fga_check(params: FgaCheckInput)        { allowed }
- FgaBatchCheck -> fga_batch_check(params: FgaBatchCheckInput) { results { allowed } }
- FgaListObjects-> fga_list_objects(params: FgaListObjectsInput) { objects }

The subject defaults to the authenticated caller and is pinned
server-side from the request headers; the optional User override is
honored only for super-admin callers. Contextual tuples are supported
on single and batch checks. Model/tuple authoring stays in the
dashboard / _fga_* admin API by design and is not part of the SDK.

This supersedes the earlier (unreleased, branch-only) resource:scope
permissions surface: GetPermissions, Permission/PermissionInput and the
RequiredPermissions fields on validate/session requests are removed,
since the server replaced resource:scope permissions with FGA relations
(required_relations).

Tests: rewrite the FGA integration tests against the new API, skip
cleanly when the target server has FGA disabled or no model installed,
and send an Origin header from the test client (the server's CSRF
middleware rejects GraphQL POSTs without Origin/Referer).

Verified against a live server (sqlite, embedded OpenFGA) end to end:
allowed/denied single checks, positional batch results, list_objects
filtering and contextual-tuple evaluation.
Match the server's renamed public FGA GraphQL surface (never released,
so a clean rename): fga_check / fga_batch_check / fga_list_objects are
replaced by check_permissions and list_permissions.

- CheckPermissions evaluates one or more checks per call; each result
  echoes its relation/object pair and is positionally aligned.
- ListPermissions returns the object ids the subject holds a relation on.
- Subject defaults to the caller's token; the optional User override
  ("type:id", bare id -> "user:<id>") is honored only for super-admins
  or when it equals the caller's own token subject.
- Rewrite integration tests and README examples to the new methods.
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.

1 participant