← Back to Pull requests

Opt-in caller tokens and TLS on both hops, so clankerbox runs without a tailnet (0.44) #72

Closed
unknown closed this pull request without merging on Nov 25, 2026 14:14 UTC
View on GitHub
unknown unknown commented on Nov 23, 2026 22:57 UTC
Author

Opt-in caller authentication for 0.44, so clankerbox can run without a tailnet. Each caller of the control plane presents a named bearer token, and the control plane presents its own token to each host; both hops run over TLS. Do not merge or release yet: this is for review.

What it adds

  • Control plane: tokens: true makes it take only a bearer token whose SHA-256 its store (server.db, new tokens table) holds unrevoked, and tls takes {cert, key}. Any other request is refused with Unauthenticated (401) before anything runs. The check reads the table at each request, so mint and revoke take effect from the next request with no restart. It sits after the Origin refusal and before the version check.

  • Managing tokens: listTokens, mintToken and revokeToken actions (clankerbox token list|mint|revoke). Any caller's token may use them (Gjermund's decision: no per-token flag), so every token is full control of the fleet; the README says so, and that after a leak you list and revoke everything you don't recognise. A revoked row stays, so list shows every token, who minted it and when, including what a since-revoked token minted.

  • Host: callers, a file of <name> <sha256 hex> lines read at start, and tls. A host has no store, so its one token stays in config. Each hosts[] entry in the server config can name a token file, which the control plane sends to that host. A host that refuses the token shows as unreachable in hosts, with the message "host X refused the control plane's token".

  • publish.address on a host is where machine SSH ports are published. It defaults to listen.address, so a host's API can stay on a private address while SSH sits on a public one.

  • Clients: Client.make({ token }) in the SDK, token (a file) in the CLI config, token (a file) in the amp-orbs settings, and token (the value) in the Rivet provider. A refused client now gets Invalid with a message saying what to fix, where it used to get Internal "answered unexpectedly".

  • clankerbox-server token add <name> prints a token once. With --config <server config> it writes into the store, opened and locked as the control plane opens it. So it refuses while the control plane runs: that's the bootstrap. With --callers <file> it appends a host's hash line.
  • The conditions

    1. Opt-in is real. With no tokens (or callers on a host), requireToken passes every request and no client sends a header. The CGNAT/loopback restriction is unchanged. Every existing server, host, CLI, SDK and provider test passes without modification: vp run ready reports 16/16.
    2. A public listen address without auth is refused at startup. I enforced this in config validation rather than in the type. listen.address decodes as any IP, and loadConfig on both sides runs listenRefusal, with {tokens, tls} on the control plane and {callers, tls} on a host. A tailnet or loopback address always passes. Any other address needs both, and tokens: false counts as unset; without them the config fails Invalid, naming what's missing and why. listenRefusal is the only path from a decoded address to a served one. I chose not to make the address type depend on auth, because the two come from different fields of the same struct.
    3. Proven off-tailnet (transcript below). The real clankerbox-server binary ran on 203.0.113.10:8585 and a host on 203.0.113.20:8484, both with TLS and tokens, with machine SSH published on 203.0.113.21. These are TEST-NET-3 addresses added to lo. No tailscale binary exists on the machine. The built CLI ran hosts, create, exec (hello from dev), stop, start and get. The control plane recorded dev's endpoint as 203.0.113.21:21000 while the host's API listened on .20, so the API/SSH split works. Tokens ran there too: the first was minted offline with the control plane stopped, and token add was refused while it ran. token mint orbs was served at once, and orbs minted phone; token revoke orbs refused orbs' next call with no restart; and token list still showed orbs, revoked, and phone, minted by orbs.
    4. Every refusal has a test that fails without it. Planted wrong implementations, each caught by a test:
    - prefix comparison, empty-token acceptance, any-64-hex acceptance;
    - passing when there is no Authorization header;
    - routes without requireToken, on either side;
    - the token set cached at startup (the revoke test gets 200 where it wants 401), revoked tokens taken, list hiding revoked tokens or what a revoked token minted, no minter recorded, and everyone passed while no token is minted;
    - listenRefusal requiring only one of the two, accepting either one, treating every address as private, or counting tokens: false as on;
    - the control plane sending no token;
    - a host's 401 read as a plain unanswered call;
    - the SDK sending no token, or reading 401 as unexpected;
    - the CLI dropping its token;
    - four bugs in token add (writing the raw token, overwriting the file, joining onto a line without a trailing newline, allowing a duplicate name).

    Each commit message lists the ones for its piece.
    5. Constant time. timingSafeEqual runs over every caller's hash, even after a match. The function is named callerInConstantTime rather than relying on a comment, because this repo's no-prose-comments rule asks for names. No test asserts the timing: lint forbids vi.mock, and a timing measurement would be flaky.

    Where this differs from what was agreed

  • Control-plane tokens moved from a callers file to the store (0efa388e, 0297aa33), before merge, so no operator ever has a callers file to migrate. A host keeps its file. A per-token manage flag was built and then removed (5c498fc6) on Gjermund's call.
  • I did not use effect-actions' Authentication. Its caller/protect requires a credential on every action of every deployment, so a deployment without tokens would break, which contradicts condition 1. I wrote requireToken as router middleware instead, about 40 lines, answering with effect-actions' own Unauthenticated so clients decode it as a built-in.

  • No pinning config for TLS. Clients and the control plane trust a private CA through Node's NODE_EXTRA_CA_CERTS. The README says so.
  • Second review (3dcd116), fixed in 56e66ae0, acd30fe3, 3fc5ad42

  • Offline clankerbox-server token list and token revoke --config, beside token add, each refusing while the control plane runs. Without them a leaked token could mint more and revoke the operator's, and token add alone left the attacker's tokens live after restart. The README's recovery is now the stopped-server sequence: list, revoke, add under a new name, start. A revoked name stays taken (Conflict) on purpose, so list keeps saying who minted what; the README says to pick e.g. laptop-2.

  • Address rule tested against its own table, replacing the tautological agreement test. It fails against an isTailnetOrLoopback that takes every IPv4-mapped address and one that takes none.

  • Comparison tested at every bit: a hash differing from the caller's in each one of its 256 bits. It fails against skipping byte 16, comparing only bytes 0 and 31, only the last 4 bytes, and bytes 0–30 plus the low bit of 31.

  • The CHECK on tokens.hash has no test, deliberately. The only writer always writes 64 lowercase hex; the constraint guards hand edits of server.db. A bad row would fail closed (every request a 500), not open.

  • Behaviour change: ::1%lo (a zone ID) was taken as loopback by the old BlockList and is now refused by the shared rule, so such a listen address needs tokens and tls. It fails closed.

  • docs/design/control-plane.md now says the tailnet is the only gate only without tokens. A repo-wide search for the claim in other wordings found no other unconditional copy.
  • Third review (3fc5ad4), fixed in 4e971702, 51b6440f, dbd61f56, c03c74dd

  • Comparison pinned to ordered equality (51b6440f). A byte-sum comparison passed the one-bit test, which shows only that every bit counts. Two tests now sit beside it: permutations of the digest (reversed, every rotation, every adjacent swap), and a digest with the same byte sum but different bytes.

  • Mapped-address prefix pinned (51b6440f). New must-refuse rows: 2001:db8::ffff:7f00:1, 1::ffff:127.0.0.1, fe80::ffff:6440:1, 0:0:0:0:1:ffff:7f00:1, plus the loopback near misses ::ffff:0:1, ::5:0:1, 0:0:0:0:1:0:0:1 and 1::1.

  • The weakenings list (dbd61f56). packages/sdk/tests/weakenings.ts lists 21 weakenings of the auth guards, the eight reviewers found by hand among them. Each comes with its source edit and the test that must refuse it. node packages/sdk/tests/weakenings.ts . plants each one, runs its test, restores the file, and exits 1 if any passes. All 21 are refused at this head. AGENTS.md points to it.

  • Offline list and revoke refuse a missing store (4e971702). A mistyped stateDir used to create an empty server.db and print an empty table with exit 0. Both commands now refuse it and create nothing, and they print only rows already read. Only the lock refusal says to stop the control plane. A newer schema or a foreign file keeps its own message. The offline revoke answers NotFound, like the online one. The table rows come from the SDK's tokenRows, which the CLI shares. The offline test lists after revoking, so a list that drops revoked rows fails it.

  • Recovery steps (c03c74dd): keep the control plane stopped throughout, revoke down MINTED_BY from the leaked token and anything minted after the leak, re-add callers the leak revoked, and list again before starting. The README now says this restores the tokens table and nothing else.
  • Harness verification (c03c74d), fixed in daa290cd, 08558d03, 41795afa

  • The weakenings harness no longer reports success when nothing ran (08558d03). Before, any non-zero run counted as refused: with vp off PATH it printed all 21 refused and exited 0. Now each weakening names the test that must refuse it. A weakening counts as refused only when its run exits 1, the named test fails on an assertion, and no file fails to load. Each test file must also pass on the unchanged code before anything is planted. Anything else exits 1. Each of these exits 1: vp off PATH (spawnSync vp ENOENT), a pattern that no longer matches, a plant that doesn't compile, a missing test file, a plant caught only by a test other than the one it names, a dirty source file at start, SIGINT to the process group, and SIGTERM to node. After both signals the source files are clean.

  • Interrupts: the harness puts the source back on SIGINT and SIGTERM, and refuses to start when a file it plants into is dirty.

  • Minted-token entropy (daa290cd): 4096 mints must each be 64 lowercase hex, all distinct, with no 8-byte block repeated. randomBytes(2)…repeat(16) (16 bits) and randomBytes(16) fail it, and both are in the list. All 23 are refused, each by the test it names. No functional test can tell randomBytes from a non-cryptographic generator of the same width, and the repo forbids module mocks, so the source itself is pinned only by review.

  • CI: a weakenings job runs the harness on a fresh checkout. It stays out of vp run ready, since it edits source. Its first two CI runs failed closed, never reporting success:

  • - At 41795af the baseline failed, because the job lacked the zsh and busybox guest shells the host's tests need. 5900962 installs them and prints a failing baseline's output.
    - At 5900962 all 23 runs were unproven, because CI colours vitest's FAIL lines and the harness couldn't read them. 7b7b8bf strips terminal escapes first, and on CI all 23 are now refused, each by its named test.
  • README caveats (41795afa): a token readable from inside a machine through exec survives the procedure. When the leak's start is unknown, treat every token as minted after it. list has no REVOKED_BY, so "revoked though you didn't" rests on memory. Then audit machines, checkpoints and templates. Neither REVOKED_BY nor last_used_at is added, by Gjermund's decision (see below).

  • Verified end to end by the reviewer, against real binaries. A leaked token minted a token that minted another, and the leak revoked two legitimate callers. After the procedure, all six old tokens are refused and the four new ones are served. The reviewer also planted 14 weakenings of its own across the host hop, TLS, the token-URL rule, an empty bearer, MINTED_BY and the store's revoke, and existing tests refused every one. So the gap was the list's coverage, not the suite's.
  • Checked against practice (7b7b8bf), with the token prefix in 53b62d6e, b0cf00a4, f8f6f222

    A review compared the design with how others solve the problem, not only looking for bugs. Its verdict: this is the normal shape.

  • Caller tokens: named, long-lived bearer tokens, kept as SHA-256 in the control plane's own store and checked on every request. This is how Nomad and Consul ACL tokens and GitLab's token_digest work.

  • The host hop: a secret in a file, as Prometheus's credentials_file does it.

  • Startup refusal: refusing a public listen address without auth matches Redis protected mode and Jupyter.

  • What it doesn't need: at one operator, mTLS, SPIFFE or short-lived tokens issued from a long-lived one would add a CA or an identity provider for no gain.
  • Every token is an admin token, by Gjermund's ruling. This departs from the role split in Nomad (management against client tokens), Buildkite (agent tokens) and Tailscale (auth keys against API tokens). The likeliest leak, an unattended provider's token, can mint its own persistence. MINTED_BY, the offline token list and revoke, and the README's stopped-server recovery are what make this survivable. It is deliberate, not an oversight.

    No REVOKED_BY and no last_used_at, by Gjermund's decision. The tokens table records who minted each token and when, and when it was revoked, and nothing more. So the README's "revoked though you didn't" step rests on the operator's memory, as a permanent property of the design rather than a gap waiting on a column. Both stay cheap to add later if operating clankerbox makes them worth having: a nullable column each, an optional Token field, and for last_used_at a coarse write at most every few minutes per token so a request doesn't become a database write.

    Token prefix (53b62d6e). A token used to be 64 hex digits, the same form as the SHA-256 it is kept as. GitHub left that format in 2021 because scanners can't tell such tokens from hashes.

  • Format: a caller's token is now cbx_ and a host's cbxh_, each followed by 32 random bytes as hex. gitleaks, trufflehog or GitHub push protection can match cbxh?_[0-9a-f]{64}, and the README says so.

  • The prefix is hashed with the token. The bearer value is hashed exactly as presented and compared over the full digest, with no parsing before the comparison. So nothing strips or reads the prefix on the way to the comparison, and the prefix can't become a shortcut in it. A token's digits under the other hop's prefix, or under none, hash differently and are refused. Nothing checks a request by its prefix: it is for recognition only.

  • Token files are read for the hop that uses them. A file holding a SHA-256, the other hop's token, or a token without its prefix is refused, saying which.

  • Names: token add, the mint API and callers files refuse a SHA-256 or a token given as a name. Before, a pasted hash was taken as a valid name.

  • Tests mint for each hop, refuse every one-character change of a token (prefix included), and run the bit, permutation and byte-sum comparisons for both prefixes.

  • Weakenings (b0cf00a4): seven new ones, 30 in all, each refused by its named test:

  • - comparing only 4 bytes after checking the caller's prefix, or the host's;
    - taking any prefixed token without comparing;
    - hashing only a token's first 36 characters, or its digits without the prefix;
    - a token file taking either hop's token;
    - a SHA-256 passing as a name.
  • No checksum. With a distinctive prefix and 64 hex digits, scanners have few false positives anyway.

  • token list --config output pinned. Printing nothing passed every test, though the recovery procedure is built on reading that output. The offline test now runs the command itself and asserts its header and, for each row, the name, MINTED_BY and whether it is revoked. The weakenings "prints nothing" and "prints no MINTED_BY" are refused, 32 in all.
  • The Stryker trial found two fail-opens that four review rounds and the hand-built weakenings list all missed (fixed in f8f6f222). Each would have let a control plane or host listen on a public address believing it private, with no tokens and no TLS, and let a client send its token there over plain http. That is the exact hole the startup refusal exists to close:

  • dropping a === 100 in isTailnetOrLoopback accepts x.64–127.. for any first octet: 10.64.0.1 passed every test as tailnet;

  • dropping its fd7a or 115c check accepts public IPv6 whose third group is a1e0: 2001:db8:a1e0::5 passed every test as tailnet.
  • Fifteen more survivors took malformed text as loopback or tailnet, such as 0::1g, 127.0.0.256, 127.0.0.01 and a seven-group fd7a:115c:a1e0 address. Twenty table rows now kill all 146 mutants of reach.ts.

    What the trial cost, for whoever adopts it properly. AGENTS.md has the same notes, beside the weakenings list.

  • Setup: Stryker 10.1.1 with the vitest runner, which works with this repo's vitest 5.1.

  • Workaround 1: tsconfigFile must name no file, because TypeScript 7 has no JS API for Stryker to read a tsconfig with.

  • Workaround 2: inPlace: true, because Stryker's sandbox copy breaks each package's relative extends of the base tsconfig. Running in place edits the checkout, so it needs a scratch worktree.

  • Speed: 338 mutants over the SDK's auth code in 130 s, and 150 over the server's tokens.ts, token.ts and listen check in 60 s, with the test files narrowed.

  • Noise:

  • - about 15 SDK survivors were equivalent or harmless, such as bearer-regex anchors (a matching token is still required);
    - the server's survivors are all in the token command layer, which is how the empty token list output was found.
  • Overlap: only about 6 of the 32 weakenings are mutants Stryker generates by default, so the tool and the list cover different ground.

  • Not wired into CI: with two workarounds and in-place runs, it is too fragile to be a security job yet.

  • Candidate: about 30 SDK mutants (in readToken and the caller-name and prefix rules) have no coverage in the SDK's own suite, because their tests live in apps/cli and apps/server, so SDK coverage understates what is tested.
  • Candidate for later: a clankerbox-server tls init helper, since an off-tailnet deployment now needs TLS.

    Not covered

  • The five real runtime adapters (smolvm, Tart, boat, smol cloud, agent-sandbox) now read publishAddress(settings) where they read listen.address. That one-line change is checked by types only: no runtime here can boot a guest. The split was proven through the fake runtime, which now reads the same address.
  • Release note for 0.44

    0.44 adds opt-in caller authentication, so clankerbox can run without a tailnet. Set tokens: true and tls on the control plane, callers and tls on each host, a token file on each hosts[] entry, and a token in each client. The control plane and hosts may then listen on any address; without both fields they still refuse anything but a tailnet or loopback address. Mint your first token with clankerbox-server token add <name> --config <server config> while the control plane is stopped. A caller's token starts cbx_ and a host's cbxh_, so secret scanners can find a leaked one. After that, mint, list and revoke tokens with clankerbox token, which takes effect at once with no restart. Any caller's token can do this, so treat every token as full control of the fleet: after a leak, stop the control plane and follow the README's recovery steps with clankerbox-server token list and token revoke --config. A host can publish machine SSH on publish.address, apart from its API. Nothing changes for a deployment that sets none of these. Upgrading is still lockstep by release as before, but turning tokens on is a separate step you take when ready.

    Off-tailnet transcript, before the move to the store (abridged)

    $ command -v tailscale tailscaled || echo none
    none
    listen.address 203.0.113.10 is not a tailnet address (...) or a loopback address, so it needs callers set too: without them anyone who reaches it can act on every machine, and tokens would cross the network in the clear      [server, no callers: exit 1]
    ... so it needs tls set too ...                                                                                                     [server, no tls: exit 1]
    host-refusal without callers / without tls: the same, for listen.address 203.0.113.20                                              [exit 1]
    LISTEN 203.0.113.10:8585 (clankerbox-server)    LISTEN 203.0.113.20:8484 (host)
    $ clankerbox hosts                      fixed-1  up  fixed  0.43.2
    $ clankerbox create dev --base ubuntu --runtime fixed --cpu 1 --ram 1G --disk 10G    dev
    $ clankerbox exec dev -- echo hello from dev     hello from dev
    $ clankerbox stop dev                    dev stopped
    $ clankerbox start dev                   dev running
    machines: { name: 'dev', host: 'fixed-1', endpoint: '{"host":"203.0.113.21","port":21000}' }
    $ clankerbox hosts   (no token)          Invalid: the control plane refused this caller: this control plane takes only a caller with a token, and this request carries none; give the client the token whose hash is a line of the control plane's callers file
    $ clankerbox hosts   (another's token)   Invalid: the control plane refused this caller: this control plane takes no caller with this token; ...
    $ clankerbox hosts   (no CA)             Unavailable: ... self-signed certificate in certificate chain
    $ curl http://203.0.113.10:8585/...      curl: (52) Empty reply from server
    $ curl https://203.0.113.20:8484/host/readHost  (no token)          {"_tag":"Unauthenticated","message":"this host takes only a caller with a token, and this request carries none"}
    $ curl ...  (another host's token)       {"_tag":"Unauthenticated","message":"this host takes no caller with this token"}
    control plane restarted with another host's token for fixed-1:
    $ clankerbox hosts --json                {"id":"fixed-1","state":"unreachable","problem":"host fixed-1 refused the control plane's token: this host takes no caller with this token; its entry in the config must name the token whose hash is in the host's callers"}
    

    The rerun against the store is off-tailnet-store.sh and its transcript, beside the original script off-tailnet.sh, kept in the Amp thread's orb backup. The test harness now accepts CLANKERBOX_HOST_CONFIG (commit 340f504f), which is what let it serve a host from a real host config.

    Fixes from Greptile's review

  • Tokens over plain http (91b85a43): a token goes only over https, or http to a tailnet or loopback IP. Client.make and the server config's host entries refuse any other URL with a token.

  • Wildcard publish (38a8ab0b): a host refuses to publish machine SSH on 0.0.0.0/::, whether set directly or inherited from a wildcard listen.address.

  • Unfinished TLS handshakes held shutdown (6b28ac1b): confirmed with a probe (close still pending after 8 s), then fixed by destroying tracked sockets.

  • Concurrent token add (8780db1b): it now appends instead of rewriting. The help no longer claims the log names the caller.
  • Each fix has a test that fails against the old behaviour or a planted wrong version. vp run ready passes 16/16.

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: gjermundgaraba Review duration: 2356m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #72"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 29.7% · Safe to merge
    29.7%