API reference
Raw Management API (/api/v1) — auth, scopes, and endpoints behind the SDK.
All routes take Authorization: Bearer <key> (kr_sk_live_… / kr_pk_live_… / legacy kr_live_…). Key metadata (workspace, type, scopes, expiry) is resolved per request; bad/revoked/expired → 401. Missing scope → 403.
Built-in scopes: check, grants.write, roles.read, roles.write, spaces.read, spaces.write, actions.read, actions.write, subject_tokens.write, telemetry.read, telemetry.write, webhooks.read, webhooks.write. Publishable keys are capped to check.
Spaces
The second isolation layer: platform scope (no space) plus fully isolated spaces — each space has its own actions, roles and grants. A subject can hold invoices.refund in space acme and nothing in globex. Every endpoint below takes an optional space (query ?space= on GETs, body space on POST/DELETEs); omitted = platform scope. Unknown slug → 404 unknown_space. Checks evaluate exactly the scope passed — no cross-scope inheritance.
GET /api/v1/spaces · POST /api/v1/spaces · DELETE /api/v1/spaces
Secret. List needs spaces.read, create/delete need spaces.write. Create is idempotent ({ slug, name, description? }); delete takes { space } and cascades to the space's roles, actions, links and grants. SDK: keyring.listSpaces(), keyring.createSpace({ slug, name }), keyring.deleteSpace(space).
GET /api/v1/check
GET /api/v1/check?subject=user_123&permission=invoices.refund&space=acme&context=%7B%22plan%22%3A%22pro%22%7D
Authorization: Bearer kr_sk_live_…- Secret key:
?subject=+?permission=(+ optional?context=URL-encoded JSON object,?space=slug). - Publishable key:
?permission=only, plusX-Keyring-Subject-Token: <jwt>; any?subject=is ignored and the subject comes from the verified JWT.?context=and?space=still ride along. - CORS:
Access-Control-Allow-Origin: *, allowed headersAuthorization, Content-Type, X-Keyring-Subject-Token. - Response:
{ "subject": "user_123", "permission": "invoices.refund", "space": "acme", "allowed": true }(space: nullfor the platform scope).
POST /api/v1/grants · DELETE /api/v1/grants
Secret, scope grants.write. Grant a role (supports display_name, expires_at / ttl_seconds, ABAC condition, space); revoke with { role, subject, space? }. SDK: keyring.grantRole({ role, subject, space }), keyring.revokeRole({ role, subject, space }).
POST /api/v1/subjects
Secret, scope grants.write. Upsert subject attributes (merged) — feeds ABAC grant conditions. Body: { subject, attrs, display_name? }.
POST /api/v1/subject-tokens
Secret, scope subject_tokens.write. Mint a browser JWT. Body: { subject, ttl_seconds? } → { token, subject, expires_at }.
GET /api/v1/roles · GET /api/v1/permissions
Secret. roles.read → { roles: [{ slug, name, description, space, created_at }] }; actions.read → { permissions: [...] } (SDK alias listActions()). Both accept ?space= (omitted = platform scope); SDK: keyring.listRoles(space?), keyring.listPermissions(space?).
POST /api/v1/roles · POST /api/v1/permissions
Secret. Create (or update) a role or action in the key's workspace + scope — no dashboard step needed. Both are idempotent: re-POSTing the same slug updates name / description (and adds permission links) instead of failing. Pass space to create inside a space; permissions attached to a role must live in the same scope.
POST /api/v1/permissions
Authorization: Bearer kr_sk_live_…
Content-Type: application/json
{ "slug": "games.play", "name": "Play games", "category": "Games" }- Scope
actions.write. Role slugs are lowercase with dashes (player); action slugs areresource.action(games.play). Bad slug →400. - Response
201:{ "slug": "games.play", "name": "Play games", "description": null, "category": "Games", "created_at": "…" }.
POST /api/v1/roles
Authorization: Bearer kr_sk_live_…
Content-Type: application/json
{ "slug": "player", "name": "Player", "permissions": ["games.play", "games.create"] }- Scope
roles.write.permissionsmust already exist in the same scope — create actions first (with the samespace). Unknown action slug →404(Unknown permission: …) with no partial write. - Permission links are additive: re-POSTing never removes existing mappings.
- SDK:
keyring.createPermission({ slug, name, space }),keyring.createRole({ slug, name, permissions, space })(aliascreateAction()).
POST /api/v1/events
Secret, scope telemetry.write. Manual telemetry event paired with auto-logged checks. Body: { subject, permission, allowed?, context?, space? } → { ok: true, id }.
GET /api/v1/subjects/access
Secret, scope check. Full access snapshot for one subject in one scope — backfill + nightly reconcile for customer mirrors (templates/customer-mirror/schema.sql). Expired grants excluded (mirror filters them too; rows stay).
GET /api/v1/subjects/access?subject=user_123&space=acme
Authorization: Bearer kr_sk_live_…Response: { "subject": "user_123", "space": "acme", "roles": ["teacher"], "permissions": ["records.insert"] }. Unknown subject → empty arrays (not 404). SDK: keyring.getSubjectAccess(subject, space?).
POST /api/v1/subjects/provision
Secret, scope grants.write. Grant the default role of the requested scope (platform default in Settings, or the space's default on the Spaces page) to a subject — auto-provisioned, idempotent. No role slug in the request: the server resolves it, so the caller can never choose or escalate roles.
POST /api/v1/subjects/provision
Authorization: Bearer kr_sk_live_…
Content-Type: application/json
{ "subject": "user_123", "display_name": "carol@example.com", "space": "acme" }Response: { "subject": "user_123", "role": "player", "space": "acme", "granted": true } (granted: false when already held). No default configured → 409 no_default_role (fail-closed). SDK: keyring.provisionSubject({ subject, displayName, space }).
POST /api/v1/integrations/supabase/start · POST /api/v1/integrations/supabase/verify
Secret, scope integrations.write. One-click mirror connect (docs). start returns { session_id, login_url } (Supabase CLI device flow); verify { session_id, project_ref, code } exchanges the code, then orchestrates SQL → PostgREST → function deploys → secrets → endpoint with the short-lived user token, returning { ok, steps: [{ step, ok, detail? }], endpoint_id }. The Supabase token is never persisted. Step failures return 502 with the per-step log — nothing half-applied hides.
GET /api/v1/webhooks · POST /api/v1/webhooks · DELETE /api/v1/webhooks
Outbound mirror feed. Secret key: list needs webhooks.read, create/delete need webhooks.write.
POST /api/v1/webhooks
Authorization: Bearer kr_sk_live_…
Content-Type: application/json
{ "name": "supabase mirror", "url": "https://<project>.supabase.co/functions/v1/keyring-applier", "events": ["grant.*", "subject.deleted"] }Omit secret to have the server mint kr_ws_live_… at creation (same 32-byte base64url body as API keys) — the raw value is returned once in the 201 response and never again. Supply your own (min 16 chars) to bring one.
Events: grant.created/updated/deleted, subject.created/updated/deleted, role.created/updated/deleted, permission.created/updated/deleted, role.permissions_updated. Subscribe exact, prefix (grant.*), *, or omit/[] for all. Deliveries POST { id, event, organization_id, created_at, data } with webhook-id / webhook-timestamp / webhook-signature: v1,<base64 HMAC-SHA256> headers. SDK: keyring.createWebhook() → CreateWebhookResult (includes secret), keyring.listWebhooks(), keyring.deleteWebhook(id). See Supabase RLS and Neon RLS.
Dispatcher setup (Keyring host project)
Triggers only queue rows in webhook_outbox. Delivery is instant + backed by cron:
- Instant (seconds): migration
0039adds anAFTER INSERTtrigger onwebhook_outboxthat kickswebhook-dispatchviapg_netthe moment rows land. Best-effort by design — ifpg_net/config is missing it silently no-ops and can never fail your grant/role writes. Enable it with one row (same key asWEBHOOK_DISPATCH_KEY):
INSERT INTO public.webhook_dispatch_config (id, url, cron_key)
VALUES (1, 'https://<keyring-project-ref>.supabase.co/functions/v1/webhook-dispatch', '<same WEBHOOK_DISPATCH_KEY>')
ON CONFLICT (id) DO UPDATE SET url = EXCLUDED.url, cron_key = EXCLUDED.cron_key, enabled = true;- Fallback (every minute): the same function runs on a cron schedule to catch anything the kick missed (worker down, redeliveries). Deploy it first:
supabase functions deploy webhook-dispatch
supabase secrets set WEBHOOK_DISPATCH_KEY="<random 32+ chars>"Then schedule every minute (needs pg_cron + pg_net enabled — enable pg_net
via Dashboard → Database → Extensions; its functions always live in the net
schema, so the call below is net.http_post regardless of where the extension
row is registered) in the SQL editor:
select cron.schedule(
'webhook-dispatch-every-minute',
'* * * * *',
$$
select net.http_post(
url := 'https://<keyring-project-ref>.supabase.co/functions/v1/webhook-dispatch',
headers := jsonb_build_object('Content-Type', 'application/json', 'X-Cron-Key', '<same WEBHOOK_DISPATCH_KEY>'),
body := '{}'::jsonb
);
$$
);Polar-style: no automatic retries. Each queued delivery is attempted once — a failure marks it failed terminally (with the error in last_error), and it stays there until you hit Redeliver on the endpoint's detail page, which flips it back to pending for the next dispatcher tick. Every attempt records its HTTP http_code + a capped response snippet on the outbox row (migration 0038), backing the per-endpoint Status column and Response block. Delivered rows older than 7 days are pruned automatically.
Troubleshooting the dispatcher: if cron.job_run_details shows schema "net" does not exist, pg_net isn't enabled yet (Dashboard → Database → Extensions → enable pg_net). If it shows function net.http_post(…) does not exist while the extension row exists, the install is hollow — reinstall directly:
drop extension if exists pg_net;
create extension pg_net with schema extensions;
-- verify: functions live in the `net` schema (NOT `extensions`) —
-- must return http_get / http_post / …
select p.proname from pg_proc p
join pg_namespace n on n.oid = p.pronamespace
where n.nspname = 'net' and p.proname like 'http%';Errors
{ "error": "…" } with 400 (bad input, e.g. missing permission/subject, invalid context, bad role/action slug), 401 (bad key / bad subject token), 403 (missing scope), 404 (unknown role / unknown permission / unknown space), 500 (API not configured).