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

Edges: firewalls for DigitalOcean and Hetzner as an infra kind, with plan steps and drift (#16696) #17092

opened this

Merged 40h 50m ago, live in production

This adds the firewall kind to the infra plan for DigitalOcean and Hetzner (phase 2 of #16696), starting with a firewall for an existing pinned machine. The new and touched suites pass and tsc is clean. I did not try it against a real DigitalOcean or Hetzner account, and I did not run the full bun test.

Notes

opened this

This adds the firewall kind to the infra plan for DigitalOcean and Hetzner (phase 2 of #16696), starting with a firewall for an existing pinned machine. The new and touched suites pass and tsc is clean. I did not try it against a real DigitalOcean or Hetzner account, and I did not run the full bun test.

What changed

  • Firewall kind. plan.ts gets a FirewallWant (machine name plus account) that adds one firewall step. It is free, so the delta is $0 and the account's before and after are equal. It is refused when:
    • the machine isn't on that account or is retired;
    • the account is read-only or not held;
    • a standing orphan is on the account;
    • the cloud has no firewall support (OVHcloud).

    A machine wanted in the same plan gets its firewall after its own steps. apply skips it when it already stands.

  • Cloud calls. New src/cloud/firewall.ts holds the DigitalOcean and Hetzner calls, reached through a new optional firewall on Driver.
    • It opens ports 80 and 443 inbound and nothing else.
    • It applies by the forge's tag (DigitalOcean) or label (Hetzner), so a machine an Update replaces stays behind it.
    • It adopts an existing forge-<name> firewall rather than making a second.
    • On Hetzner, a delete first removes the firewall from its machines, since Hetzner refuses to delete one that is still applied.
  • Lifetime. firewallPinned in actions/pinned.ts makes the firewall and records its id in a new pinned_firewall table (migration and pin included). retirePinned deletes it with the machine, so auto-retire at end-of-life does too. A retire that stopped before the firewall delete can be run again to finish it.
  • Orphan detection. The hourly watch now reads firewalls. One named forge-<name> with no live forge recording it is an orphan, raised like an orphan machine, with $0 list price. /infra drift now says "1 firewall". Firewalls named any other way are left unread, so a hand-made one won't raise "outside".
  • Door. The infra MCP tool's plan takes want: {firewall: "<machine name>"}, then apply its id. docs/features/infra.md covers it.

What I reused: the existing retire, withCloud, oneChange and gone helpers, the plan's refusal and ledger machinery, and the watch's Seen/judge path. caller and gone in machine.ts are now exported so the firewall module could use them.

What I chose not to do

  • No terminal or web compose offering. The commits say No door: for that.
  • No cost model: both clouds charge nothing for firewalls.
  • No firewall for OVHcloud.
  • I did not guess at Hetzner's firewall-delete behaviour beyond the remove-from-resources call, and it has no real-API test.

Things to know

  • The watch now reads /firewalls on each account. If a read-scoped DigitalOcean token can't list firewalls, that account's reading becomes "could not read" until the scope is widened. It does not fail quietly.
  • I edited existing tests: test/pinned-ceiling.test.ts, whose guard allows ensureFirewall and removeFirewall taking a bare driver (a free firewall moves no money) and counts 10 driver uses instead of 8, and test/infra-plan.test.ts, whose helpers gained the new fields. test/helpers/recorded-cloud.ts now answers firewall calls.
  • New tests are test/firewall.test.ts plus additions to the infra-plan, infra-plan-apply, infra-page and cloud-watch suites.
  • schema-migrations timed out in one batch run and passed alone.

To try it: on the preview, call the infra tool with {action: "plan", want: {firewall: "<a running machine's name>"}}, then {action: "apply", id: <plan id>}. show the plan id to see the step.

🤖 Generated with Claude Code

Closes #17070

Show 1 earlier items

7 earlier comments
commented

The check failed because the pinned-firewall migration and a migration that landed on main had the same timestamp, 20261201140000. The generated migration list then contained m446 twice.

I merged main and renamed mine to 20261201150000-pinned-firewall.ts, so it now sorts after main's scan-finding-excerpt. I regenerated src/generated/migrations.ts with bun scripts/own-source.ts, and the generated list now has m446 and m447 once each.

bun x tsc --noEmit is clean. test/firewall.test.ts and test/own-source.test.ts pass (8 tests); I did not run the full suite, since the forge runs it on push. The merge is pushed. The only conflict was the generated migrations file.

I left the three gate notes alone. They are advisory: the setFirewall and noteScanRun similarity, the cloud and f helpers in test/firewall.test.ts, and the long comment lines the nightly rewrap handles on main. I also did not touch the design-drift warning about 11 one-off classes. It is about files under src/web/, which this pull does not change.

commented

The gate no longer complains about the migration pin. The remaining gate lines are similarity and comment-width notes. In the failing log only the missing-pin line was marked failed:, so I take the rest to be advisory.

The migration had been renamed to 20261201150000-pinned-firewall, but the old 20261201140000-pinned-firewall.pin was still committed. I removed that stale pin and ran bun scripts/pin-migrations.ts, which wrote src/core/migration-pins/20261201150000-pinned-firewall.pin. That is committed and pushed as 9d7db6441. test/schema-migrations.test.ts and test/firewall.test.ts pass (31 tests); I did not run tsc or the full suite.

I left two things alone:

  • Similarity notes: setFirewall resembles noteScanRun, and cloud resembles f in the firewall test. Both are phrased as questions ("one implementation?"), and I judged merging them out of scope for this fix.
  • Long comments: gate --fix reported nothing to rewrap in those eight files, and the gate says the nightly rewrap handles them on main.

The forge will run the full check on this push.

commented

I merged main into the branch and pushed it. The only conflict was src/generated/migrations.ts.

I took main's version of that file and regenerated it with bun scripts/own-source.ts. That gives main's new migration 20261201140000-app-registry-item and ours, 20261201150000-pinned-firewall, together in the index. bun scripts/pin-migrations.ts found every migration already pinned.

tsc --noEmit is clean, and test/own-source.test.ts, test/schema-migrations.test.ts and test/firewall.test.ts pass (34 tests). I did not run the full suite, so the forge's check on this push is the full run.

commented

This pull adds a firewall kind to the infra plan, for a machine that is already pinned. The one failure reported on #17092 did not reproduce.

What changed

  • Firewall kind: a firewall is planned as a free step around a pinned machine. Both the DigitalOcean and Hetzner drivers can create one (src/cloud/firewall.ts, plan.ts, droplet.ts, hetzner.ts, drivers.ts).
  • Pinned machines: the pinned-firewall record is new (src/core/pinned_firewall.ts plus a migration), and actions/pinned.ts and actions/infra.ts apply it.
  • Orphans and retire: the hourly watch reads firewalls and flags orphans, and retire deletes them (watch.ts, watch_read.ts).
  • MCP: the infra MCP tool can plan a firewall.
  • Ceiling guard: it now counts the firewall's two driver uses.
  • Docs: docs/features/infra.md covers the new kind.

This push

  • The red check: it failed on #17092, the pull that follows this branch, on /, /explore and a repository page, rendered 2,000 times > grow the heap by under 24 MiB. I changed nothing for it. test/pages-memory.test.ts passes here (5 tests), so it may be flaky under load or caused by something else on #17092.
  • Merge: I merged main into the branch with no conflicts.
  • Tests: the following pass, 95 tests in total:
    • the dead-export and UNTIMED job guards;
    • the firewall tests;
    • the plan, plan-apply, watch, ceiling and page tests.

    tsc and design-lint are clean. I did not run the whole suite; the forge's check does that on push.

  • Gate: its only remarks are long comment lines in eight files (left for the nightly rewrap) and a possible duplicate between core/pinned_firewall.ts#setFirewall and checks/scan_store.ts#noteScanRun. I left the duplicate: the two are small setters over different records.

What I chose not to do

  • No firewall rules beyond the pinned-machine case.
  • No firewalls for machines the forge doesn't pin.

How to try it Plan an infra step for a pinned machine with the infra tool, or open the infra page. The plan lists the firewall as a free step, and the hourly watch reports any firewall with no machine behind it.

commented

I merged main into the branch, fixed the four conflicts, and pushed (merge commit 4e6cd6986). bun x tsc --noEmit is clean. 33 tests in test/pinned-ceiling.test.ts and test/infra-page.test.ts pass, and so do 480 tests across the 58 firewall, snapshot, migration, Hetzner, droplet and machine test files. I did not run the full suite; the forge runs the whole check on the push.

I ran bun scripts/gate.ts --fix before committing, but I didn't read its output, so I can't say what it reported.

  • src/actions/pinned.ts: I kept the firewall imports from this branch and added the Restore type that main brought.
  • src/cloud/droplet.ts: digitalocean keeps firewall: digitaloceanFirewall. It also takes main's createVolume, which can restore a volume from a snapshot.
  • src/generated/migrations.ts: all three migrations are listed in order: infra-snapshot, scan-finding-excerpt, then pinned-firewall (m447 to m449). I edited the file by hand rather than regenerating it.
  • test/pinned-ceiling.test.ts: the allowed driver call names are now the snapshot ones plus ensureFirewall and removeFirewall. The count of driverOf uses is 15, which I derived from the two sides' counts rather than counting the uses directly. The test passes with it.
commented

I merged main into this branch and pushed it as 70603adbf. The only conflict was src/http/mcp/tools/infra.ts.

  • Imports: I kept firewallWant from this branch and bindBucket/readBucket from main.
  • Tool doc and description: I kept the firewall wording from this branch and the bucket wording from main. The description is now "Cloud machines and spend." The action list already included price and bind from main.

bun x tsc --noEmit printed no errors. I ran the six infra suites that cover the merge (firewall, bucket, plan, plan-apply, snapshot and talk-infra-says), and all 69 tests pass.

I did not run the wider set that scripts/fast.ts named. It would select 3,566 files, so I stopped that run and left the full check to the forge's push run.

commented

This round addresses all four of sentinel's points and is pushed as 8187a6574. The tests that cover the change pass, but I did not run the full suite; the forge's check does that on the push. tsc is clean, and the gate reported nothing beyond notes after the rewrap commit.

  1. Both doors: I disagree that a terminal entry is needed. Commits on this branch already carry No door: lines with the reason, and the new commit repeats it. A firewall is planned around an existing machine through the infra MCP tool, and the compose forms plan one machine question at a time. docs/features/infra.md says so.
  2. Dead code in src/cloud/plan.ts: I removed void l;. ledger(...) is now called bare, with a comment saying it opens the account's ledger row.
  3. DigitalOcean lookup in src/cloud/firewall.ts: digitaloceanFirewall.find now reads 200 firewalls a page, up to 25 pages. It stops at the match or a short page. A new test in test/firewall.test.ts finds forge-shop on page 2 and makes no POST, so no duplicate.
  4. test/pinned-ceiling.test.ts: I added a comment explaining that ensureFirewall and removeFirewall cannot spend money. A firewall is free, and each call only finds, makes or deletes that one firewall.

I also extended the retire test in test/infra-plan-apply.test.ts. With the firewall DELETE refused once, the forge ends up retired and keeps its firewall id fw-1, and the firewall is still at the provider. After the cloud is mended, retirePinned deletes the firewall and clears the id.

The retire step in apply counts as done once the machine is retired, even if the firewall delete failed. The test therefore checks state and the kept id, not the step result.

On the check's list, I did not run its dead-code, issue-number or llms.txt tests individually. The new code adds no unused export and no as never in a test.

commented

I merged main into the branch, resolved the four conflicts and pushed (e734dd356). bun x tsc --noEmit is clean. 105 tests pass in the infra, firewall, plan, pinned-ceiling, watch and migrations suites plus the managed-database test. I did not run the full suite, so the forge's check on the push is the first run of everything else.

  • src/generated/migrations.ts: both migrations are kept in filename order: 20261201150000-pinned-firewall is m449 and 20261201170000-managed-database is m450.
  • src/cloud/plan.ts:
    • Want is now MachineWant | FirewallWant | DatabaseWant.
    • StepKind carries firewall, database, online and bind.
    • The header comment names both kinds.
  • src/actions/infra.ts: firewallWant and planDatabase sit side by side, and the plan summary counts both firewalls and databases.
  • src/http/mcp/tools/infra.ts: the plan action accepts {firewall: name} and {database: true, …}, and the doc string lists both.

test/managed-database.test.ts needed two fixture fields, firewalls on its reads and firewall on its machine record, because both are now required.

An earlier push of this merge, 2cb973e47, had a type error in that test file because my edit to it hadn't taken. e734dd356 fixes it.

Sign in to join this conversation.

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs