ppv2: approved operator copy; prereq checks both slots under the guard
Applies the PPv2 operator text review (59 strings, approved without edits). Three strings differed from the code: the edge's no-route refusal now names CARLOS_INGRESS_PROXY_SOURCES, and the prereq usage paragraph and guard refusal follow the new check. ppv2-step.py prereq: on a box with the guard installed, check that both /opt/carlos/carlos and /opt/carlos/carlos.prev report ingress-proxy-v2, instead of the guard binary itself. An old guard's recovery can only pick one of those two, and carlos.prev only ever becomes the outgoing current binary, so once both are vN or later the guard binary stops mattering. Refuses per box and slot; an absent guard still passes. Runbook prerequisite 6 and the prereq paragraph say the same.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
5 files changed,
+134
−38
docs/region-ha-runbook.md+2 −2internal/host/edgetrust.go+2 −2internal/host/edgetrust_test.go+1 −1scripts/ppv2-step.py+62 −25scripts/ppv2_step_test.py+67 −8
CI cancelled — superseded by a newer push — run details
Intent
Human
<task-notification> <task-id>bv0qnkkay</task-id> <tool-use-id>toolu_018So8qgrwAmMdxDLEsnbpcN</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/a0025b5e-60c7-44a1-8f2f-0568a41826c3/tasks/bv0qnkkay.output</output-file> <status>completed</status> <summary>Background command "Add a real-shell guard check test and run the suite" completed (exit code 0)</summary> </task-notification>
diff --git a/docs/region-ha-runbook.md b/docs/region-ha-runbook.md| index 739ad3973..ed1107d1e 100644 |
| --- a/docs/region-ha-runbook.md |
| +++ b/docs/region-ha-runbook.md |
| @@ -366,9 +366,9 @@ In this order: |
| 3. `CARLOS_INGRESS_PROXY_SOURCES` equals the module's output, in the region's host-env parameters (then a group roll, because members write host.env only at launch) and in each fixed box's host.env (drained restart). Every target's journal shows `edge: proxy protocol: armed on :80 and :443, trusting ...` with exactly the module's addresses. |
| 4. The group module is at vN. |
| 5. `CARLOS_HOST_METRICS=cloudwatch` on every target, the module's `proxy_trust_alarm` set, both alarms applied and in OK, and a notification seen arriving. |
| -6. On a box with the guard armed, the installed guard binary `/opt/carlos/system/guard/carlos` is vN or later. guard-arm copies it once, and application updates do not refresh it. An older one runs `guard-exec recover` with no PPv2 check, so with a journal open it could restore a predecessor below vN. A box without the guard has no such file. |
| +6. On a box with the guard armed, both `/opt/carlos/carlos` and `/opt/carlos/carlos.prev` report `ingress-proxy-v2` (`<binary> version --json`) before you publish the key. The guard binary `/opt/carlos/system/guard/carlos` is copied once by guard-arm and never refreshed by application updates, and an old one's recovery can fall back to `carlos.prev` without a PROXY protocol check. Once both slots are vN or later, anything it can fall back to carries the check. A box whose `carlos.prev` is older gets one more apply of a release at vN or later, which makes the outgoing vN binary its `carlos.prev`; then check again. A box without the guard has no guard binary and passes. |
| -`prereq` checks only the automated part: both target groups in S0, every target armed with the NLB's node addresses, the barrier down, the trust alarm OK, and item 6 on every target. For item 6 it runs the installed guard binary's `version --json` over SSM and refuses, naming the boxes, unless the binary is absent or reports `ingress-proxy-v2`. It writes `prereq.json`, including the NLB's public addresses, which the probes must target. Items 1, 2 and 4 and a delivered notification stay manual. |
| +`prereq` checks only the automated part: both target groups in S0, every target armed with the NLB's node addresses, the barrier down, the trust alarm OK, and item 6 on every target. For item 6 it checks over SSM whether the guard binary exists and, where it does, runs `version --json` on both slots, refusing and naming the box and the slot for each one that does not report `ingress-proxy-v2`. It writes `prereq.json`, including the NLB's public addresses, which the probes must target. Items 1, 2 and 4 and a delivered notification stay manual. |
| ``` |
| python3 scripts/ppv2-step.py prereq --nlb-arn <nlb> --tg-arn-80 <tg80> --tg-arn-443 <tg443> \ |
diff --git a/internal/host/edgetrust.go b/internal/host/edgetrust.go| index 580a1c9d0..b2b38612f 100644 |
| --- a/internal/host/edgetrust.go |
| +++ b/internal/host/edgetrust.go |
| @@ -513,11 +513,11 @@ func (cmd edgeTrustCommand) run(ctx context.Context, args []string, out, stderr |
| case r.NoRoute: |
| // A socket without the routes: a box not armed (whose socket |
| // serves other verbs), or an agent older than the routes or not |
| - // restarted since the key was set. host.env tells which. |
| + // restarted since CARLOS_INGRESS_PROXY_SOURCES was set. host.env tells which. |
| if getenv, err := cmd.hostEnv(); err == nil && !proxySourcesSet(getenv) { |
| return fail(2, errEdgeNotArmed.Error()) |
| } |
| - return fail(1, "the agent does not serve the trust routes: an older release, or not restarted since the key was set") |
| + return fail(1, "the agent does not serve the trust routes: an older release, or not restarted since CARLOS_INGRESS_PROXY_SOURCES was set") |
| case r.Error != "": |
| return fail(1, oneLine(r.Error)) |
| } |
diff --git a/internal/host/edgetrust_test.go b/internal/host/edgetrust_test.go| index a9fa77579..fe68f67ca 100644 |
| --- a/internal/host/edgetrust_test.go |
| +++ b/internal/host/edgetrust_test.go |
| @@ -502,7 +502,7 @@ func TestEdgeTrustVerbAnswers(t *testing.T) { |
| {"no socket, host.env unarmed", drainCallResult{V: 1, AgentDown: true, Error: "dial"}, nil, "", 0, []string{"trust-status"}, 2, "", "edge: this box is not armed for PROXY protocol\n"}, |
| {"no socket, host.env armed", drainCallResult{V: 1, AgentDown: true, Error: "dial"}, nil, "172.31.29.110", 0, []string{"trust-barrier"}, 1, "", "edge: the agent's drain socket is not answering\n"}, |
| {"no route, host.env unarmed", drainCallResult{V: 1, NoRoute: true, Error: "404"}, nil, "", 0, []string{"trust-barrier"}, 2, "", "edge: this box is not armed for PROXY protocol\n"}, |
| - {"no route, host.env armed", drainCallResult{V: 1, NoRoute: true, Error: "404"}, nil, "172.31.29.110", 0, []string{"trust-status"}, 1, "", "edge: the agent does not serve the trust routes: an older release, or not restarted since the key was set\n"}, |
| + {"no route, host.env armed", drainCallResult{V: 1, NoRoute: true, Error: "404"}, nil, "172.31.29.110", 0, []string{"trust-status"}, 1, "", "edge: the agent does not serve the trust routes: an older release, or not restarted since CARLOS_INGRESS_PROXY_SOURCES was set\n"}, |
| {"agent error", drainCallResult{V: 1, Error: "edge: write trust barrier: disk\nfull"}, nil, "", 0, []string{"trust-barrier"}, 1, "", "edge: edge: write trust barrier: disk full\n"}, |
| {"child failed", drainCallResult{}, errors.New("the drain call failed"), "", 0, []string{"trust-barrier"}, 1, "", "edge: the drain call failed\n"}, |
| {"no answer", drainCallResult{V: 1}, nil, "", 0, []string{"trust-status"}, 1, "", "edge: the agent answered nothing usable\n"}, |
diff --git a/scripts/ppv2-step.py b/scripts/ppv2-step.py| index 79e7c1478..fa9ee6819 100755 |
| --- a/scripts/ppv2-step.py |
| +++ b/scripts/ppv2-step.py |
| @@ -15,11 +15,12 @@ them changes PPv2 while preservation is off, so no node can pass through S3. |
| prereq the automated part of the prerequisites (spec 6.1): both target |
| groups in S0, every target armed with the NLB's node addresses, |
| - barrier down, the trust alarm OK, and on every target the |
| - installed guard binary (/opt/carlos/system/guard/carlos) absent |
| - or reporting ingress-proxy-v2. Writes prereq.json with the NLB's |
| - public addresses. Versions, the bootstrap object hash and a |
| - delivered alarm notification are still checked by hand. |
| + barrier down, the trust alarm OK, and on every box with the |
| + guard installed, both /opt/carlos/carlos and /opt/carlos/carlos.prev |
| + reporting ingress-proxy-v2. Writes prereq.json with the NLB's |
| + public addresses. Versions, the bootstrap object hash, the group |
| + module version and a delivered alarm notification are still |
| + checked by hand. |
| apply makes one step on one target group through a targeted tofu plan, |
| writes <step>-applied.json, then goes straight into convergence: |
| it polls target health in BOTH target groups every 10 s, from |
| @@ -117,10 +118,20 @@ TRUST_STATUS = '/opt/carlos/carlos system edge trust-status' |
| LISTENERS = ('80', '443') |
| TRUST_KEYS = {'armed', 'barrier', 'edge_instance', 'counters', 'proxied_by_node', 'by_listener'} |
| # The guard binary guard-arm installs; app updates do not refresh it, and an |
| -# old one's `guard-exec recover` has no PPv2 gate (spec 6.1). |
| +# old one's `guard-exec recover` can run /opt/carlos/carlos.prev without a |
| +# PPv2 gate (spec 6.1). carlos.prev only ever stays as it is or becomes the |
| +# outgoing current binary, and the current binary cannot go below vN on an |
| +# armed box. So once both slots report the feature, whatever an old guard |
| +# picks carries the full activation guard, and the guard binary itself stops |
| +# mattering. On a box with the guard installed, prereq checks both slots. |
| GUARD_BINARY = '/opt/carlos/system/guard/carlos' |
| GUARD_ABSENT = 'ppv2-step: guard binary absent' |
| -GUARD_CHECK = (f'g={GUARD_BINARY}; if [ -e "$g" ] || [ -L "$g" ]; then "$g" version --json; ' |
| +GUARD_SLOTS = ('/opt/carlos/carlos', '/opt/carlos/carlos.prev') |
| +GUARD_SLOT_MARK = 'ppv2-step: slot ' |
| +GUARD_SLOT_EXIT = 'ppv2-step: exit ' |
| +GUARD_CHECK = (f'g={GUARD_BINARY}; if [ -e "$g" ] || [ -L "$g" ]; then ' |
| + f'for b in {" ".join(GUARD_SLOTS)}; do echo "{GUARD_SLOT_MARK}$b"; "$b" version --json 2>&1; ' |
| + f'rc=$?; echo; echo "{GUARD_SLOT_EXIT}$rc"; done; ' |
| f"else echo '{GUARD_ABSENT}'; fi") |
| FEATURE = 'ingress-proxy-v2' |
| ARMED_LINE = 'edge: proxy protocol: armed on' |
| @@ -1511,14 +1522,12 @@ def cmd_prereq(args, cloud): |
| reasons.append(f'{iid}: no armed line in the carlos-edge journal') |
| elif sorted(match.group(1).split(',')) != private: |
| reasons.append(f"{iid} trusts {match.group(1)}, not the NLB's node addresses {','.join(private)}") |
| - # The installed guard binary: guard-arm copies it, app updates do not |
| - # refresh it, and an old one's guard-exec recover has no PPv2 gate. |
| + # On a box with the guard installed, both slots an old guard binary |
| + # can run must report the feature (GUARD_SLOTS). |
| guards = {} |
| for iid, (code, stdout, stderr) in cloud.ssm(targets, GUARD_CHECK).items(): |
| - guards[iid] = one_line(stdout or stderr)[:300] |
| - reason = guard_refusal(iid, code, stdout, stderr) |
| - if reason: |
| - reasons.append(reason) |
| + guards[iid] = one_line(stdout or stderr)[:600] |
| + reasons.extend(guard_refusals(iid, code, stdout, stderr)) |
| alarms = cloud.aws('cloudwatch', 'describe-alarms', '--alarm-names', args.alarm).get('MetricAlarms') or [] |
| alarm = [a for a in alarms if a.get('AlarmName') == args.alarm] |
| if not alarm: |
| @@ -1543,20 +1552,48 @@ def cmd_prereq(args, cloud): |
| return 1 |
| -def guard_refusal(iid, code, stdout, stderr): |
| - """Why the installed guard binary on iid would let a pre-vN predecessor |
| - run (it does not report ingress-proxy-v2), or None (absent, or it does).""" |
| +def guard_slots(stdout): |
| + """GUARD_CHECK's answer on a box with the guard installed: each slot's |
| + (output, exit code), the code None when its exit line is missing.""" |
| + slots, current, lines = {}, None, [] |
| + for line in (stdout or '').splitlines() + [GUARD_SLOT_MARK]: |
| + if line.startswith(GUARD_SLOT_MARK): |
| + if current is not None: |
| + code = None |
| + while lines and not lines[-1].strip(): |
| + lines.pop() |
| + if lines and lines[-1].startswith(GUARD_SLOT_EXIT): |
| + rc = lines.pop()[len(GUARD_SLOT_EXIT):].strip() |
| + code = int(rc) if rc.isdigit() else None |
| + slots[current] = ('\n'.join(lines).strip(), code) |
| + current, lines = line[len(GUARD_SLOT_MARK):].strip(), [] |
| + elif current is not None: |
| + lines.append(line) |
| + return slots |
| + |
| + |
| +def guard_refusals(iid, code, stdout, stderr): |
| + """Why iid's guard could fall back to a binary below vN: one reason per |
| + slot in GUARD_SLOTS that does not report ingress-proxy-v2; empty when the |
| + guard is absent or both slots report it.""" |
| text = (stdout or '').strip() |
| if code == 0 and text == GUARD_ABSENT: |
| - return None |
| - if code == 0: |
| - doc = first_json(text, 'features') |
| - if doc and isinstance(doc.get('features'), list) and FEATURE in doc['features']: |
| - return None |
| - said = one_line(text or stderr)[:200] or f'exit {code}' |
| - return (f'{iid}: the installed guard binary {GUARD_BINARY} does not report {FEATURE} ({said}); ' |
| - 'app updates do not refresh it, so its guard-exec recover has no PPv2 gate. Bring it to vN or later ' |
| - 'on this box before the key is published') |
| + return [] |
| + slots = guard_slots(stdout) if code == 0 else {} |
| + reasons = [] |
| + for slot in GUARD_SLOTS: |
| + out, rc = slots.get(slot, ('', None)) |
| + if rc == 0: |
| + doc = first_json(out, 'features') |
| + if doc and isinstance(doc.get('features'), list) and FEATURE in doc['features']: |
| + continue |
| + said = one_line(out)[:200] or (f'exit {rc}' if rc is not None else |
| + one_line(text or stderr)[:200] or f'exit {code}') |
| + reasons.append(f'{iid}: this box has the guard installed, and its {slot} does not report {FEATURE} ' |
| + f"({said}). The guard's recovery can fall back to that binary without a PROXY protocol " |
| + 'check. Apply a release at vN or later once more so both /opt/carlos/carlos and ' |
| + '/opt/carlos/carlos.prev are vN or later, then run prereq again') |
| + return reasons |
| def cmd_sync_tfvars(args, cloud): |
diff --git a/scripts/ppv2_step_test.py b/scripts/ppv2_step_test.py| index aaee2062e..b501dd181 100644 |
| --- a/scripts/ppv2_step_test.py |
| +++ b/scripts/ppv2_step_test.py |
| @@ -38,6 +38,8 @@ SOURCES = ['172.31.11.189', '172.31.29.110'] |
| PUBLIC = ['54.77.110.223', '54.77.110.224'] |
| INTERFACES = [{'private': SOURCES[0], 'public': PUBLIC[0]}, {'private': SOURCES[1], 'public': PUBLIC[1]}] |
| ALARM = 'carlos-dev-ie-proxy-trust' |
| +CURRENT, PREV = '/opt/carlos/carlos', '/opt/carlos/carlos.prev' |
| +NEW_BINARY = '{"version":"v0.35.0","features":["ingress-proxy-v2"]}' |
| APPLIED_AT = '2026-11-12T10:00:00.000000Z' |
| STATES = {'S0': ('true', 'false'), 'S1': ('true', 'true'), 'S2': ('false', 'true'), 'S3': ('false', 'false')} |
| EXPECT = {'A': 's1', 'B': 's2', 'R': 's1'} |
| @@ -100,7 +102,14 @@ def invocation(iid, text): |
| if 'journalctl' in text: |
| return [iid, 'Success', 0, world['journal'][iid] + '\n'] |
| if 'system/guard/carlos' in text: |
| - return [iid, 'Success', 0, world.get('guard', {}).get(iid, 'ppv2-step: guard binary absent') + '\n'] |
| + slots = world.get('guard', {}).get(iid) |
| + if slots is None: |
| + return [iid, 'Success', 0, 'ppv2-step: guard binary absent\n'] |
| + out = '' |
| + for slot in ('/opt/carlos/carlos', '/opt/carlos/carlos.prev'): |
| + said, rc = slots[slot] |
| + out += f'ppv2-step: slot {slot}\n{said}\n\nppv2-step: exit {rc}\n' |
| + return [iid, 'Success', 0, out] |
| return [iid, 'Failed', 1, MARK + 'unknown command'] |
| if name == 'aws': |
| @@ -1827,9 +1836,9 @@ class PrereqTests(Harness): |
| and 'system/guard/carlos' in json.dumps(c['args'])] |
| self.assertEqual(1, len(guard_checks)) |
| self.assertEqual(sorted(TARGETS), sorted(guard_checks[0]['instances'])) |
| - # A guard binary that reports the feature passes. |
| + # A guard installed with both slots reporting the feature passes. |
| self.setUp() |
| - self.world['guard'] = {t: '{"version":"v0.35.0","features":["ingress-proxy-v2"]}' for t in TARGETS} |
| + self.world['guard'] = {t: {CURRENT: (NEW_BINARY, 0), PREV: (NEW_BINARY, 0)} for t in TARGETS} |
| self.run_prereq(expect=0) |
| cases = { |
| 'TG not in S0': (lambda: self.live({'80': 'S1', '443': 'S0'}), 'S1'), |
| @@ -1848,11 +1857,19 @@ class PrereqTests(Harness): |
| "are not the NLB's node addresses"), |
| 'no public address': (lambda: self.world['interfaces'][1].pop('public'), 'no public address'), |
| 'no interfaces': (lambda: self.world.update(nlb_suffix='net/other/1'), 'no network interfaces'), |
| - # W12: an installed guard binary older than the PPv2 gate. |
| - 'old guard binary': (lambda: self.world.update(guard={TARGETS[1]: 'carlos v0.34.49'}), |
| - TARGETS[1] + ': the installed guard binary /opt/carlos/system/guard/carlos does not report'), |
| - 'guard without the feature': (lambda: self.world.update( |
| - guard={TARGETS[0]: '{"version":"v0.35.0","features":[]}'}), TARGETS[0] + ': the installed guard binary'), |
| + # W12: with the guard installed, an old guard binary can fall |
| + # back to carlos.prev, so both slots must report the feature. |
| + 'guard, old carlos.prev': (lambda: self.world.update( |
| + guard={TARGETS[1]: {CURRENT: (NEW_BINARY, 0), PREV: ('{"version":"v0.34.49","features":[]}', 0)}}), |
| + TARGETS[1] + ': this box has the guard installed, and its /opt/carlos/carlos.prev does not report ' |
| + 'ingress-proxy-v2 ({"version":"v0.34.49","features":[]})'), |
| + 'guard, carlos.prev missing': (lambda: self.world.update( |
| + guard={TARGETS[0]: {CURRENT: (NEW_BINARY, 0), PREV: ('', 127)}}), |
| + TARGETS[0] + ': this box has the guard installed, and its /opt/carlos/carlos.prev does not report ' |
| + 'ingress-proxy-v2 (exit 127)'), |
| + 'guard, current without the feature': (lambda: self.world.update( |
| + guard={TARGETS[0]: {CURRENT: ('carlos v0.34.49', 2), PREV: (NEW_BINARY, 0)}}), |
| + TARGETS[0] + ': this box has the guard installed, and its /opt/carlos/carlos does not report'), |
| } |
| for name, (fault, text) in cases.items(): |
| with self.subTest(case=name): |
| @@ -1866,5 +1883,47 @@ class PrereqTests(Harness): |
| self.assertFalse(record['passed']) |
| +class GuardCheckTests(unittest.TestCase): |
| + """GUARD_CHECK run by a real sh against fake binaries, its output read |
| + back by guard_refusals: the same text SSM would carry.""" |
| + |
| + def run_check(self, binaries, guard=True): |
| + m = load_script() |
| + with tempfile.TemporaryDirectory() as d: |
| + root = Path(d) |
| + for slot, body in binaries.items(): |
| + path = root / slot.lstrip('/') |
| + path.parent.mkdir(parents=True, exist_ok=True) |
| + path.write_text('#!/bin/sh\n' + body + '\n') |
| + path.chmod(0o755) |
| + if guard: |
| + g = root / m.GUARD_BINARY.lstrip('/') |
| + g.parent.mkdir(parents=True, exist_ok=True) |
| + g.write_text('') |
| + script = m.GUARD_CHECK.replace('/opt/carlos/', str(root) + '/opt/carlos/') |
| + r = subprocess.run(['sh', '-c', script], capture_output=True, text=True) |
| + out = r.stdout.replace(str(root), '') |
| + return m.guard_refusals(TARGETS[0], r.returncode, out, r.stderr) |
| + |
| + def test_slots(self): |
| + new = "echo '" + NEW_BINARY + "'" |
| + old = """echo '{"version":"v0.34.49","features":[]}'""" |
| + self.assertEqual([], self.run_check({}, guard=False)) |
| + self.assertEqual([], self.run_check({CURRENT: new, PREV: new})) |
| + reasons = self.run_check({CURRENT: new, PREV: old}) |
| + self.assertEqual(1, len(reasons)) |
| + self.assertIn(f'its {PREV} does not report ingress-proxy-v2 ({{"version":"v0.34.49","features":[]}}). ' |
| + "The guard's recovery can fall back", reasons[0]) |
| + reasons = self.run_check({CURRENT: new}) |
| + self.assertEqual(1, len(reasons)) |
| + self.assertIn(f'its {PREV} does not report', reasons[0]) |
| + # A binary that prints the feature but fails is not trusted. |
| + reasons = self.run_check({CURRENT: new + '; exit 3', PREV: new}) |
| + self.assertEqual(1, len(reasons)) |
| + self.assertIn(f'its {CURRENT} does not report', reasons[0]) |
| + self.assertEqual(2, len(self.run_check({CURRENT: old, PREV: 'exit 1'}))) |
| + self.assertIn('(exit 1)', self.run_check({CURRENT: new, PREV: 'exit 1'})[0]) |
| + |
| + |
| if __name__ == '__main__': |
| unittest.main() |