Skip to content

tools: shelter an app, chroot tier (build, prove, stop-native, start) - #82

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

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

Conversation

@TusanHomichi

Copy link
Copy Markdown
Member

What this adds

Route: none. This is a harness change. The box that uses it, el/centos7-pyapp, follows in its own PR.
New fixes: none
Claims issue: none. This follows SPEC "Sheltering an app" (#77).

Before: a box whose own app needs Python 2 can't walk past the release that ships it, because the walk rolls back the hop that drops Python 2.

After: when a box carries a [shelter.<app>] plan, the reference harness builds the app a shelter at that hop and moves the app into it:

  • build (before the hop that leaves keeps_runtimes_on): resolves the interpreter and import owners, fetches the closure from that release's vault, checks each rpm's signature (rpmkeys --checksig), installs a root, and writes shelter.lock.
  • prove: runs the app's checks against the shelter root in a throwaway copy of the box.
  • stop-native (that hop's pre phase): disables the app's unit and comments out its cron lines, saving the originals.
  • start (post phase): writes the podman unit, the egress table unit, the socket proxies and the timers, and enables them.

The run records shelters with tier = "chroot" and confinement_proved = false. A failed build or prove stops the walk on keeps_runtimes_on, which is the "stop" option.

How:

  • tools/shelter.py holds the ops.
  • walk.py calls them only for boxes with a plan. For every other box the hop commands are byte-identical, and parity holds.
  • check.py validates the plan, and tools/test_check.py covers the broken cases.
  • tools/podman_standin.sh is CI-only. It stands in for podman while checks run, by chrooting into the shelter root with the declared mounts, and it is never shipped to clients.

Why the box isn't in this PR: CI judges with the base branch's tools. If the box landed first, every centos7 route would go red.

Model

anthropic:claude-opus-5-5, hand-directed.

Evidence

Local, on this code plus the follow-up box:

  • python3 wend check passes, and tools/test_check.py plus every other tools/test_*.py pass.
  • Rust parity: 152 checker cases (66 refused), 137 type cases (121 refused): identical.
  • wend replay routes/el/centos7-to-alma10.toml el/centos7-pyapp printed KEPT shelter billing: built on centos7 and proved (51 packages), then 9/9 checks after alma9 and after alma10: PASS ... 2 hops, 11 fixes fired. There were no decoy errors.

Not proved: confinement (real podman, the uidmap with :idmap mounts, SELinux :Z, nftables, the socket units). That's the VM tier on remi.

Self-review (AGENTS.md step 5)

🤖 Generated with Claude Code

https://claude.ai/code/session_016XrCggTfrYZFPiDyPrhqLF


Generated by Claude Code

tools/shelter.py is the reference for SPEC "Sheltering an app" on CI: build
resolves the interpreter and the owners of what the app's programs load
(run once in a throwaway copy), takes their closure from keeps_runtimes_on's
own repos at final versions, checks each rpm's sha256 against the index and
its signature against the release's key, installs with the release's rpm
into /var/lib/wend/shelter/<app>/root, carries the user's passwd and group
lines and any unowned or changed files, and writes shelter.lock. prove sets
the shelter up in a copy of the box and runs its checks there.
stop-native and start are the drop hop's pre and post steps.

tools/podman_standin.sh stands in for `podman run` while checks run: it
chroots into the shelter root the image ID names with the declared mounts
and ignores confinement. walk.py runs build and prove before the hop that
leaves keeps_runtimes_on and records each shelter in the run; boxes without
[shelter] walk exactly as before. check.py validates [shelter.<app>].

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]>
@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-13T19:16:06.762109Z b34ac6c 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

Independent review of head b9d5f4e68d4213c90e702d113e90464745b81c24.

Changes requested on b9d5f4e

What I ran: python3 wend check (ok, and still ok with el/centos7-pyapp/box.toml from the follow-up dropped in), tools/test_check.py plus all the other tools/test_*.py (all rc=0, no WRONG lines, every shelter case refused or passed as intended), and the client build plus client/parity.py (identical).

What holds up:

  • Boxes without [shelter] behave exactly as before. sh_pre and sh_post are [], drop is None, check_health follows the old path, and the run dict gets no new key.
  • A refused build or prove stops the walk, records a failed step, and failed_stage names it.
  • A rolled-back drop hop also undoes stop-native and start, because both are hop commands restored from the snapshot.
  • Every plan value interpolated into shell matches a checker pattern with no quotes, $, %, backslash or ;.
  • The stand-in rbinds the box's own tmpfs /dev, never the host's. Its first bind leaks into the host namespace but sits under the box root, and Box._umount removes it.
  • The rpm -K signature check really refuses NOT OK, NOKEY and unsigned packages.
  • The lock has the fields the SPEC lists.

Blockers

  1. tools/shelter.py:327 and :351: the host writes through a symlink the box controls. open(f"{scratch}/tmp/wend-shelter-runner.py", "w") and open(f"{scratch}/tmp/wend-files", "w") run on the host as root. copy_to uses rsync -a, which keeps symlinks, so a /tmp (or /tmp/wend-files) that is an absolute symlink in the box sends the write onto the runner's real filesystem. This repo's own threat model says "a box's package scripts can plant symlinks, and this runs on the host" (backends.file_sha256), and the same file guards {work}, {d} and usr/bin with plain_dir. These two writes need the same guard, or should go through s.run.
  2. tools/check.py check_shelter / shelter.cron_calendar: some cron lines translate wrongly but pass the checker. In cronie, when either day field starts with * (*/2, for example), the two day fields are ANDed, not ORed. 30 2 */2 * 1 /x becomes ['*-*-1/2 02:30:00', 'Mon *-*-* 02:30:00'], which runs every odd day or every Monday instead of odd days that are Mondays. The checker accepts this, start writes the wrong timer, and SPEC:1266 and :1282 say "translates exactly". Either emit the AND form (Mon *-*-1/2 …) or refuse it, and add a test case.
  3. SPEC.md:1204 contradicts SPEC.md:1292. The Defaults bullet still says shelter.start reserves the subuid range and "records it in the lock". The new text, and the code (walk.py, rec["subuid"]), put it in the run only. One of the two has to change.

Non-blocking notes

  • sandbox.Box._umount kills only processes whose /proc/<pid>/root equals the box root. A sheltered program runs chrooted into …/var/lib/wend/shelter/<app>/root in its own mount namespace, so if a check times out it outlives the box, keeping its namespace and mounts. Matching r + "/" as a prefix would catch it.
  • shelter.py:414: carried paths come from what the program loaded at runtime and go into cp -a {f} $R{f} unquoted. This runs inside the chroot, but a name containing a space or a shell metacharacter would break it or execute. Hold them to ABS_PATH or quote them.
  • shelter.py:352: os.path.realpath(f"{scratch}{i}") resolves an absolute interpreter symlink against the host, and the slice then yields a garbage path. It's redundant anyway, since the runner already records realpath(sys.executable).
  • The SPEC says the lock records "signing keys" and that the proxy's User= is "recorded in the run". The lock holds only the key's path, and the run's shelters record has no proxy user. The table is wend_shelter_<app>, while SPEC:1217 says inet wend_shelter.
  • data may name /var/lib/wend/... (the shelter's own root and lock) or /var/run/... (a symlink to /run on EL7). Consider refusing both.
  • SPEC says shelter.build refuses when the drop hop's facts need something the plan didn't list. Nothing compares them yet. That's fine while preflight isn't built, but the text should say so.
  • Build and prove each take a full extra copy of the box, on top of the snapshot. That is roughly 3× an EL box's disk on the runner.

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: b9d5f4e68d

ℹ️ 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 tools/shelter.py Resolved
Comment thread tools/shelter.py Resolved
…y fields AND when one starts with *; SPEC: the uid range is in the run

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

Answering the changes requested on b9d5f4e. All three are fixed in 9c734b7:

  1. Host writes into the box copy. Both writes now go through a new _host_write. It requires the target directory to be a plain directory inside the copy (backends.plain_dir), removes whatever is at the path, and creates the file with O_CREAT|O_EXCL|O_NOFOLLOW. A symlinked /tmp, or a planted link at the file's path, gets refused instead of followed.
  2. Cron day fields. When either day field starts with *, the timer now needs both to match, as cronie does. Only when both are restricted and neither starts with * does it become two OnCalendar= lines. 30 2 */2 * 1 → Mon *-*-1/2 02:30:00. There are regression cases in tools/test_check.py, and the SPEC sentence says the same.
  3. The SPEC contradiction. The uid range is now recorded in the run, as the code does.

wend check, every tools/test_*.py, and Rust parity (...152 checker cases (66 refused)...: identical) all pass.

The notes are not in this PR. The unquoted carried paths, the stray-process killer and disk use go into the client-ops PR, where they're built for real.


Generated by Claude Code

Copy link
Copy Markdown
Member Author

Re-review of head 9840a8f7365b0edf8cc041fec11c0aa598a692a2. It covers 9c734b7 (the fixes for my three blockers) and 9840a8f (cron user must be the app's user).

Sign-off: approve 9840a8f

How each blocker was resolved:

  1. Host writes into the box copy. Both writes now go through _host_write. It requires plain_dir on the target directory, unlinks anything already at the path, and opens with O_CREAT|O_EXCL|O_NOFOLLOW. A symlinked /tmp or a planted link is refused instead of followed. Resolved.
  2. Cron day fields. When either raw day field starts with *, the timer now uses a single AND line: 30 2 */2 * 1 gives Mon *-*-1/2 02:30:00. I checked */1 by hand and it also comes out AND. The three regression cases pass, and the SPEC sentence matches. Resolved.
  3. SPEC contradiction. SPEC:1204 now says the range is recorded in the run, which matches the code. Resolved.

The new commit, 9840a8f: check_shelter refuses a cron entry whose user isn't the plan's user, and a test case and the SPEC table cell were added. This is correct, and tighter than before: build's crontab lookup and the timer both run as the app's user.

What I re-ran on 9840a8f:

  • python3 wend check is ok, and also ok with el/centos7-pyapp/box.toml added.
  • Every tools/test_*.py passes, with 0 WRONG.
  • Client parity is identical. 9840a8f changes no client code.

On the earlier non-blocking notes, I re-checked whether any of them is unsafe on a CI runner. None is:

  • Stray sheltered process. It only outlives a check when that check times out, since normal exits kill the process group. It runs as the app's uid, chrooted inside the box. The box's app and cron checks run in an isolated network namespace, and the runner is ephemeral. That makes it a resource leak, not an escape.
  • Unquoted carried paths. They run inside the box chroot, with the same privilege the box's own customize already has.

Fine to defer both to the client-ops PR.


Generated by Claude Code

…-pzmnbf

Signed-off-by: Claude <[email protected]>

# Conflicts:
#	tools/test_check.py
@github-actions github-actions Bot added the needs-claude-review Waiting on the Claude review layer label Oct 13, 2026

Copy link
Copy Markdown
Member Author

Review of the merge commit 7a356966126fa16110e7d2e93353cffb3e7fdd87 (parents 9840a8f and main's da52d7b).

Sign-off: approve 7a35696


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: 7a35696612

ℹ️ 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 tools/shelter.py Resolved
Comment thread tools/shelter.py Resolved
Comment thread tools/shelter.py Resolved

Copy link
Copy Markdown
Member Author

Review of git diff 7a35696 eda8eef7ae891f9c40ac2eddbc1348b06cf5f7e4, which covers Codex's three P1s.

Sign-off: approve eda8eef

  • ExecStartPre quoting. I ran the generated heredoc through sh with I, S, U, G and X set. In the written unit, $I expands to the 64-hex digest, in both the image exists tag and the import - tag. The '...' inside the heredoc stays literal, so systemd hands sh -c one argument. After expansion, nothing is left for systemd to treat as a $ or % specifier. The digest comes from the lock through a [0-9a-f]{64} sed, and the app name from SHELTER_APP, so nothing unvalidated reaches the line. The box's checks read ^ExecStart=, which doesn't match ExecStartPre=.
  • Stand-in. image exists exits 0. import - drains stdin and exits 0. The tag is stripped with ${1#localhost/wend-shelter-*:} and still has to be 64 lowercase hex, and anything that isn't a shelter tag is refused. sh -n passes.
  • NET_BIND_SERVICE. It's added only when the unit publishes a port below 1024. Timers never publish, so they never get it.
  • egress. Entries are held to PUBLISH (IPv4 octets under 256, port 1–65535). Host names and shell are refused, with tests. Each entry becomes an ip daddr … tcp dport … accept in both chains, after established,related and before the subnet drop. Everything else still drops, so it fails closed.
  • python3 wend check and every tools/test_*.py pass on eda8eef, with 0 WRONG. The SPEC text matches the code.

Non-blocking notes:

  • The tag says the lock's digest, but nothing re-derives that digest from root/ before podman import. If the root changes after the build, it is imported under a tag that no longer describes it. A tree_digest re-check at import, or in start, would make "runs the image by the lock's digest" mean "verified".
  • \d in PUBLISH also matches non-ASCII Unicode digits. That's harmless (no shell metacharacters, and nft fails closed), but [0-9] would be stricter. This also applies to ports.
  • Whether --cap-add reaches a non-root --user process as an ambient capability depends on the podman version. Only the VM tier will show it.

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: eda8eef7ae

ℹ️ 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 tools/shelter.py Resolved

Copy link
Copy Markdown
Member Author

Review of git diff eda8eef 0a4f89ecbd08d85807167c52706e31d43fc4d152: the code volume changes from :ro to :ro,idmap, plus one SPEC sentence.

Sign-off: approve 0a4f89e

  • The stand-in still mounts the code volume read-only. I ran its own parsing on /opt/billing:/opt/billing:ro,idmap: opts=ro,idmap, and case ",$opts," matches *,ro,*, so it still runs mount -o remount,bind,ro (podman_standin.sh:35). The stand-in ignores idmap, as it ignores every other confinement option.
  • The SPEC sentence matches the code.
  • python3 wend check and every tools/test_*.py pass on 0a4f89e, with 0 WRONG.

Generated by Claude Code

…-pzmnbf

Signed-off-by: Claude <[email protected]>

# Conflicts:
#	tools/test_check.py

Copy link
Copy Markdown
Member Author

Review of the merge commit b34ac6cb66c6080effb51aba42e734dccc5aaf5f (parents 0a4f89e and main's 5b41b8f).

Sign-off: approve b34ac6c

  • The conflict. git show --remerge-diff shows one conflict, in tools/test_check.py. The resolution keeps the shelter cases and cron cases, main's root_fs cases, and main's updated pockets comment (-updates/-security/-backports); the old comment is dropped. It touches nothing else.
  • The rest of git diff 0a4f89e b34ac6c is main's. That is vm: XFS v4 on LVM with an empty extra disk, and relocate onto it #72/vm: [vm].pockets may name backports (wend#47) #85/box: ubuntu/trusty-web-updated asks the VM installer for -backports too (wend#47) #86: [relocate] and the install keys in adapters/el.toml, check_relocate, [vm].root_fs, backports pockets, vm.py, test_relocate.py, the client's check.rs, boxes and a run. tools/sandbox.py, tools/walk.py and tools/shelter.py are unchanged by the merge.
  • Interactions with the shelter path. I found none:
    • relocate exists only in tools/vm.py (VM tier). Neither walk.py, shelter.py, backends.py nor sandbox.py mentions it.
    • The adapter keys the shelter reads are untouched: runtimes, may_skip, releases.<r>.repos and .major, mirror.shim, release_file, and hop. vm: XFS v4 on LVM with an empty extra disk, and relocate onto it #72 only adds install sub-keys and a [relocate] table.
    • vm.py still borrows hop_cmds on a bare object. getattr(self, "shelter_steps", {}) keeps that working, and the VM tier doesn't shelter yet, as the SPEC says.
    • The shelter test plan builds on el/centos7-lamp, whose new [vm].root_fs is valid, so the shelter cases still mean what they did.
  • Checks on b34ac6c. python3 wend check is ok (9 boxes, 35 runs), and still ok with el/centos7-pyapp staged (10 boxes). Every tools/test_*.py passes, with 0 WRONG. The client builds, and parity is identical (156 checker cases, 70 refused).

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: b34ac6cb66

ℹ️ 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 tools/shelter.py Resolved
@TusanHomichi
TusanHomichi merged commit bb32f72 into main Oct 13, 2026
7 checks passed
@TusanHomichi
TusanHomichi deleted the claude/project-thread-pzmnbf branch October 13, 2026 19:16
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