Public: anyone can read this; the crew can change it.

A deployed forge is claimed by one link over HTTPS on its own name, on a hardened machine #16255

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

Fixes #16217 and the boot-config half of #16218. Found by a security review of the pinned-forge path before forges are sold on it: a deployed forge could not be claimed by anyone, was served on a bare address over plain HTTP, ran as root with every port open, and had password SSH on.

Notes

shipped production is serving it deploy 3fede26

opened this

Fixes #16217 and the boot-config half of #16218. Found by a security review of the pinned-forge path before forges are sold on it: a deployed forge could not be claimed by anyone, was served on a bare address over plain HTTP, ran as root with every port open, and had password SSH on.

Claim (#16217)

  • A deploy takes a hostname and answers once with a claim link. The seller makes the code and keeps only its sha256 and deadline; the boot config carries FORGE_FIRST_ADMIN_SEED=<sha256>@<deadline> and seedFirstAdmin seeds the existing first-admin row from it once. One redemption path, as before; the claim lives 7 days (FIRST_ADMIN_SEED_TTL_MS).
  • Claimed or not is read from the deployed forge (GET /api/v1/first-admin/claim?seed=<hash>), not kept by the seller.
  • Reissue replaces the server on the same volume, and is refused once the forge says claimed.
  • HTTPS on the forge's own name: cloud-init installs Caddy from Ubuntu's repository with a one-site config; the forge binds loopback through a new FORGE_BIND; urlOf is https://<host>/. DNS is not automated: deploy and check name the record, and check says "waiting for DNS" until the name resolves to the machine.

Hardening (#16218)

  • The forge runs as the unprivileged user forge from a root-owned Bun, under a locked-down unit. ufw allows 80 and 443 only. sshd refuses passwords and root. Unattended upgrades on. bubblewrap, socat and an AppArmor profile that lets /usr/bin/bwrap make a user namespace.
  • Each create sends a throwaway SSH public key (private half never kept) so neither cloud generates and mails a root password, then deletes the key.
  • checkConfig refuses names that steer the loader, runtime or path, the names the boot sets itself, and more secret-like names. The deployed forge's env sets FORGE_CREW_SANDBOX=require (honoured by #16233).

Not done

  • Provider-level firewall (machine firewall only).
  • A reserved address or DNS upsert: every Update, Roll back or reissue gives a new IP and the record is edited by hand.
  • #16220 must also guard claimPinned, which replaces the machine outside the update path.
  • A forge deployed before this has no hostname; Update and Roll back are refused until a claim names it.

Tested Built by two subagents on a laptop. Before the merge, on Bun 1.4.2: typecheck clean, gate 0, 313 pass in 19 files, 975 pass in 23 guard files. After the merge, only what runs without a listening socket was run: typecheck clean, gate 0, pinned-harden, pinned-forge-recovery, pinned-hetzner, pinned-canary, first-admin-recovery-unit and 7 of pinned-claim pass. NOT run after the merge: pinned-forge, pinned-forge-address, pinned-hetzner-doors, pinned-page, first-admin, first-admin-recovery, first-admin-timing, and the two-forge block in pinned-claim; expected call sequences in pinned-forge and pinned-claim were edited without being run. This pull's check is their first run. Nothing here has booted on a real machine; docs/features/pinned-forge.md lists what only a real boot proves.

A fix-up follows on this branch: Caddy's certificates on the data volume, and no default page before our config.

No look: the pinned page gains a hostname field and a one-time claim link.

Files: src/cloud/machine.ts, src/cloud/harden.ts, src/cloud/throwaway_key.ts, src/cloud/droplet.ts, src/cloud/hetzner.ts, src/core/pinned.ts, src/core/first_admin.ts, src/actions/pinned.ts, src/http/pinned_routes.ts, src/web/pinned.ts, src/tui/screens/pinned.ts, src/main.ts

🤖 Generated with Claude Code

commented

This pull now carries the whole sell-ready deploy; #16232 (ceiling) and #16233 (sandbox hold) are folded in and closed, and main (with #16220) is merged.

Since the description was written:

  • "Claim" is one thing: the buyer's link. Claimed is the deployed forge's own answer; the seller's row takes #16220's claimed_at and emits pinned.claimed once. After that update, rollback and reissue are refused. The manual "Hand to buyer" path is removed.
  • Certificates live on the data volume, so a replaced machine reuses its certificate; the Caddyfile is in place before the package first starts.
  • Every cloud account has a monthly ceiling ($50 by default, dollars everywhere, one conversion function); every driver create passes it, including reissue, and a test fails on a bare driverOf(. Creates queue per account and changes queue per forge.
  • FORGE_CREW_SANDBOX=require holds queued runs, conversation turns and one-shots when the sandbox is unavailable, and re-probes at most once a minute while something waits. Default off is unchanged; a deployed forge sets require.
  • From an adversarial review: ProtectKernelLogs removed from the unit (it would likely break bubblewrap's /proc mount); the SSH listener is off on a deployed forge.

Still true: nothing here has booted on a real machine, and the tests that need a listening socket have only ever run in this pull's check. Known gaps: the hold sentence suggests FORGE_CREW_SANDBOX=off, which a deployed forge cannot set; DNS is by hand and changes on every replace; no provider-level firewall; no hostname ownership check.

Changes requested — before the latest push

I read the whole diff except the tail the review view cut off. That tail is the rest of claimNow, check and src/cloud/*. I opened the preview. / answers 200, and /pinned and /deploy-to answer 303 to sign-in without an admin session, as intended. The pictures on the pull are only / and /docs (listed at /looks; I could not fetch the image bytes). None shows /pinned, /deploy-to or the cloud page, so the design points come from the code.

What holds up:

  • The claim link keeps only its hash in the row, in boot config and in events.
  • The seed is taken once at boot.
  • The status oracle answers only to the matching hash, compared with timingSafeEqual.
  • Same-origin and admin checks are on the new routes.
  • README is untouched, the how-to is in docs/features, and a TUI screen exists.

Changes needed, in order:

  1. Never: a cap or hold is added where removing something would do.
    • The $50 default ceiling refuses every create on every cloud account once the account is near it. Its own docs say the figure comes from list prices, not the bill.
    • FORGE_CREW_SANDBOX=require holds runs, turns and one-shots. Your own notes say its hold sentence suggests FORGE_CREW_SANDBOX=off, which a deployed forge cannot set.
    • Neither is needed for "claimed by one link over HTTPS on a hardened machine". Drop them from this pull, or make the ceiling opt-in with no default and the hold a visible notice only. A forge that refuses to deploy or run is close to the "locks up" Never.
  2. Split. Ceiling (#16232) and sandbox hold (#16233) are each usable alone and are unrelated to the claim link. Land them as their own pulls. The pull is now about 4000 lines that has never booted on a real machine.
  3. Design: hand-rolled markup (principles 3, 6, 7).
    • src/web/pages/pinned.ts adds a raw <input class="mono"> inside the action row. It has no visible label and does not use field.
    • src/web/pages/cloud.ts puts a number input and a second button into every account row, next to Verify, Write, Audit and Remove. Put the ceiling on its own confirm or settings page, using the named field component, or remove it (item 1).
  4. Principle 1 and 8: the page says things twice.
    • The cloud page now has a new paragraph plus a ceilingLine on every row.
    • The pinned list repeats the claim-link sentence in the rows. The issued page has a sub line, then claimWords, then a muted paragraph saying the same thing.
    • Cut each to one sentence.
  5. Unauthenticated GET /api/v1/first-admin/claim?seed=. It is hash-gated, which is fine. But a hash in a query string lands in access logs and the proxy's logs. Take it as a POST body or confirm no log keeps the query.
  6. Hostname ownership is not checked (your own known gap), and the DNS record is made by hand and changes on every replace. The machine then serves a certificate request for any name you type. Say in the pull what stops a typo or someone else's name from burning Let's Encrypt limits. At least a resolve check before the machine is made.

Fix 1 and 2 first.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs