carlos / platform Public

ppv2-step: guard slot answers cannot be forged by a binary's output

Astra P1 (one scoped round): a slot binary could print a fake exit line
and slot marker, so its own output answered for its exit status. Each
slot now comes back as one line, mark, slot, exit code and its output
in base64, and the answer must be exactly both slots in order or both
refuse. The reproducer and a cross-slot forgery are in GuardCheckTests.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 765b81fca914f64061aab90213a294dd1e9881a7 parent 2edfa93
3 files changed, +55 −22
  • docs/superpowers/reviews/ASTRA-FINDINGS-ppv2-guard-slots.md +15 −0
  • scripts/ppv2-step.py +23 −20
  • scripts/ppv2_step_test.py +17 −2

CI failed — run details

Intent

Human

<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="18165bdc-1c9b-4891-8af8-b357610bcaa8"> Agent manager 8a3d302: good catch. (a): draft corrected wording for just those three strings and submit a short review on the SHARED app (cd into the review dir and run copy-review submit &lt;strings.json&gt;; if your sandbox refuses it, tell me the path and I&apos;ll submit it). Send me the link. Don&apos;t merge until it&apos;s approved. </paseo-system>

Attributed to this commit: 80.1 g CO₂e (8,180,117 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on ppv2-operator-copy, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/docs/superpowers/reviews/ASTRA-FINDINGS-ppv2-guard-slots.md b/docs/superpowers/reviews/ASTRA-FINDINGS-ppv2-guard-slots.md
new file mode 100644
index 000000000..9fd9caea4
--- /dev/null
+++ b/docs/superpowers/reviews/ASTRA-FINDINGS-ppv2-guard-slots.md
@@ -0,0 +1,15 @@
+1. **P1 fail-open — binary output can replace its actual exit status.** [scripts/ppv2-step.py:1560](/home/paulca/amadan.net/carlos/platform/.claude/worktrees/ppv2-operator-copy/scripts/ppv2-step.py:1560). If current prints the following and exits **3**, while previous reports the feature and exits 0, `guard_refusals` returns `[]`:
+
+ ```text
+ {"features":["ingress-proxy-v2"]}
+ ppv2-step: exit 0
+ ppv2-step: slot diagnostic
+ ```
+
+ The parser accepts the printed exit 0 for current and assigns its actual exit 3 to the ignored `diagnostic` slot. This breaks the requirement that each slot must successfully report the feature. Reproduced through `sh`.
+
+ **Fix:** reject unknown, duplicate, or out-of-order slot markers and require exactly both expected slots with complete exit records. Add this reproducer to `GuardCheckTests`.
+
+The targeted test could not run because the read-only sandbox prevents temporary-file creation. No files changed.
+
+**NOT READY.**
\ No newline at end of file
diff --git a/scripts/ppv2-step.py b/scripts/ppv2-step.py
index fa9ee6819..5173f320e 100755
--- a/scripts/ppv2-step.py
+++ b/scripts/ppv2-step.py
@@ -75,6 +75,7 @@ Exit codes: 0 done or passed, 1 refused or failed, 2 invalid arguments,
130 interrupted.
"""
import argparse
+import base64
from collections import namedtuple
from contextlib import contextmanager
from datetime import datetime, timezone
@@ -127,12 +128,14 @@ TRUST_KEYS = {'armed', 'barrier', 'edge_instance', 'counters', 'proxied_by_node'
GUARD_BINARY = '/opt/carlos/system/guard/carlos'
GUARD_ABSENT = 'ppv2-step: guard binary absent'
GUARD_SLOTS = ('/opt/carlos/carlos', '/opt/carlos/carlos.prev')
-GUARD_SLOT_MARK = 'ppv2-step: slot '
-GUARD_SLOT_EXIT = 'ppv2-step: exit '
+GUARD_SLOT_MARK = 'ppv2-step: slot'
+# One line per slot: the mark, the slot, its exit code and its output in
+# base64, so nothing a binary prints can pose as another slot's answer.
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'for b in {" ".join(GUARD_SLOTS)}; do out=$("$b" version --json 2>&1); rc=$?; '
+ f'echo "{GUARD_SLOT_MARK} $b $rc $(printf %s "$out" | base64 -w0)"; done; '
f"else echo '{GUARD_ABSENT}'; fi")
+GUARD_SLOT_RE = re.compile(r'^' + re.escape(GUARD_SLOT_MARK) + r' (\S+) (\d+)(?: ([A-Za-z0-9+/=]*))?$')
FEATURE = 'ingress-proxy-v2'
ARMED_LINE = 'edge: proxy protocol: armed on'
JOURNAL = "journalctl -u carlos-edge.service -o cat --no-pager | grep -F '%s' | tail -n 1" % ARMED_LINE
@@ -1554,21 +1557,21 @@ def cmd_prereq(args, cloud):
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)
+ (output, exit code), or None unless it is exactly one well-formed line
+ per slot in GUARD_SLOTS, in order, and nothing else."""
+ lines = [line for line in (stdout or '').splitlines() if line.strip()]
+ if len(lines) != len(GUARD_SLOTS):
+ return None
+ slots = {}
+ for line, slot in zip(lines, GUARD_SLOTS):
+ match = GUARD_SLOT_RE.match(line.strip())
+ if not match or match.group(1) != slot:
+ return None
+ try:
+ out = base64.b64decode(match.group(3) or '', validate=True).decode('utf-8', 'replace')
+ except ValueError:
+ return None
+ slots[slot] = (out.strip(), int(match.group(2)))
return slots
@@ -1579,7 +1582,7 @@ def guard_refusals(iid, code, stdout, stderr):
text = (stdout or '').strip()
if code == 0 and text == GUARD_ABSENT:
return []
- slots = guard_slots(stdout) if code == 0 else {}
+ slots = (guard_slots(stdout) if code == 0 else None) or {}
reasons = []
for slot in GUARD_SLOTS:
out, rc = slots.get(slot, ('', None))
diff --git a/scripts/ppv2_step_test.py b/scripts/ppv2_step_test.py
index b501dd181..56c100761 100644
--- a/scripts/ppv2_step_test.py
+++ b/scripts/ppv2_step_test.py
@@ -8,6 +8,7 @@ Two harnesses, neither reaching AWS or tofu:
Run from the repo root: python3 -m unittest scripts/ppv2_step_test.py
"""
import argparse
+import base64
import contextlib
import copy
import fcntl
@@ -49,7 +50,7 @@ TFVARS = (b'{ "ppv2_preserve_client_ip": {"80": true, "443": true},\n'
b' "ppv2_proxy_protocol_v2": {"80": false, "443": false} }\n')
FAKE = r'''
-import json, os, sys, time
+import base64, json, os, sys, time
from pathlib import Path
name = Path(sys.argv[0]).name
@@ -108,7 +109,7 @@ def invocation(iid, text):
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'
+ out += f'ppv2-step: slot {slot} {rc} {base64.b64encode(said.encode()).decode()}\n'
return [iid, 'Success', 0, out]
return [iid, 'Failed', 1, MARK + 'unknown command']
@@ -1923,6 +1924,20 @@ class GuardCheckTests(unittest.TestCase):
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])
+ # Astra P1: a binary that prints a forged exit line and slot marker
+ # must not pass with its real exit code moved elsewhere.
+ forged = "printf '%s\\n' '" + NEW_BINARY + "' 'ppv2-step: exit 0' 'ppv2-step: slot diagnostic'; exit 3"
+ reasons = self.run_check({CURRENT: forged, PREV: new})
+ self.assertEqual(1, len(reasons))
+ self.assertIn(f'its {CURRENT} does not report', reasons[0])
+ # Nor can one slot's output answer for the other slot.
+ fake_prev = 'ppv2-step: slot /opt/carlos/carlos.prev 0 ' + base64.b64encode(NEW_BINARY.encode()).decode()
+ reasons = self.run_check({CURRENT: new + "; echo '" + fake_prev + "'", PREV: old})
+ self.assertEqual(1, len(reasons))
+ self.assertIn(f'its {PREV} does not report', reasons[0])
+ # A malformed answer refuses both slots.
+ m = load_script()
+ self.assertEqual(2, len(m.guard_refusals(TARGETS[0], 0, 'garbage\n', '')))
if __name__ == '__main__':