carlos / platform Public

plan: egress allow by private CIDR (#1357)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev f1eb7b731e555801a2472d7d324b94db86863872 parent d3266e8
1 file changed, +261 −0
  • docs/superpowers/plans/2026-11-22-egress-allow-cidr.md +261 −0
diff --git a/docs/superpowers/plans/2026-11-22-egress-allow-cidr.md b/docs/superpowers/plans/2026-11-22-egress-allow-cidr.md
new file mode 100644
index 000000000..46dac014b
--- /dev/null
+++ b/docs/superpowers/plans/2026-11-22-egress-allow-cidr.md
@@ -0,0 +1,261 @@
+# Egress allow by private CIDR (#1357)
+
+Spec: docs/superpowers/specs/2026-10-21-instance-sizes-and-egress-design.md §4
+(the single-address egress allow, #328). This plan widens §4.1 from "a single
+address" to "a single address or a private prefix". All of the spec's other
+rules and rulings still apply. Issue: #1357 (amadan discuss carlos/platform).
+
+## Findings (what is there today)
+
+- One rule set, `internal/egressaddr`, is applied at the console door
+ (`Normalize`, apipolicy.go ~1047), in `apppolicy.Policy.Validate` (signing
+ and every open on a box), and by root (`instancectl.EgressAsserter.desired`,
+ egress.go ~638). Root writes `IPAddressAllow=` as full-length prefixes,
+ and `readBack`/`parseHeld` already parse prefixes (masked).
+- **Old box given a CIDR entry:** `egressaddr.Parse` refuses any `/`, so
+ `Validate` fails and the policy is `ErrUnverifiable`. `policyColsFor` then
+ fails closed with `Known: true` (apppolicy_reconcile.go ~113-140): the
+ app's whole allow list AND its size override are cleared on that box. It
+ never fails open, but it does regress the app's other entries. So CIDR
+ entries are gated behind a box version floor (Task 3).
+- **~33 minutes:** fleet boxes have no change index
+ (changeindex.go:59-61), so `PolicyCache` re-reads only on the 30-minute
+ backstop (`release.ChangeIndexBackstop`) plus up to 3 minutes of jitter
+ (apppolicy_cache.go:128). Shared boxes follow the change index and apply
+ a change within seconds. A serial-triggered fleet full pass does not
+ re-read an already cached policy (`backstopDue` waits for `c.next`).
+- **"publish no address list":** `apps_policy.go:48`. Grant-time
+ checking reads box addresses from edges files
+ (`control/edges/<box>.json`, `addrs`), and only platform boxes write edges
+ files (edgesfile.go:1267). So for bucketless fleet boxes the warning is
+ accurate and by design (spec §4.2), but its wording reads like a fault.
+ Root on every box, fleet boxes included, still refuses an entry that is
+ one of its own addresses.
+
+## Decisions
+
+1. **Entry forms.** A single address (as today) or a prefix `a.b.c.d/n` /
+ `x::/n`. IPv6 prefixes are accepted, because IPv6 singles are accepted.
+2. **Stored form.** A full-length prefix (`/32`, `/128`) is stored as the
+ bare address, so a policy with singles only is byte-identical to today
+ and old boxes keep reading it. Other prefixes are stored as
+ `netip.Prefix.String()`.
+3. **Host bits set is refused, not normalized** (`10.0.64.5/20`): the
+ operator may have meant the single address. The refusal names the
+ canonical prefix (`10.0.64.0/20`).
+4. **Minimum prefix length:** /16 for IPv4 and /48 for IPv6. /16 is the
+ largest CIDR block an AWS VPC can have, and a common VPC size elsewhere,
+ so one entry covers at most one whole VPC and never spans `10.0.0.0/8`
+ or `172.16.0.0/12`. /48 is a ULA site prefix (RFC 4193), so one entry
+ never spans sites. A wider prefix is refused and names the limit.
+5. **Private ranges only, exactly as today.** A prefix is allowed when its
+ whole range lies inside one `FenceDeny` range and it overlaps none of
+ the refused classes: loopback, unspecified, link-local, both metadata
+ addresses, multicast, the reserved ranges and NAT64. Equivalently,
+ every address in it would pass `Allowed`, and the check is done on
+ prefixes, not by enumeration. Example: `fd00:ec2::/48` is refused
+ because it holds the v6 metadata address.
+6. **Count limit unchanged:** at most `MaxAllow` (8) entries. Each
+ prefix counts as one entry. Exact duplicates collapse, and an entry
+ inside another entry is kept as written (no subsumption). The sort
+ order is address, then prefix length, so `10.0.64.0/20` comes before
+ `10.0.64.0`.
+7. **Root accepts the prefix exactly.** Root writes `IPAddressAllow=` with
+ the entry's own prefix: no widening, and no masking of a stored
+ host-bits entry (`Validate` already refused those). An entry
+ **overlapping** any of the box's own addresses is refused on that box
+ with a reason. `IPAddressAllow` beats `IPAddressDeny` in systemd, so
+ the box's address cannot be carved out of the prefix. The equality rule
+ for singles becomes an overlap rule.
+8. **Console grant check and live report:** an added prefix is refused if
+ any published box address lies inside it, naming the box. This is the
+ §4.2 rule with "equals" widened to "contains". The live report and
+ `apps show`'s `!` work the same way.
+9. **Version floor.** `release.EgressPrefixFloor = v0.43.0` (the next
+ minor; v0.42.1 is the latest tag). A grant that adds a non-full-length
+ prefix is refused with a 409 while any fresh heartbeat box of the
+ deployment reports a release below the floor or no release. This
+ follows the `teamFloorRefusal` pattern in internal/console/teamfloor.go
+ and is not scoped to the app's placement, because an app can move to
+ any box. If the release ships under another number, the floor constant
+ moves with it. A floor set too high only refuses prefixes for longer
+ (fail safe).
+10. **Propagation is documented, not shortened, in this slice.**
+ Shortening it means a fleet full pass that re-lists
+ `control/app-policy/` whenever the serial moves. Serial bumps follow
+ any console activity, so that adds S3 requests on every fleet box, which
+ ruling 11 forbids without a budget. The bound (about 33 minutes on
+ fleet boxes, seconds on shared boxes) is already in docs/site/cli.md.
+ The proposal goes on #1357.
+11. **Fleet-box warning reworded**, not removed. It names the boxes as
+ fleet boxes that do not publish their addresses, and says that root
+ on each of those boxes still refuses an entry holding the box's own
+ address.
+12. **Hostname entries:** not built here. A proposal goes on #1357.
+
+## Global constraints
+
+- `internal/egressaddr` stays a pure leaf package (no platform imports).
+- No new per-box polling, no new S3 reads on a timer.
+- Policies with singles only stay byte-identical (stored form, signed wire,
+ registry column, the `IPAddressAllow=` line root writes).
+- User-facing text: no em dashes, curly quotes in docs prose, plain and
+ short. Refusals are lower-case fragments in the existing `egressaddr`
+ style (`"%q is ..."`). Copy gets a Luna pass after Task 3.
+- No tenant names; examples use `shop`, `10.0.64.0/20`, `fd00:5::/64`.
+- Root-read code changes (instancectl) need a census card
+ (`make census-card` / `census-propose`) if `TestPlan14RootReadCensus`
+ moves.
+- Local tests: targeted `-run` on changed packages only. Also cross-build
+ `GOOS=darwin` and `GOOS=windows` for `./...`-touched packages.
+
+## Task 1: egressaddr prefixes
+
+Files: internal/egressaddr/egressaddr.go, egressaddr_test.go.
+
+- Add `ParseEntry(s string) (netip.Prefix, error)`. A bare address becomes
+ its full-length prefix, with an IPv4-mapped address unmapped. `a/n` is
+ parsed with `netip.ParsePrefix`. A mapped-v4 prefix is refused as
+ not-an-address, to keep it simple. Ports, zones and empty input are
+ refused as today. Host bits set gives `"%q has host bits set. write it
+ as %s"`. Keep `Parse` (single addresses) for existing callers that still
+ need an address.
+- Add `AllowedPrefix(p netip.Prefix) error`:
+ - Full-length → `Allowed(p.Addr())` (same messages as today).
+ - Otherwise:
+ - min length (decision 4): `"%s is wider than /%d. allow at most a /%d"`;
+ - containment in a `FenceDeny` range, else public or partly public:
+ `"%s is not wholly inside a private range"`;
+ - no overlap with loopback, multicast, link-local
+ (`169.254.0.0/16`, `fe80::/10`), the metadata addresses, reserved
+ or NAT64: reuse the existing messages with the prefix in place of
+ the address. Loopback and multicast are already caught by the
+ length plus containment rules, but test them anyway.
+- `Normalize` works on entries (decisions 2, 3 and 6), and stays the one
+ door function.
+- Constants: `MinPrefixV4 = 16`, `MinPrefixV6 = 48`.
+- `Parse` stays the single-address reader and keeps refusing a `/`
+ (Task 2's old-box witness pins that). Update the package doc for
+ ranges.
+- **Witness: table tests.**
+ - Accepted: `10.0.64.0/20`, `10.0.0.0/16`, `172.16.0.0/16`,
+ `192.168.0.0/16`, `100.64.0.0/16`, `fd00:5::/64`, `fd00:5::/48`,
+ `10.0.5.20/32` → stored `10.0.5.20`, `fd00:5::20/128` →
+ `fd00:5::20`.
+ - Refused, each with its message: `10.0.0.0/8`, `10.0.0.0/15`,
+ `fd00::/47`, `10.0.64.5/20`, `169.254.0.0/16`,
+ `169.254.169.0/24`, `fd00:ec2::/48`, `64:ff9b::/96`,
+ `198.18.0.0/16`, `8.8.8.0/24`, `0.0.0.0/16`, `224.0.0.0/16`,
+ `fe80::/64`, `10.0.64.0/20:5432`, `::ffff:10.0.0.0/112`.
+ - Sort and dedup: `10.0.64.0`, `10.0.64.0/20`, `10.0.64.0/20` →
+ `[10.0.64.0/20 10.0.64.0]`.
+ - The count limit holds with prefixes.
+ - A fuzz-free property test: for each accepted prefix, its first and last
+ addresses pass `Allowed`.
+
+## Task 2: the box accepts prefixes exactly
+
+Files:
+- internal/apppolicy/apppolicy.go (Validate uses `ParseEntry`,
+ `AllowedPrefix` and the decision-6 order);
+- internal/instancectl/egress.go (`desired`);
+- internal/instancectl/localaddrs.go (an overlap helper);
+- callers of `egressaddr.Parse` in internal/console/egressfleet.go only as
+ far as compiling needs (the logic is Task 3).
+
+- `desired`:
+ - parse with `ParseEntry`, check with `AllowedPrefix`, and dedup by
+ prefix;
+ - refuse an entry overlapping any local prefix
+ (`"%s: holds an address of this box (%s)"`, with the existing
+ single-address text unchanged for full-length entries);
+ - write the prefix as is.
+- The `want`/read-back comparison already uses masked prefixes. Confirm
+ that systemd's read-back of `10.0.64.0/20` parses equal (a unit test
+ with the fake systemctl).
+- **Witnesses:**
+ - (a) `desired` table: a prefix is written verbatim, a prefix
+ overlapping a local /32 is refused, singles are unchanged, and the
+ count limit applies.
+ - (b) Assert writes `IPAddressAllow=10.0.64.0/20` through the fake
+ systemctl. A read-back of `10.0.64.0/20` counts as in force, not
+ failing.
+ - (c) **old-box safety:** a test in internal/provision that pins the
+ old-box path. A policy whose `Validate` fails (a bad entry) gives
+ fail-closed columns, with an empty allow, never a wider one. Also
+ assert in egressaddr's tests that `Parse` (the old single-address
+ reader, still used by old boxes' code shape) refuses every prefix
+ form. The floor in Task 3 is the guard that stops it happening.
+ - (d) **production-wired:** a registry egress column `10.0.64.0/20
+ 10.0.5.20` goes through the real egress source (internal/host
+ egress_source.go) into the asserter, which writes exactly those two
+ prefixes. Use the existing wiring test's harness
+ (egress_claim_wiring_test.go or egress_source_test.go).
+- Run the census test (`go test ./internal/provision -run
+ TestPlan14RootReadCensus`). If it moves, produce the card per AGENTS.md
+ ("The census: an approval, not a decision").
+
+## Task 3: console door, fleet check, floor, copy
+
+Files:
+- internal/console/egressfleet.go;
+- internal/console/apipolicy.go;
+- internal/console/teamfloor.go (or a new egressfloor.go);
+- internal/release/layoutintent.go (the floor);
+- apps_policy.go, plus the CLI help for `--egress-allow`;
+- docs/site/cli.md (~262).
+
+- `grantAdded` returns added prefixes. The check refuses a prefix that
+ contains any published box address, naming the box and the address.
+ `egressFleetHeldMsg` gets the prefix wording when the entry is a
+ prefix.
+- The live report and `apps show` `!` work on prefix containment.
+- Floor (decision 9): refuse with 409 using the teamfloor phrasing
+ pattern:
+ - `"box %s runs %s. allowing a range needs v%s or later on every box. single addresses are unaffected"`;
+ - a heartbeat read failure → 503, as in teamfloor.
+ - Only grants that add a non-full-length entry are gated. Revokes and
+ singles never are.
+- Fleet warning reworded (decision 11).
+- CLI help and the docs paragraph: entries may be a private range with at
+ least /16 (IPv4) or /48 (IPv6). Host bits refused. Count 8. The floor.
+ The box refuses a range that holds one of its own addresses. The
+ propagation bound stays.
+- **Witnesses:** console tests.
+ - A grant of a prefix holding an edges-file address → 409 naming the
+ box.
+ - A prefix with no conflicts → 200.
+ - Floor: one fresh box at v0.42.1 → 409. All at v0.43.0 → 200. A
+ single address with an old box → 200.
+ - The report flags a prefix that later contains a box address.
+
+## Task 4: kernel witness (root runner)
+
+File: internal/host/egress_kernel_rootrunner_linux_test.go (or a sibling
+`egress_prefix_rootrunner_linux_test.go`), `//go:build linux &&
+rootrunner`.
+
+- Use the kernel proof's dummy-link harness:
+ - put two listeners on a dummy link, one inside `10.250.64.0/20`
+ (`10.250.64.10`) and one outside it but in the same /16
+ (`10.250.80.10`);
+ - give a tenant in a child unit with the template's `IPAddressDeny=`
+ a slice allow of `10.250.64.0/20`, written by the real asserter;
+ - the tenant reaches the inside listener and is refused at the outside
+ one;
+ - revoke, and the inside listener is refused as well.
+- Log one `verdict:` line per question.
+- The controller runs it on the root runner (memory root-runner) and
+ records the run id in the ledger.
+
+## After the tasks (controller)
+
+- Luna copy pass over the new strings and the docs paragraph, then apply it.
+- Post on #1357:
+ - progress;
+ - the propagation finding and proposal (decision 10);
+ - the warning explanation;
+ - the hostname proposal.
+- Final whole-branch review by Astra (max three rounds), CI, squash-merge
+ with amadan.
+- Tell paseo 09cca118 and 8a3d302 the SHA. The release waits for Paul's GO.