| index afa7bb1d5..47eef47ba 100644 |
| --- a/docs/superpowers/specs/2026-11-12-edge-proxy-protocol-design.md |
| +++ b/docs/superpowers/specs/2026-11-12-edge-proxy-protocol-design.md |
| @@ -1,6 +1,8 @@ |
| # PROXY protocol v2 on the region HA load balancers |
| |
| -Design, 2026-11-12, **rev 5** (Astra rounds 1 to 3 applied, §12, §13 and §15. Round 3, the last, was NOT READY with one P1 in F1; its fix, the trust barrier, was **accepted without a fourth round by 8a3d302 on 2026-11-12** (§15). **APPROVED 2026-11-12** for build: Paul approved "PPv2 ... before G6"; no infra or live change without 8a3d302's GO and a #421 window. Earlier: round 2 repeated fault family F1, so under stopping rule 2 the choice went to Paul: **option A, one-way PROXY protocol, decided 2026-11-12** by agent manager 8a3d302 on Paul's standing acceptance of recommendations, Paul informed and free to override; §14). Rev 4 wrote A in; rev 5 applies round 3's P2s and proposes the barrier for its P1 (§4.7, §15). Agent manager 8a3d302 asked for it on 2026-11-12 with Paul's approval: client IP preservation off and PROXY protocol v2 on, on both target groups of each region NLB, before G6 opens the NLBs to customers. Design only; the build is a separate GO. Review budget: at most three Astra rounds (AGENTS.md stopping rules); all three rounds are spent. |
| +Design, 2026-11-12, **rev 5.1** (Astra rounds 1 to 3 applied, §12, §13 and §15. Round 3, the last, was NOT READY with one P1 in F1; its fix, the trust barrier, was **accepted without a fourth round by 8a3d302 on 2026-11-12** (§15). **APPROVED 2026-11-12** for build: Paul approved "PPv2 ... before G6"; no infra or live change without 8a3d302's GO and a #421 window. Earlier: round 2 repeated fault family F1, so under stopping rule 2 the choice went to Paul: **option A, one-way PROXY protocol, decided 2026-11-12** by agent manager 8a3d302 on Paul's standing acceptance of recommendations, Paul informed and free to override; §14). Rev 4 wrote A in; rev 5 applies round 3's P2s and proposes the barrier for its P1 (§4.7, §15). Agent manager 8a3d302 asked for it on 2026-11-12 with Paul's approval: client IP preservation off and PROXY protocol v2 on, on both target groups of each region NLB, before G6 opens the NLBs to customers. Design only; the build is a separate GO. Review budget: at most three Astra rounds (AGENTS.md stopping rules); all three rounds are spent. |
| + |
| +**Rev 5.1 (2026-11-13), build-time amendments from the whole-branch review:** §4.7 and §6.5, the barrier blocks only B steps (S1 to S2), A steps and reverify are allowed under it; §6.1 item 6, the installed guard binary; §4.5 and §6.4, per-listener counters and the edge's identity, which convergence uses; §6.5, the incident's step order. |
| |
| Line citations are to `origin/main` at ae1b8cca. AWS facts quote "Edit target group attributes for your Network Load Balancer" (docs.aws.amazon.com/elasticloadbalancing/latest/network/edit-target-group-attributes.html, read 2026-11-12) unless another page is named. |
| |
| @@ -94,6 +96,8 @@ The header's destination address and port are not used. |
| |
| Per listener and, for trusted connections, per node address, since start: `proxied`, `no_client`, `no_client_refused` (§4.6), `ignored` (untrusted header consumed), `ignored_private` (untrusted header from a private address: almost certainly an NLB node missing from the key), `marker_trusted` (§6.4), `malformed`, `timeout`. One journal line at start (`edge: proxy protocol: armed on :80 and :443, trusting 172.31.29.110,172.31.11.189`), and one throttled line every minute while armed, naming every counter. `no_client_refused` and `ignored_private` above zero also log once a minute at warning level with the peer address. The cutover reads these lines over SSM (§6.4). |
| |
| +**Rev 5.1: what `trust-status` carries.** The counters and `proxied_by_node` summed over both listeners (the metric's view, below), and `by_listener` with each listener's own counters and per-node `proxied`, keyed `"80"` and `"443"`, all from one snapshot. And `edge_instance`, a random id the edge sets once when it arms at start: the counters live exactly as long as it, so a reader that sees it change knows they started again. Convergence (§6.4) uses both: a B step's evidence is its own port's listener, and a changed `edge_instance` or any count lower than at the previous poll is a restart that fails the window. |
| + |
| **The trust-violation metric, for the whole armed lifetime.** `no_client_refused` plus `marker_trusted` is the S3 signal: in S3 every client that sends no header of its own lands in `no_client_refused` (§4.6), which on a serving target group is nearly every client, and the forgery probe's marker lands in `marker_trusted`. The agent publishes the per-minute increase of that sum as `IngressProxyTrustViolations` in the `Carlos/Host` namespace, with the `Deployment` and `Region` dimensions the clock and admission metrics already use (`internal/host/memwatch.go:53-90`, `ingress/alarms.tf:49-90`), on every armed box with `CARLOS_HOST_METRICS=cloudwatch`. The agent runs the edge in-process (`internal/host/ingressdrain.go:87-88` holds it) and reads the counters directly. One alarm in the ingress module (§8.1) fires on Maximum > 0 for one minute, missing data not breaching (unarmed boxes publish nothing). The armed prerequisite (§6.1) includes `CARLOS_HOST_METRICS=cloudwatch` on every target. |
| |
| ### 4.6 A trusted connection without a client address answers the health check only |
| @@ -106,9 +110,9 @@ In S3, ordinary clients (no header of their own) are refused loudly by this rule |
| |
| ### 4.7 The trust barrier (rev 5, accepted 2026-11-12; replaces rev 4's one-shot `close-trusted`, see §15) |
| |
| -A root command on the box, `carlos system edge trust-barrier`, raises a barrier in the edge. While it is up, a trusted connection's header grants no identity: **every** connection from a node address, whether open, still parsing its header, or accepted later, is treated as `no-client` (§4.6) once its state resolves, so it can answer the health check and nothing else. Raising the barrier sets it before it closes anything: first the flag, then it closes every open connection from a node address, pending ones included. The wrapper tracks trusted connections from accept, not from parse, for this. A connection that finishes a forged header after the flag is up is still `no-client`; a node still in S3 that sends new connections meets the same rule. Health checks keep passing, so targets stay in service, and in S0 or S1 every client connection is untrusted and served as normal. |
| +A root command on the box, `carlos system edge trust-barrier`, raises a barrier in the edge. While it is up, a trusted connection's header grants no identity: **every** connection from a node address, whether open, still parsing its header, or accepted later, is treated as `no-client` (§4.6) once its state resolves, so it can answer the health check and nothing else. Raising the barrier sets it before it closes anything: first the flag, then it closes every open connection from a node address, pending ones included, then (rev 5.1) it writes the barrier file. Containment never waits on the disk: a stalled or slow data disk delays only the file, and a write that fails leaves the barrier up in the running edge and says it is not persisted. The wrapper tracks trusted connections from accept, not from parse, for this. A connection that finishes a forged header after the flag is up is still `no-client`; a node still in S3 that sends new connections meets the same rule. Health checks keep passing, so targets stay in service, and in S0 or S1 every client connection is untrusted and served as normal. |
| |
| -The barrier is written to a file in the agent's state directory and read at edge start, so a restart does not lower it. Only `carlos system edge trust-resume` lowers it, run after the target group is verified back in S1 or S2 by the marker probe (§6.4). The step script refuses a forward step while any target's barrier is up. The commands are root CLI verbs that reach the agent the way W6's and §25's verbs do: a child that drops to the agent's user and calls the drain socket (`internal/host/hadrain_call.go`, `hadrain_socket_linux.go:23`, which admits only the agent's UID). The agent holds the edge in-process (`internal/host/ingressdrain.go:87-88`). Each reports how many connections it closed and the barrier state; the state also goes in the §4.5 journal line. |
| +The barrier is written to a file in the agent's state directory and read at edge start, so a restart does not lower it. Only `carlos system edge trust-resume` lowers it, run after the target group is verified back in S1 or S2 by the marker probe (§6.4). The step script refuses a B step (S1 to S2) while any target's barrier is up. **Rev 5.1:** A steps (S0 to S1) and `reverify` are allowed under a barrier: in S0 and S1 no client connection is trusted, so the barrier matters only once preservation goes off, and an A step under the barrier is the only way forward from an S3 incident without lowering it first (8a3d302's build-time ruling via the controller, 2026-11-12). The commands are root CLI verbs that reach the agent the way W6's and §25's verbs do: a child that drops to the agent's user and calls the drain socket (`internal/host/hadrain_call.go`, `hadrain_socket_linux.go:23`, which admits only the agent's UID). The agent holds the edge in-process (`internal/host/ingressdrain.go:87-88`). Each reports how many connections it closed and the barrier state; the state also goes in the §4.5 journal line. |
| |
| ## 5. Client IP everywhere it is used |
| |
| @@ -142,6 +146,7 @@ In this order: |
| 3. **The key.** `CARLOS_INGRESS_PROXY_SOURCES` equal to the module output (§8.1): in the region's host-env parameters, then a group roll so every member is launched with it (members write host.env only at launch, `hostenv.go:144-150`), and in each fixed box's host.env with a drained restart, as W6 delivered `CARLOS_INGRESS_TARGET_GROUPS`. Each target's journal shows the §4.5 armed line with exactly the module's addresses. |
| 4. **The group module at vN**, whose precondition accepts the new states (§8.2). A group plan with the old module would refuse once the TGs change. |
| 5. **Metrics and alarm.** `CARLOS_HOST_METRICS=cloudwatch` on every target; the module's `proxy_trust_alarm` input set, both alarms applied, in OK, and notification delivery seen (§4.5, §8.1, §8.3). |
| +6. **Rev 5.1: the installed guard binary at vN or later.** On a box with the guard armed, `/opt/carlos/system/guard/carlos` is a separate copy guard-arm installed (`internal/host/guardarm.go:149`) and application updates do not refresh it. An older one runs `guard-exec recover` with no activation check (§7.3), so with a journal open and a carlos.prev below vN it could restore that predecessor. The step script's `prereq` checks, over SSM on every target, that the file is absent or reports `ingress-proxy-v2` in `version --json`, and refuses naming the boxes otherwise. |
| |
| Arming changes nothing on the wire: until step A80 no connection carries a header, and trusted peers are only health checks, which §4.6 serves. |
| |
| @@ -197,10 +202,11 @@ The edge catches the forged marker itself: a trusted `proxied` header whose sour |
| |
| Convergence of a step, per TG port, needs all of: |
| - after A: the marker fails on **both** NLB addresses for 30 consecutive attempts (60 s); plain stays at its port's answer on both addresses (`:443`: 200 with the probe's address; `:80`: 302, not followed); |
| -- after B: the same, plus every target's counters show `proxied` rising from **both** node addresses and `no_client_refused` at 0; |
| -- all the time: `malformed`, `timeout`, `ignored_private` and `marker_trusted` at 0. |
| +- after B: the same, plus every target's counters show `proxied` rising from **both** node addresses on **the changed port's listener** (`by_listener`, §4.5; rev 5.1: after B80, `:80` traffic is no evidence for B443) and `no_client_refused` at 0; |
| +- all the time: `malformed`, `timeout`, `ignored_private` and `marker_trusted` at 0, summed and on the changed port's listener; |
| +- all the time (rev 5.1): every target's `edge_instance` as at the step's baseline, and no count lower than at the previous poll. A restart fails the window; a fresh window (`reverify`) follows once the box is back. |
| |
| -**Transition gates and maintenance rows are separate.** From the start of an attribute step until its convergence record is written, every target is healthy in both TGs (`describe-target-health` every 10 s) and no drain, restart or group roll runs. Maintenance rows (§10 rows 5 and 6) run only between steps: during one, the named target may be `unhealthy.draining` or deregistered, every other target stays healthy, and the plain probe stays at 0 errors. The all-healthy gate is back before the next attribute step starts. |
| +**Transition gates and maintenance rows are separate.** From the start of an attribute step until its convergence record is written, every target is healthy in both TGs (`describe-target-health` every 10 s) and no drain, restart or group roll runs. Rev 5.1: the step script itself watches both TGs, from just after it writes the step's intent record (before `tofu apply` starts, the continuity check's anchor) through the apply and the convergence to the record, interrupted runs included; any unhealthy target in either TG, or more than 15 s without an observation of either, fails the step. Maintenance rows (§10 rows 5 and 6) run only between steps: during one, the named target may be `unhealthy.draining` or deregistered, every other target stays healthy, and the plain probe stays at 0 errors. The all-healthy gate is back before the next attribute step starts. |
| |
| The script writes the record (times, counts, per-address results) that the next step requires. |
| |
| @@ -210,11 +216,14 @@ The script writes the record (times, counts, per-address results) that the next |
| |
| **Rollback ends at S1.** B443 then B80 back, each preservation **on**, by the step script or, in an abort, the direct command. S1 is today's client addresses through the NLB and today's collision behaviour, which is everything a rollback needs to restore; the edge stays armed and keeps ignoring the NLB's header as in S1. A80 and A443 are never reversed (§6.2, §7.3). No convergence proof is needed for S2 to S1, because every node is in S1 or S2 throughout and neither trusts a client header. |
| |
| -**S3 incident** (the alarm, any `marker_trusted`, or any `no_client_refused`): |
| +**S3 incident** (the alarm, any `marker_trusted`, or any `no_client_refused`). Rev 5.1 order: barrier, preservation on, the A step again or `reverify --incident-cleared`, verify S1, resume, B steps. |
| 1. `carlos system edge trust-barrier` (§4.7) on every target in that TG, over SSM on all of them at once. From that moment no connection from a node address carries an identity, open, pending or new, and the forged ones are closed. Health checks keep passing. |
| -2. Preservation **on** for the affected TG with the direct command (§6.3). New client connections become untrusted (S0 or S1) and are served normally behind the barrier. |
| -3. Find who turned PPv2 off. Verify the TG is in S1 with the marker probe on both addresses, then `trust-resume` on every target, then go forward with the step script (S1 to S2) in a window. |
| -4. Report to 8a3d302 with the alarm, the counters and the barrier's close counts. |
| +2. Preservation **on** for the affected TG with the direct command (§6.3). New client connections become untrusted (S0 or S1) and are served normally behind the barrier. Then the step script's `sync-tfvars` brings its tfvars file back in line with live (every step refuses until it does; it never writes S3). |
| +3. Find who turned PPv2 off. With PPv2 off (the TG is in S0), run the A step again with the step script, under the barrier (§4.7). With PPv2 already on (S1), `reverify` the A step with `--incident-cleared`. |
| +4. Verify the TG is in S1 with the marker probe on both addresses. |
| +5. `trust-resume` on every target. |
| +6. Go forward with the step script (S1 to S2, the B steps) in a window. |
| +7. Report to 8a3d302 with the alarm, the counters and the barrier's close counts. |
| |
| ### 6.6 Order across NLBs |
| |