Skip to content

Download gate: per-box maker acceptances for the factory (#464) - #470

Draft
teaspoonai wants to merge 14 commits into
license-installer-no-namefrom
feat/gate-maker
Draft

teaspoonai wants to merge 14 commits into
license-installer-no-namefrom
feat/gate-maker

Conversation

@teaspoonai

Copy link
Copy Markdown
Contributor

Closes the teaport side of #464 (part of #465 / #283): the factory installs the engine on each box as Teaspoon AI, with a per-box maker acceptance, and no shared secret in any image. The station side (teaport-factory) and the owner's acceptance at setup (#465) are not in this PR; RELEASING.md "Worker secrets" sets what teaport-factory has to build.

Draft, stacked on #469 (base license-installer-no-name, which carries #468): it merges after both, per the agreed order #468 → deploy + 0002 → #469 → this, and is retargeted to main once #469 lands.

How it works

  1. At provisioning (the box's first boot in the factory, when its agent asks the station's /provision), the station calls POST /api/factory with the station-only FACTORY_TOKEN, the box's device_id (SHA-256 of teaport-appliance: + its appliance serial) and the installer pin. The Worker records a maker acceptance (maker_acceptances, no name or email: Teaspoon AI installing its own box, no one's acceptance of the license) and returns its id.
  2. The box's agent writes only that id as its license receipt: {"method": "factory", "acceptance_id": "maker-…"}, root 0600.
  3. The first-boot install.sh sees the factory receipt and gets download tokens with it through /api/token, whatever the current license version, for MAKER_MAX_DAYS after provisioning. A factory receipt never counts as an acceptance of any version.
  4. The seal removes the receipt, so the box ships without one, and its owner accepts the license (License: the owner accepts the engine license at setup; the factory installs as the maker #465) before its first engine download or update. An expired, revoked or unknown maker record makes install.sh fall back to the owner accepting; an explicit --accept-eula always wins.

Worker

  • POST /api/factory: rate-limited first, then FACTORY_TOKEN (constant-time), then misconfiguration (503: a secret under 32 characters or equal to CHECK_TOKEN/TOKEN_KEY; a bad FACTORY_DAILY_MAX or MAKER_MAX_DAYS), then the body. Caps: FACTORY_DAILY_MAX boxes a day and MAKER_PER_BOX_DAY (10) records a box a day, both counted per FACTORY_TOKEN (a keyed mark on each row), so a rotation after a leak lets the factory go on at once.
  • Maker ids are maker- + 24 characters, acceptance ids 24 characters; maker tokens carry k: "maker". Neither is ever taken for the other (tested both ways). A maker token never outlives its record, and every download re-checks the record (revoked, expired, gone), with the gate open or not.
  • FACTORY_TOKEN downloads nothing and gets no token.
  • Migration 0003_factory.sql only adds a table: the Worker before it still runs, refusing maker tokens and ids (fails closed). Retention deletes maker rows and their downloads like acceptances'.

The points #464 asked to think through

  • A leaked FACTORY_TOKEN: records for made-up boxes, each reaching every gated file for MAKER_MAX_DAYS. Brakes: the two caps, the per-IP limit. Detection: the records' IP, country and box. Remedy: rotate (stops new records), and revoke records since the leak. The station's /provision would hand out the same records without a leak, so it must answer only on the boxes' USB interfaces. A rollback past a rotation brings the old secret back: RELEASING.md says how to rotate again without redeploying a broken main.
  • Scope: the gate covers dl/engine/ and dl/models/ only, which is all a maker record reaches.
  • Retention and privacy (docs/engine-license-data.md, "The factory's rows"): 7 years like acceptances, flagged for counsel (these rows prove no contract). Not personal data when written; the device_id hides the serial from nobody (serials follow a date-and-number pattern), so after sale they are the owner's data. Erasure steps added.
  • CI: FACTORY_TOKEN is never a GitHub secret or variable, no workflow names it, the tests use a made-up one, and worker-deploy leaves Worker secrets alone.

Settings (decided by the product owner)

  • MAKER_MAX_DAYS = "3": how long a provisioned box can download under its maker record before its owner must accept. A factory install takes hours; the seal removes the receipt either way.
  • FACTORY_DAILY_MAX = "50": the most boxes recorded in 24 hours, above the factory's busiest day for now.
  • Retention: the factory's rows keep the 7 years acceptances have, flagged in the data note for whoever reviews the license and privacy notice.
  • Still to come, each with the product owner's OK: setting FACTORY_TOKEN on the Worker, and the deploy.

Notes

  • Download gate: a maker download kind for the factory station #464's latest comment says the acceptance is recorded "at flash time" by device_provision. In teaport-factory, device_provision.py is the box's agent and runs at first boot; the flash image is the same for every box. RELEASING.md follows the real flow (the station's handle_provision calls the Worker, the agent writes the receipt). The box does have /etc/machine-id by then; the station uses the serial because that is what it knows.
  • Follow-ups not here: signing the station's request instead of sending the secret (keeps it out of Workers Logs); an optional Cloudflare rule letting /api/factory in only from the factory's IP; the public licenses page and FAQ once License: the owner accepts the engine license at setup; the factory installs as the maker #465 lands.

Tests

  • Worker: 40 (the maker path: recording, tokens, downloads, license changes, expiry, revocation, gone records, misconfiguration, both caps, rotation, the keyed mark, ids never crossing, rate-limit order, retention). Each guard was mutation-checked by the reviews.
  • Installer: factory receipts with and without a license server, every server answer, server down then refused later, --accept-eula, dry run, the exact receipt shape.
  • Docs lint: 0 errors.

Reviewed by independent agents until clean (code clean since the first rounds; the later rounds tightened the teaport-factory requirements against its code).

🤖 Generated with Claude Code

teaspoonai and others added 14 commits November 23, 2026 19:39
The factory station records, as it provisions each box, a maker acceptance for it
(POST /api/factory, authorized by the station-only FACTORY_TOKEN; a maker_acceptances
row: no one's acceptance of the license) and writes only its id into the box, as the
receipt. install.sh's first-boot run gets download tokens with it through /api/token,
whatever the license's version, for MAKER_MAX_DAYS; after that, or once revoked, the
box's owner accepts (#465). No secret ships in any image. Each record is per box and
revocable; FACTORY_DAILY_MAX caps the boxes recorded a day, per FACTORY_TOKEN.
Migration 0003 (after #468's 0002), additive.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A factory receipt is never an acceptance of its version, with or without a license
server to ask; --accept-eula is honored over it. RELEASING.md follows teaport-factory's
real flow (the station calls /api/factory in /provision, the box's agent writes the
receipt before /etc/appliance-id, the seal removes it, the first-boot unit drops
TEAPORT_ACCEPT_EULA). The data note: what a box shipped with its receipt would record.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A revoked factory record lets the owner accept, as an expired one does: it says nothing
about them. RELEASING.md: /provision answers only on the boxes' USB network and only for
boxes the station flashed; the record id goes beside ProvisionConfig's keys, so older
agents still provision; the first-boot unit waits for /etc/appliance-id; the shared
per-IP limit; how to provision a box again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RELEASING.md: the station sends a box its stored maker id again on a retry or while it
stands, and records a new one only past its time, revoked, or on purpose; where the
station keeps FACTORY_TOKEN; the receipt needs only method and acceptance_id; the seal
checks the receipt is gone. A download with a maker record past its time is refused
with 403; a later token request in the same run speaks of the factory record. A test
pins the cap's per-secret 'seen'.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The station records a new maker acceptance on every /provision (it can tell neither a
stored one's state nor a retry from provisioning again); the Worker bounds that at
MAKER_PER_BOX_DAY (10) records a box a day, per FACTORY_TOKEN. A MAKER_MAX_DAYS set up
wrong answers 503, the server's fault. The seal refuses a non-factory receipt.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RELEASING.md: who may get a record is enforced by /provision answering only on the USB
link (the station keeps no flash or seal record by module to check against); the box's
agent treats an answer without a well-formed acceptance_id as a failed attempt; the
receipt holds method and acceptance_id only; seal and provisioning again said apart.
A download whose maker record is gone answers 403, as an acceptance's.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RELEASING.md: the station calls /api/factory last, once its answer is built and checked,
so a station failure cannot spend a box's records; a fixed URL in the station's config;
how to recover a box the seal refuses. The per-box limit answers factory_box_cap. Tests:
the secret before the setup checks, and the receipt exactly as the station writes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RELEASING.md: /provision is limited by an input rule on the USB interfaces, not by its
address (the station routes for the factory Wi-Fi); the station sends FACTORY_TOKEN only
over https, follows no redirect, and keeps the header off any; the Worker call and the
secret stay out of the code baked into boxes; the station stops calling after a 401 or
503 and waits after factory_cap; the first-boot unit started by the agent; an optional
IP rule on /api/factory.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RELEASING.md: the first-boot unit needs no start from the agent (its timer tries again
after a skipped start; a plain start from the provisioning unit would hang); the station
stops calling only on the Worker's own bad_factory_token or factory_misconfigured, not on
any 503; FACTORY_TOKEN in a 0600 file, never the environment the bake and flash commands
inherit; an interface rule, not SO_BINDTODEVICE, and why; the record names the box
image's pin; the receipt written atomically; a User-Agent of the station's own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RELEASING.md: the record's installer is the pin the box's agent reports (an image_id
does not tell bakes apart); an overall deadline on the station's call; the nft rule lets
loopback in, names the boxes' interfaces by USB vendor, and serve checks it covers its
port; fullmatch for the id; the agent makes /var/lib/teaport; restart serve after a
rotation; the station keeps no maker ids in its logs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RELEASING.md: the box has its machine-id at provisioning; the station uses the serial
because that is what it knows; the boxes' interfaces get unique names under one prefix
by a udev rule (a .link Name= names one interface, and several boxes are attached at
once); the agent is to start sending its pin; the answer's new key goes in docs/06;
reading the ruleset needs sudo. An absurd MAKER_MAX_DAYS fails closed with 503.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RELEASING.md: the boxes' interfaces named tpbox$attr{ifindex}, unique while the station
runs (%n repeats usb0 and usb1 for every box, so a second box would be dropped); an inet
table; what else names usbN; restart the station after fixing the Worker's settings.
The box's agent, not the station, writes the receipt (comments). The retention cron's
maker deletes are statements of their own.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
RELEASING.md: restart the station a minute after a rotation (an edge can answer for the
old version that long); a Worker call that succeeds past the station's deadline spends a
record. wrangler.toml: what a bad MAKER_MAX_DAYS does to existing records.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…t owner's)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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