Skip to content

feat(server): accept the app's client keys next to the server key - #98

Merged
Vect0rM merged 2 commits into
mainfrom
change/client-keys
Nov 12, 2026
Merged

Vect0rM merged 2 commits into
mainfrom
change/client-keys

Conversation

@Vect0rM

@Vect0rM Vect0rM commented Nov 12, 2026

Copy link
Copy Markdown
Member

Summary

Account remote access in the desktop app (AtomicBot-ai/Atomic-Chat#410) gives every paired device its own key for the public /v1 API. The app's Rust owns pairing, crypto and key minting. The core only needs to accept those keys on the listener it owns.

The existing host keyring (AtomicCoreOptions.publicApiKeys) does not fit here. Only an embedder can set it, not the app daemon. It also replaces the server's api_key and would close a keyless server. This PR adds a thin, replaceable, in-memory list of extra keys instead.

Control route

PUT /atomic/v1/server/client-keys

  • Body: {"keys": string[]}. It replaces the whole list.
  • Answer: 200 {"count": n}. A key is never echoed, and there is no GET.
  • Validation: keys must be an array of at most 200 strings, each 20–256 characters of [A-Za-z0-9._~-]. Anything else gets 400 INVALID_ARGUMENT, and the stored list stays as it was.
  • The list lives in memory. It survives public-listener restarts but not core restarts, so the app sends it again on every change and every reattach.
  • Client: CoreClient.setServerClientKeys(keys).

Gate behaviour (src/server/public/index.ts, acceptedKeys)

The list is read on every request:

  • If the host keyring (publicApiKeys) answers a list, it wins and the extra keys are ignored. No change from today.
  • If the listener has a non-empty api_key, it accepts [api_key, ...clientKeys]. A removed key gets 401 on its next request.
  • If the listener has no key, it stays open. Extra keys never close it.
  • requires_api_key, serverHasApiKey / endpoint().hasApiKey and publicOptionsCompatible still depend only on the server's own key.

Keys never appear in a response, the snapshot, GET /server, LocalApiServerState, the state files, logs or telemetry.

Docs

  • ADR docs/decisions/2026-11-12-accept-app-client-keys-next-to-the-server-key.md, plus its line in the index.
  • A new row in docs/contracts.md.

Tests

  • src/server/control/routes/public-server.test.ts:
    • replacing the list, and the {count} answer
    • the bounds: 200 keys, 20 and 256 characters
    • 400 for a non-array, an array over 200, keys that are too short or too long, bad characters and non-strings; the list is kept and no key is echoed
    • no read-back
  • src/server/public/index.test.ts:
    • the server key and every extra key pass, by bearer or x-api-key
    • an unknown key gets 401
    • a removed key gets 401 on the next request
    • a keyless server stays open
    • the host keyring wins and the extra keys are ignored
  • src/core/public-server-client-keys.test.ts (real core, through the control API):
    • the same gate checks
    • the list survives a listener restart
    • a keyless server stays open, with requires_api_key and serverHasApiKey false
    • publicApiKeys wins
    • no key appears in the snapshot, the server state, the remote-access status or any file under the data folder
  • src/client/control-client.test.ts: setServerClientKeys.

Gates run locally on macOS arm64: lint, typecheck, format:check on the changed files, test:coverage (floors passed) and build:bin.

🤖 Generated with Claude Code

Vect0rM and others added 2 commits November 12, 2026 12:24
Add PUT /atomic/v1/server/client-keys {"keys": string[]}: it replaces an
in-memory list of extra keys (at most 200, each 20-256 characters of
[A-Za-z0-9._~-], else 400 INVALID_ARGUMENT) and answers {"count": n}.
The public listener reads the list per request and accepts
[api_key, ...clientKeys] only while it has its own non-empty api_key and
the host keeps no keyring; a keyless listener stays open and an embedder
keyring still wins. requires_api_key, serverHasApiKey and the start
comparison keep reading the server's own key. Keys never appear in a
response, snapshot, server state, file, log or telemetry.

Used by account remote access in the app: one key per paired device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts:
#	docs/decisions/INDEX.md
@Vect0rM
Vect0rM merged commit ffbd556 into main Nov 12, 2026
13 checks passed
Vect0rM added a commit to AtomicBot-ai/Atomic-Chat that referenced this pull request Nov 12, 2026
Core v0.23.0 adds `PUT /atomic/v1/server/client-keys`
(AtomicBot-ai/atomic-chat-core#98): the public listener accepts the keys a
sharing computer hands its paired devices, next to its own API key. Without
it, remote access through the account answers those devices with 401.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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