Skip to content

feat: enforce token scopes in the api (rbac)#428

Merged
kacy merged 2 commits into
mainfrom
feat/rbac-enforcement
May 24, 2026
Merged

feat: enforce token scopes in the api (rbac)#428
kacy merged 2 commits into
mainfrom
feat/rbac-enforcement

Conversation

@kacy
Copy link
Copy Markdown
Owner

@kacy kacy commented May 24, 2026

enforces the scoped tokens from #427: every operator API route now requires a
token whose scopes permit the request. finishes the rbac + token lifecycle item.

summary

  • src/api/auth.zig:
    • requiredScope(method, path) maps a request to its scope (GET/HEAD → :read,
      writes → :write; /cluster/* writes → cluster:admin; /apps/dry-run
      apps:read; public routes → none; unknown routes fail closed → *).
    • authorize(...) resolves the bearer: the existing single api_token is
      treated as full admin (backward compatible), otherwise a named token is
      looked up by sha256(secret) and its scopes/expiry/revocation apply.
  • dispatch enforces it: 401 when no valid token, 403 when the token lacks the
    required scope. cluster join routes keep using the join token. with no token
    configured the server stays open (unchanged dev behavior).
  • the audit actor is now the token's name (named tokens) or api-token (legacy),
    so /v1/audit attributes actions to a real identity.

tested

  • YOQ_SKIP_SLOW_TESTS=1 zig build test — 2183 passed, 2 skipped, 0 failed
    (existing dispatch auth tests still pass: legacy admin token = full access).
  • unit tests: requiredScope for representative paths, authorize with the
    legacy admin token and with a missing/wrong token, scope matching, and the
    audit name override.
  • end to end against yoq serve: a status:read token gets 200 on /v1/status
    and 403 on secrets (read and write); the admin token gets 200; no token gets
    401; denied requests write no audit entry; /v1/audit shows the actor.
  • zig fmt --check clean.

kacy added 2 commits May 24, 2026 16:20
src/api/auth.zig resolves a bearer token to its scopes (legacy admin
token = full admin, or a named token by sha256 lookup) and maps a
request to its required scope from path-prefix + method. add a 403
forbidden status + helper, and an audit setActorName so a named token
shows up as the audit actor.
operator routes now require a valid token (legacy admin or named) and
the scope for the request; insufficient scope returns 403. cluster join
routes still use the join token. the audit actor is set to the token's
name. with no token configured the server stays open (unchanged).
@kacy kacy merged commit a67eab0 into main May 24, 2026
2 checks passed
@kacy kacy deleted the feat/rbac-enforcement branch May 24, 2026 16:20
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