Skip to content

feat: gateway keys as a resource, with a default and an owner (v0.9.0) - #48

Merged
fylorn merged 1 commit into
mainfrom
feat/keys-api
Sep 19, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/keys-api

Conversation

@fylorn

@fylorn fylorn commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Groundwork for the desktop's keys page redesign. Keys were the one part of the config only the generic patch endpoint could reach, so the desktop assembled YAML by hand and decided for itself what was safe to delete.

What core now enforces

  • A default key. default_key names it (the way default_route names a route); it cannot be deleted or disabled, and adoption falls back to it. Before, there was only a key that happened to be called default, and adoption fell back to the first key in the list.
  • A key knows whose it is. Adoption records the client on the key instead of matching names. Cancelling adoption keeps the key and the binding, so adopting again reuses it; a rename no longer breaks the link, and a user-made key named codex is no longer mistaken for Codex's.
  • Rotation syncs. POST /keys/{name}/rotate generates the value, writes our config, rewrites the adopted client's config, and reports whether that client needs restarting. Two calls with a failure in between would leave the interface saying "done" while that client gets 401s.
  • Deleting is refused while the client is adopted or a rule still matches the key's name; renaming carries the rules and default_key in the same version.
  • Disabled keys are turned away by name at the gateway, and say they were disabled on purpose — until now "pause this client" meant an empty model list, which reads as a misconfiguration.

Also

  • Usage can be grouped by key (CostDim::Client), and each key reports last_seen_ms. Both answer "is this one still in use"; the existing last-seen is by the client's self-reported hint, which anyone can write.
  • GET /keys/new is gone — creating a key is now one call that generates and saves.
  • GET /overview's clients and GET /keys are the same view, so the two cannot disagree.

Tests

New tests/keys.rs (11) covers masking, the default, rename-carries-references, the two refusals, rotation, and stale base versions. tests/adopt.rs gains four: adoption makes a key of its own and records the owner, cancelling keeps it, adopting again reuses it, rotation writes the new value into the client's config, and the key cannot be deleted while adopted. A gateway test covers the disabled key.

fmt, clippy -D warnings, cargo test --workspace, ./scripts/smoke.sh (51 passed) all pass locally.

🤖 Generated with Claude Code

Keys were the one part of the config only a generic patch could reach. The
desktop assembled two lines of YAML by hand and decided for itself what was
safe to delete — so rules that only core could enforce lived in the
interface, or nowhere at all.

`/keys` now has the shape the other resources have: create, update, delete,
and a rotate that does the whole job. What core enforces:

- **A default key exists and cannot be deleted or disabled.** `default_key`
  names it, the way `default_route` names a route. Until now there was only
  a key that happened to be called `default`, and adoption fell back to the
  *first* key in the list, which is not the same thing.
- **A key knows which client it was made for.** Adoption writes that down
  instead of matching on names: a rename used to break the link silently,
  and a key the user happened to name `codex` looked like Codex's own.
  Cancelling adoption keeps both the key and the binding, so adopting again
  reuses it rather than asking the user to configure a new one.
- **Rotation syncs.** Changing the value of a key an adopted client uses is
  two writes that must both land — ours and theirs. Split across two calls,
  a failure in between leaves the interface saying "done" while that client
  gets 401s.
- **Deleting is refused** while the client is adopted, or while a rule still
  matches on the key's name; renaming carries the rules and `default_key`.
- **A disabled key is turned away by name.** Until now "pause this client"
  meant giving it an empty model list, which reads as a misconfiguration.

Usage can be grouped by key, and each key reports when it was last used.
Both answer "is this one still in use" — the existing last-seen is by the
client's self-reported hint, which anyone can write; the key cannot be
faked.

`GET /keys/new`, which generated a value for the interface to write back,
is gone: creating a key is now one call that generates and saves.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thanks for the PR. One thing before review: this targets main, and it should target dev.

main is a release-only line — branch-protected, linear history, and every commit on it is a tagged release snapshot. Routine work lands on dev and reaches main with the next release. GitHub pre-filled main here because it is the default branch, so this is our defaults being unhelpful rather than anything you did wrong.

No need to close and reopen: click Edit next to the PR title and change the base branch to dev. The commits and the discussion carry over.

See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract.

@fylorn
fylorn merged commit 1a05e15 into main Sep 19, 2026
2 checks passed
@fylorn
fylorn deleted the feat/keys-api branch September 19, 2026 12:11
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