Skip to content

feat: org-scoped admin API keys + cloud credential federation - #15

Merged
fcraviolatti merged 2 commits into
mainfrom
feat/org-scoped-keys-cloud-federation
Jul 16, 2026
Merged

feat: org-scoped admin API keys + cloud credential federation#15
fcraviolatti merged 2 commits into
mainfrom
feat/org-scoped-keys-cloud-federation

Conversation

@fcraviolatti

Copy link
Copy Markdown
Contributor

Summary

Two backend features, ported from internal development.

1. Org-scoped admin API keys (migration 000177)

admin_api_keys gains optional org_id + permissions. NULL org_id keeps existing keys superadmin-wide (cross-org, legacy); a non-NULL value scopes the key to a single organization — the prerequisite for the Clavex Kubernetes Operator's per-CR authSecretRef model, where the controller must never hold cross-org credentials. VerifyKey returns org/permissions; the admin API-key auth callback maps them to IsSuperAdmin + org-scoped claims. New ?org_id= filter on list.

2. Cloud credential federation for Terraform (migration 000178)

organizations.agent_token_allowed_audiences (per-org allowlist) + agent_tokens.audience (persisted for audit). Agent-token issuance accepts an optional audience, validated against the org allowlist (invalid_target on rejection), defaulting to the issuer when omitted. New GET/PUT /api/v1/organizations/:id/agent-token-audiences (superadmin + org-admin-delegate). Clavex only issues a short-lived, signed, correctly-audienced OIDC id_token; the aws/azurerm/google Terraform provider performs its own native federation. Docs: docs/cloud-federation.md.

Test plan

  • go build ./... clean
  • go vet ./... clean
  • go test ./internal/handler/ ./internal/repository/ → 279 pass

Two backend features:

1. Org-scoped admin API keys (migration 000177): admin_api_keys gains
   optional org_id + permissions. NULL org_id keeps legacy superadmin
   (cross-org) keys; a non-NULL value scopes the key to one org, the
   prerequisite for the Kubernetes Operator's per-CR authSecretRef.
   VerifyKey now returns org/permissions; the admin API-key auth path
   maps them to IsSuperAdmin + org-scoped claims.

2. Cloud credential federation for Terraform (migration 000178):
   organizations.agent_token_allowed_audiences + agent_tokens.audience.
   Agent-token issuance accepts an optional audience validated against
   the per-org allowlist (invalid_target on rejection), plus GET/PUT
   /organizations/:id/agent-token-audiences endpoints. Clavex only
   issues a short-lived, correctly-audienced OIDC id_token; the target
   cloud's own Terraform provider performs the native federation.

Docs: docs/cloud-federation.md.
Add the 4 GET/PUT /agent-token-audiences routes (superadmin + org-admin)
to the OpenAPI spec, with the allowed_audiences request schema on PUT.
@fcraviolatti
fcraviolatti merged commit 35fd010 into main Jul 16, 2026
13 checks passed
@fcraviolatti
fcraviolatti deleted the feat/org-scoped-keys-cloud-federation branch July 16, 2026 20:24
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