Files
tenant-registry/migrations/0029_capability_requests.up.sql
Sharang ParnerkarandClaude Opus 5.5 fe05192182
ci / shared (pull_request) Successful in 26s
ci / test (pull_request) Successful in 6m7s
ci / image (pull_request) Skipped
feat(authz): individual capabilities per member (RBAC step 3)
A member can hold capabilities on top of their bundle. They live in the
Keycloak user attribute extra_capabilities, which the tenant-context
mapper puts into the token; the registry writes it like org_roles and
clears it when the member leaves.

- POST/DELETE /v1/tenants/{id}/members/{uid}/capabilities[/{cap}]
- a person who holds registry:members.manage grants, never on
  themselves, and only what they hold themselves
- an administration capability waits for a second person: open
  requests in capability_requests (0029), approve or reject under
  /v1/tenants/{id}/capability-requests
- a role change keeps the extras; the principal parses the claim, the
  registry's own checks still go by org_roles

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_014aRnCGqELxoix5TfpX8Ejf
2026-11-11 13:39:36 +01:00

17 lines
1.0 KiB
SQL

-- RBAC step 3: a request to grant an administration capability to one
-- member waits here for a second person (four-eyes). A grant of any other
-- capability is written to Keycloak at once and never lands here. The row
-- is deleted when the request is approved, rejected or withdrawn, or the
-- member leaves; the audit log keeps the history.
CREATE TABLE capability_requests (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
tenant_id UUID NOT NULL REFERENCES tenants(id) ON DELETE CASCADE,
user_id TEXT NOT NULL CHECK (char_length(user_id) BETWEEN 1 AND 200),
user_email TEXT NOT NULL DEFAULT '' CHECK (char_length(user_email) <= 320),
capability TEXT NOT NULL CHECK (capability ~ '^[a-z]+:[a-z0-9-]+\.[a-z0-9-]+$'),
requested_by TEXT NOT NULL CHECK (char_length(requested_by) BETWEEN 1 AND 200),
requested_email TEXT NOT NULL DEFAULT '' CHECK (char_length(requested_email) <= 320),
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
UNIQUE (tenant_id, user_id, capability)
);