Skip to content

spec: runtime preflight, so a machine's own Python 2 programs aren't silently broken - #73

Merged
TusanHomichi merged 3 commits into
mainfrom
claude/project-thread-pzmnbf
Oct 13, 2026
Merged

TusanHomichi merged 3 commits into
mainfrom
claude/project-thread-pzmnbf

Conversation

@TusanHomichi

Copy link
Copy Markdown
Member

Requested by Peter · project thread

What this adds

A spec change, not a route. It adds SPEC "Runtime preflight": the adapters get a [runtimes] table, there's a new maintainer tool tools/runtimes.py, both checkers validate the table, and the client adds facts and a verdict.

Before: wend preflight judged only the hardware. A CentOS 7 box whose billing app runs on Python 2 was told "can land on alma10", and the app would die on the hop to alma9.

After: wend facts (now wend.hardware/2) lists the box's Python 2 users: running processes, cron jobs, and anything with libpython2 mapped (mod_wsgi in httpd), each with the package that owns its program. A user counts as the machine's own when no package owns its program, or when the interpreter is embedded. The distro's own Python 2 tools (yum, firewalld, fail2ban) don't count, because the route carries their packages. When the route drops Python 2 before the hardware stops, preflight offers a choice: stop at the last release that ships it, or shelter the programs and go on. The shelter design is the next spec PR. Nothing overrides a runtime problem.

How: each booted release's python2 = [...] versions come from the release's own index, not from docs. Debian ships Python 2 through bullseye (2.7.18), Ubuntu through jammy (universe, 2.7.18), and EL through EL8 (the python27 module). wend's EL routes never land on EL8 (may_skip), so an EL7 box's stop is CentOS 7 itself. Facts files from the old schema are refused, so a missing runtimes list is never read as "no Python 2".

Claims issue: none

Model

None. Hand-written in the dep-lab project thread.

Evidence

  • python3 wend check: ok. tools/test_check.py: 4 new broken adapter cases, all refused.
  • cargo fmt --check, cargo clippy --all-targets -- -D warnings and cargo test all pass (35 tests, 5 new: detection on a fixture /proc and root, plus EL7, Ubuntu, Debian 2.4-note and hardware-first verdicts).
  • client/parity.py: identical.
  • Live on a real CentOS 7.9 userland (docker, static musl client): it found /opt/billing/app.py (relative argv, resolved from cwd), python -m SimpleHTTPServer, the cron job /opt/billing/nightly.py (#!/usr/bin/env python) and httpd with mod_wsgi (/usr/lib64/libpython2.7.so.1.0, embedded). It recorded /usr/lib64/python2.7/SimpleHTTPServer.py as owned by python-libs, so that one doesn't count.
  • No route or fix changes. The gate judges with the base branch's tools and adapters, so the replays exercise main's adapters.

Self-review

  • Preconditions: n/a, no fixes
  • Fixes the real problem: it detects what runs, not what's installed
  • One problem: the runtime verdict only; shelter is a separate spec PR
  • No edits to tools/, adapters/, SPEC.md: this is a maintainer spec change, so it edits all three on purpose
  • Commits are signed off

🤖 Generated with Claude Code

https://claude.ai/code/session_016XrCggTfrYZFPiDyPrhqLF


Generated by Claude Code

…silently broken

wend facts now lists the machine's Python 2 users (running processes, cron
jobs, and anything with libpython2 loaded, such as mod_wsgi), with the package
that owns each program. Programs no package owns, and embedded interpreters,
are the machine's own; the distro's own Python 2 tools are carried by the route
and don't count.

Each adapter gets [runtimes.<release>] python2 = [...] for every release a
route boots into, read from the releases' own indexes by tools/runtimes.py:
Debian through bullseye, Ubuntu through jammy (universe), EL through EL8, which
wend's EL routes never land on, so EL7 stops at CentOS 7.

preflight adds runtime_problems per hop and keeps_runtimes_on, and when Python 2
goes before the hardware stops, offers the choice: stop there, or shelter the
programs (SPEC "Sheltering an app", next) and go on. Facts schema is now
wend.hardware/2; older facts files are refused rather than read as "no Python 2".

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016XrCggTfrYZFPiDyPrhqLF
Signed-off-by: Claude <[email protected]>
@TusanHomichi TusanHomichi self-assigned this Oct 13, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-13T14:53:12.615895Z 8a32b7b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copy link
Copy Markdown
Member Author

Changes requested on e69e0a9

I checked the CI steps locally on this sha and all of them pass: cargo fmt --check, cargo clippy --all-targets --locked -- -D warnings, cargo test --locked (35 passed), python3 -B client/parity.py <release binary> (identical), python3 wend check, client/target/release/wend check, and python3 tools/test_check.py. I also checked the adapter version claims against the real indexes, and they match: lenny 2.4.6/2.5.2, squeeze 2.5.5/2.6.6, bullseye 2.7.18-8+deb11u1, bookworm none, jammy universe 2.7.18-13ubuntu1, noble universe none.

Two silent false negatives block this. In both, preflight reports "This machine can land on …" and exits 0 on a machine whose own Python 2 code the route will break, which is the exact outcome this PR exists to prevent.

Blocking

1. Running preflight as a normal user silently finds no Python 2. client/src/runtime.rs:209-211 (let Ok(exe) = fs::read_link(d.join("exe")) else { continue }) and client/src/runtime.rs:296-303/310 (the spool read_dir/read_to_string errors are swallowed).
Neither facts nor preflight asks for root, and client/README.md:47-49 shows both run without sudo. For a non-root caller:

  • readlink /proc/PID/exe and /proc/PID/maps fail with EACCES for every process another user owns. I checked this here with setpriv --reuid=65534: readlink returns 1 and maps gives "Permission denied".
  • /var/spool/cron (0700 on EL) and /var/spool/cron/crontabs (1730 root:crontab on Debian) can't be listed.

Scenario: a CentOS 7 box where billing.service runs /usr/bin/python2 /opt/billing/app.py as user billing, and alice has a Python 2 crontab. The admin runs wend preflight centos7-to-alma10 as themselves. runtimes comes back [] and the verdict is "This machine can land on alma10." The commit message says older facts are refused "rather than read as no Python 2", but this path reads unreadable facts as exactly that. Two possible fixes:

  • Refuse wend facts and live preflight unless euid is 0.
  • Or record that the process scan and spools couldn't be read, and have check_facts/evaluate refuse such facts.

2. On EL5 and EL6, cron jobs that run /usr/bin/python are missed whenever a second Python is installed. client/src/runtime.rs:73-92 (python2_of), reached from the cron path at runtime.rs:268-271.
On EL5 and EL6, /usr/bin/python is a hardlink to python2.4/python2.6, not a symlink. I confirmed this from the rpm headers: python-2.4.3-56.el5 and python-2.6.6-66.el6_8 both give /usr/bin/python and /usr/bin/python2.N the same inode, and python2 is a symlink to python. So resolve stops at python, and the code falls back to counting lib dirs:

  • With EPEL python26 on CentOS 5 (very common), found = {2.4, 2.6} and the function returns None.
  • With EPEL python34 on CentOS 6, three = true and it also returns None.

shebang() then reads the ELF binary and also returns None. I reproduced this with a test against this sha. A root with hardlinked usr/bin/python/python2.4, usr/lib64/python2.{4,6}, and /etc/cron.d/app containing 0 * * * * root /usr/bin/python /opt/app/other.py and 5 * * * * root /opt/app/job.py (#!/usr/bin/python) gives gather() == []. Running processes survive this only because the maps fallback sees libpython2.N. A cron-only Python 2 user on centos5-to-alma10 gets "can land on alma10".
Fix: when the name is ambiguous, look for a sibling python2.N in the same directory with the same (dev, ino) and use its version. The process row at SPEC.md:1021 needs the same wording change.

Non-blocking

  • runtime.rs:203-248: processes in containers (docker/LXC) are counted as the machine's own. Their exe basename is python2.7, and the owner lookup against the host's dpkg/rpm finds nothing. A host running a python:2.7 container is told to stop at bullseye or jammy, even though that program is already sheltered. Consider skipping pids whose /proc/PID/root isn't /, or whose mount namespace differs.
  • runtime.rs:346-350: embedded counts any process that maps libpython2, even when that process is package-owned. An admin's vim on trusty (linked to libpython2.7) or a gdb left open makes the verdict say stop at jammy. The comment "the distro never configures mod_wsgi" is also not quite true: FreeIPA's ipa-server ships its own WSGIScriptAlias on EL7.
  • runtime.rs:124-139, 235-236: a cmdline rewritten by setproctitle is one NUL-free string. For example, salt-minion shows up as "/usr/bin/python /usr/bin/salt-minion KeepAlive …". cmd[1..] is then empty and the program becomes (interactive), with no owner, so it counts as own. Every such process also collapses into a single (interactive) entry. Splitting a lone argv[0] on whitespace would fix most of these cases.
  • runtime.rs:179-185: when rpm -qf fails (rpmdb lock, rpm missing from PATH), the owner is null and distro programs count as own. This errs on the safe side, but it might be worth a note or a refusal.
  • runtime.rs:25: PATH includes /usr/local/bin, but cron's default PATH on Debian is /usr/bin:/bin. A bare python that cron wouldn't find can still be matched.
  • SPEC.md:1046-1048: keeps_runtimes_on is only defined relative to "the first such hop". When the machine has its own Python 2 but no hop drops it, the code returns the last booted release. Please say so in the SPEC.
  • hardware.rs:866: a hop's ok stays true when it has runtime_problems, while report prints NO for it (hardware.rs:897-905). This matches "problems stay the hardware's", but JSON consumers may want it spelled out in the SPEC.
  • client/parity.py: there are no runtimes cases of its own, so only the four refused cases from test_check.py reach parity. Accept-side cases would also be useful, e.g. a table for may_skip alma8, or "2.7" without a patch level.
  • tools/check.py and client/check.rs check_runtimes agree on what they refuse. Their messages differ (['alma9'] vs ["alma9"]), which doesn't matter because parity compares only the refused flag. tools/runtimes.py looks correct. It reads only the release pocket, not -updates/-security (xenial 2.7.11 vs 2.7.12), which is harmless since matching is by minor version.

Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e69e0a923d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread SPEC.md Resolved
Comment thread client/src/runtime.rs Resolved
Comment thread client/src/runtime.rs Resolved
- refuse to gather facts as non-root: a normal user can't read other users'
  /proc/PID/exe and maps or their crontabs, and would quietly see no Python 2
- EL5/EL6 /usr/bin/python is a hard link to python2.N: match the sibling by
  inode, so a second Python (EPEL python26, python34) doesn't hide it
- skip processes in containers (a root of their own)
- cron: honor the crontab's own PATH=, resolve ./job after a cd, and default
  to cron's /usr/bin:/bin
- a hop with runtime problems is not ok in the JSON either
- SPEC: keeps_runtimes_on when no hop drops Python 2; README: run as root

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016XrCggTfrYZFPiDyPrhqLF
Signed-off-by: Claude <[email protected]>

Copy link
Copy Markdown
Member Author

This answers the review on e69e0a9. The changes are in dbcfeaf, which isn't pushed yet.

Blocking:

  1. Non-root misses everything. wend facts and a live wend preflight now refuse to run unless root, with exit 2 and an explanation. I checked that as uid 65534. The README shows sudo.
  2. EL5/EL6 hard-linked /usr/bin/python. It's now matched to a sibling python2.N by device and inode, before the lib-dir guess. A test covers CentOS 5 with EPEL python26 beside it. SPEC is updated.

Non-blocking, taken:

  • Processes whose /proc/PID/root isn't the machine's root (docker, LXC) are skipped. Tested.
  • Cron PATH is /usr/bin:/bin, or whatever the crontab sets.
  • A hop with runtime problems now reads ok: false in the JSON.
  • SPEC now defines keeps_runtimes_on for the case where no hop drops Python 2.
  • I corrected the mod_wsgi comment. FreeIPA is packaged mod_wsgi, but no route carries IPA across anyway, so counting it as own is the safe side.

Non-blocking, left as is:

  • Embedded Python 2 in a package-owned interactive process (vim, gdb) still counts. It over-flags, and the owner sees exactly what was flagged.
  • A process that rewrote its argv still lands under (interactive). Also an over-flag.
  • If rpm -qf fails, the program counts as own. Same direction.

All three of those err toward flagging, never toward a silently broken app.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Signed off on dbcfeaf

I re-reviewed e69e0a9..dbcfeaf and the whole PR at that head.

CI steps rerun on dbcfeaf, all green:

  • cargo fmt --check
  • cargo clippy --all-targets --locked -- -D warnings (re-checked after touching the source)
  • cargo test --locked (35 passed)
  • python3 -B client/parity.py <release binary> (identical)
  • python3 wend check
  • python3 tools/test_check.py
  • the release binary's wend check

Both earlier blockers are fixed:

  1. Non-root runs. runtime::gather_live (client/src/runtime.rs:215-228) refuses when euid isn't 0. wend facts exits 2 with the explanation; I checked this as uid 65534. A live preflight returns the same error, and preflight --facts FILE still works without root. The README now shows sudo.
  2. EL5/EL6 hard-linked /usr/bin/python. It's now matched to a sibling python2.N by device and inode (runtime.rs:74-90), before the lib-dir guess. My earlier reproduction root now finds both cron jobs at this head: CentOS 5 with EPEL python26, one /usr/bin/python other.py line and one #!/usr/bin/python script, each reported as Python 2.4.

The non-blocking fixes taken also look right:

  • Containers. Processes whose /proc/PID/root isn't the machine's root (by device and inode) are skipped (runtime.rs:244-249). Processes that share the host's root but run in their own mount namespace, such as systemd PrivateTmp/ProtectSystem, still count.
  • Cron PATH. The default is /usr/bin:/bin, and a PATH= line in a crontab overrides it for the jobs after it in that file (runtime.rs:361-377).
  • Relative paths after cd. A relative ./job after a cd resolves against that directory. Other words containing /, like >/dev/null, now get normalized and looked up too; they never match, so that's harmless.
  • Per-hop ok. It's false when the hop has runtime problems (hardware.rs:867), and SPEC now says so and defines keeps_runtimes_on when no hop drops Python 2.

Non-blocking notes, none of which need to hold the merge:

  • runtime.rs:404: run-parts scripts resolve #!/usr/bin/env python through the default /usr/bin:/bin. On Debian, run-parts actually runs from /etc/crontab, whose PATH includes /usr/local/bin. So a run-parts script that ends up on a source-built /usr/local/bin/python 2.x is missed. Using /etc/crontab's PATH for the run-parts directories would close this.
  • runtime.rs:305-306: a relative script or ./job with no cd before it is resolved against /, but cron's working directory is the user's HOME. Such a job is missed or named wrongly. This only affects a narrow case.
  • I accept the reasoning for leaving the vim/gdb embedded case, the (interactive) argv case and the rpm -qf failure case as they are: each one over-flags rather than missing a user.

Generated by Claude Code

Union with main's filesystem preflight (mounts): runtime tables follow main's
new driver hashes and boot_mib; the verdict checks mounts then runtimes.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_016XrCggTfrYZFPiDyPrhqLF
Signed-off-by: Claude <[email protected]>

Copy link
Copy Markdown
Member Author

Signed off on 8a32b7b

This review covers only the merge of main (332fda8) into dbcfeaf, which I signed off earlier. I read git show 8a32b7b (the combined diff) and git diff dbcfeaf 8a32b7b -- client/src/hardware.rs adapters/.

  • Adapters: in debian.toml, el.toml and ubuntu.toml, the last release's values now come from main: the new drivers hashes, and ubuntu's boot_mib = 116. The [runtimes.*] tables follow them unchanged. wend check (both engines) confirms the driver hashes match the atlas.
  • evaluate: the loop runs main's mounts check, then first = false, then the runtime check, before lands/blocked are computed. Mount problems go into problems, so they count as hardware and can stop the route first. Python 2 problems stay in runtime_problems. The first flag (main) and the own/keeps/runtime_broken/noted variables (this PR) are both declared before the loop.
  • Facts: check_facts refuses facts that lack valid runtimes and facts that lack valid mounts. The schema stays wend.hardware/2. Main was still on /1, so there's no clash.
  • Test helper: machine() carries both "runtimes": [] and main's mounts (a 256-byte-inode ext3 root), and main's with_mount helper is kept.
  • No test lost: the hardware test functions at the merge (20) are exactly the union of dbcfeaf's (18) and main's (17). runtime.rs, check.rs and main.rs are byte-identical to dbcfeaf.

CI steps rerun at 8a32b7b in a separate worktree, all green:

  • cargo fmt --check
  • cargo clippy --all-targets --locked -- -D warnings
  • cargo test --locked (37 passed, including both sides' new tests)
  • python3 -B client/parity.py <release binary> (identical)
  • python3 wend check
  • python3 tools/test_check.py
  • the release binary's wend check (64 fixes, 30 runs: ok)

One nit, not blocking: the resolution added an extra blank line at the end of adapters/debian.toml and adapters/ubuntu.toml.


Generated by Claude Code

@github-actions github-actions Bot added the needs-claude-review Waiting on the Claude review layer label Oct 13, 2026
@TusanHomichi
TusanHomichi merged commit 8d2adad into main Oct 13, 2026
13 checks passed
@TusanHomichi
TusanHomichi deleted the claude/project-thread-pzmnbf branch October 13, 2026 15:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-claude-review Waiting on the Claude review layer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants