Skip to content

feat(api): self-service API keys — admin minting with a role ceiling, list, show-once UI (#866) - #1216

Merged
athvin merged 8 commits into
mainfrom
issue/866-self-service-api-keys
Nov 25, 2026
Merged

athvin merged 8 commits into
mainfrom
issue/866-self-service-api-keys

Conversation

@athvin

@athvin athvin commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Closes #866

🚧 Claimed by an agent session — 2026-11-25T07:23:22Z, session Claude Code:d1e3b2dc-3174-4091-9c30-c08fc4820306 on Mac.
The claim is this open draft PR: closing it releases the ticket.

Post-merge is part of this pull request. The ledger below records whether
the follow-up work actually happened. /land-pr closes it.

What

A customer org admin can now mint, list and revoke its own API keys, from a settings page or over the API. Before this, every key came from the operator.

  • er-server:
    • create_key and revoke_key move from operator-only to the org Admin guard.
    • Minting has a role ceiling, and operator is still never mintable (422).
    • New GET /v1/orgs/{org}/api-keys (Admin), served through ApiKeyWire, which has no hash field.
  • BFF and UI:
    • /api/orgs/[org]/api-keys routes, all admin.
    • A settings page using the webhook secret's show-once pattern: mint, plaintext with a copy button and a curl check, list, revoke.
  • Two guards beyond the ticket:
    • The app's own per-org service keys are marked "Used by this app" and can't be revoked. The BFF answers 409.
    • er-mcp doesn't offer the /api-keys routes to agents.

Why

#857 / #1013: "connect your own system" was a support ticket. This is the getting-started step the docs page (#867) publishes.

Proof

  • make check: 1,165 passed, 0 failed.
  • make frontend: 946 passed, 0 failed (lint, format, types, authz, unit with the coverage floor, Playwright functional).
  • pg_auth against Postgres covers every case in the ticket:
    • admin mints in its own org (201, plaintext); another existing org is 404
    • viewer and steward get 403; operator is 422
    • the minted key calls GET /v1/orgs/{org}
    • the list is admin-only, 404 cross-org, and contains no hash or plaintext
    • admin revoke works, and the key then gets 401
    • exactly one key.issue and one key.revoke audit row
  • Mutation check: putting back operator_only on mint fails the test.
  • er-server --tests against Postgres: 396 passed.
  • Frontend:
    • api-keys.test.tsx: 5 component tests.
    • api-keys.spec.ts: 9 Playwright runs across 3 projects (mint, copy, list, revoke, reload; 409 on a service key; 403 below admin).
    • The page is in the axe sweep. Lint, types, the authz gate and unit tests (1,076) are clean.
  • er-mcp: credential_management_is_never_offered.

Risk & rollback

This widens who can mint keys: org admins, not just the operator. It's bounded by the org guard, the role ceiling, the service-key refusal and the agent exclusion. Three config-studio visual baselines change, because the settings nav gains a tab. Rollback: git revert <merge-sha>.

Post-merge ledger

Closed by: agent · session Claude Code:d1e3b2dc-3174-4091-9c30-c08fc4820306 on Mac · 2026-11-25T08:27:55Z

Specific to this change

Context — plan, discoveries, measurements, files

Plan

  • Declare the api_key read by_org statement and generate it.
  • er-server: Admin guard plus ceiling on mint and revoke, a new list_keys, and ApiKeyList on ResponseDoc. The envelope ledger gains wrapped/keys.
  • BFF routes, hooks, the page, a nav tab, and serviceKeyIds(org).
  • Mock key store and keys-{dev,ios,android} orgs; component, functional and axe coverage.
  • er-mcp exclusion.
  • Skills: er-server-control-plane (minting rules), frontend-bff (the service-key guard).

Discoveries

  • The app's own keys are in the list. mintServiceKeys (admin.ts) mints three keys per org that the BFF calls er-server with, so a customer admin would see them and could revoke them, signing the app out of their org. They are matched by org_credentials.key_id, then marked and refused.
  • The regenerated MCP manifest made these admin tools. An agent holding an admin key could mint a durable credential, so they are excluded from offered().
  • The ceiling is unreachable for an admin today. Admin is both the floor to mint and the highest mintable role. It is still stated, so a future lower minting floor cannot mint upward.
  • The visual re-baseline script rewrote 24 baselines with =all. Only the three config-studio shots carry the settings nav. The other 21 were sub-tolerance noise on untouched screens and are not included.

Measurements

Files

Backend: entities/api_key/read/by_org.{sql,yaml}, rust/crates/er-server/src/{lib.rs,openapi.rs}, rust/crates/er-server/tests/pg_auth.rs, rust/crates/er-mcp/{src/manifest.rs,tools.json}. Frontend: src/app/api/orgs/[org]/api-keys/**, src/app/(tenant)/[org]/settings/api-keys/page.tsx, src/components/settings/api-keys-content.tsx, src/lib/query/api-keys.ts, src/lib/bff/credentials.ts, the mock and fixtures, tests.

bmoore813 and others added 7 commits November 24, 2026 23:23
create_key and revoke_key move from operator_only to the org Admin guard,
so a customer admin connects without asking the operator. The operator
still passes every org guard. The minted role is capped at the minter's
own, and operator stays unmintable (422). A new GET /v1/orgs/{org}/api-keys
(Admin) lists the org's keys newest first, revoked included, through
ApiKeyWire, which has no key_hash field. The new api_key read by_org
statement is declared and generated.

pg_auth covers:
- admin mints in its own org (201, plaintext) and gets 404 on another
  existing org
- viewer and steward get 403; operator is 422
- the minted key calls GET /v1/orgs/{org}
- the list is admin-only, 404 cross-org, and never contains a hash or a
  plaintext
- admin revoke, after which the key 401s
- one key.issue and one key.revoke audit row for the key

Co-Authored-By: Claude Opus 5.5 <[email protected]>
#866)

BFF routes under /api/orgs/[org]/api-keys (GET/POST) and
/api-keys/[keyId] (DELETE), all requireOrgAccess(org, "admin"). The list
unwraps er-server's {keys} (ledger: wrapped/keys) and marks the app's
own service keys. The settings page follows the webhook secret's
show-once pattern: the plaintext and a copy button appear only in the
mint response's moment, with a curl line to check it works.

The guard this needed: the BFF calls er-server with three per-org
service keys it minted at registration, and those keys appear in the
org's list. Revoking one would sign the app out of the org for every
member. serviceKeyIds(org) reads org_credentials, so the list marks
them 'Used by this app' and offers no revoke, and the DELETE route
refuses them with a 409 that says why.

Mock: a stateful per-org key store seeded on new keys-{dev,ios,android}
orgs with the fixtures' service keys plus one customer key. Minted
plaintexts are unique and never equal a stored service credential.
Tests: api-keys.test.tsx (show-once, revoke offered only for active
customer keys, non-admin notice, roles offered) and api-keys.spec.ts
(mint, copy, list without plaintext, revoke, reload; 409 on a service
key; 403 for a viewer). The page is registered in the axe sweep.
The developer reference is regenerated (the key routes are public now).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…efs (#866)

er-mcp: the /api-keys routes are admin tools in the regenerated manifest,
and offered() now excludes them. A prompt-injected agent holding an admin
key could otherwise mint a durable credential and leak it beyond the
session it was trusted for. Pinned by
credential_management_is_never_offered.

Skills:
- er-server-control-plane: minting is org Admin with a role ceiling, plus
  the list endpoint and the MCP exclusion.
- frontend-bff: the app's own service keys are guarded at the BFF.
- Regenerated references: the entities index, plus the screens and dense
  surfaces lists for the new page.

The api-keys spec's non-admin case logs in as the steward. The viewer is
not a member of the per-project orgs, so it never reached the page.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ab (#866)

The settings nav gains an eighth tab, which reflows its rows on narrow
viewports (settings-nav.tsx warns of exactly this). Regenerated with
scripts/frontend-dev/update-baselines.sh in the pinned image. Only the
three config-studio shots carry the settings nav. The script's other 21
rewrites were sub-tolerance noise on screens this change does not
touch, and are left out to keep the diff to what moved.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…tement (#866)

catalog_bounds_match_declared_sql_and_distinct_relations pins the
er.statement attribute's cardinality to the number of declared .sql
files. by_org is the 280th.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

The marketing preview was removed because this PR is closed or merged.

The OpenAPI documents were regenerated with the new GET
/v1/orgs/{org}/api-keys, but the TypeScript types were not, so the
frontend gate's regenerate-and-diff step failed.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

This branch was previously deployed

1 inactive deployment
marketing-preview — b6c9a5ed Deployed Nov 25, 2026 by athvin via remove closed PR previews #34
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.

Self-service API keys: org-admin minting with a role ceiling, list endpoint, show-once UI

2 participants