Repository navigation
feat: gateway keys as a resource, with a default and an owner (v0.9.0) - #48
Merged
Merged
Conversation
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>
|
Thanks for the PR. One thing before review: this targets
No need to close and reopen: click Edit next to the PR title and change the base branch to See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
default_keynames it (the waydefault_routenames a route); it cannot be deleted or disabled, and adoption falls back to it. Before, there was only a key that happened to be calleddefault, and adoption fell back to the first key in the list.codexis no longer mistaken for Codex's.POST /keys/{name}/rotategenerates 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.default_keyin the same version.Also
CostDim::Client), and each key reportslast_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/newis gone — creating a key is now one call that generates and saves.GET /overview'sclientsandGET /keysare 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.rsgains 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