Repository navigation
feat(sandbox): reclaim leftovers from a previous boot - #58
Conversation
Record the machine (Linux machine-id in the initial PID namespace outside containers; macOS IOPlatformUUID) and the boot, so that leftovers of an earlier boot of the same machine (created before this boot) and of a renamed Mac are reclaimed. Anything else stays kept. Co-Authored-By: Claude Opus 5.5 <[email protected]>
nishide-dev
left a comment
There was a problem hiding this comment.
Verdict: CHANGES_REQUESTED
PR #58(#56: 前の boot と、host 名を変えた後の残りものの回収)のレビューです(head 0f1d2c9)。「消してはいけないものを決して消さない」という観点で見ました。判定は全体として残す側に倒れていて、must-fix はありません。should-fix は 1 件で、Linux で btime による保険を通らずに別 boot の creator を PID で判定してしまう経路があります。強制はされていない不変条件に頼っているので、CHANGES_REQUESTED にします。修正は数行で済みます。
実行結果
clone した PR の head で、docker build -t texrun-engine:latest docker/engine(label 無し)を使いました。host は macOS、OrbStack です。
cargo fmt --check/cargo clippy --workspace --all-targets --all-features --locked -D warnings/cargo test --workspace --all-features --locked: すべて pass- dev コンテナ(
docker-compose run --rm dev cargo test --workspace --all-features --locked): すべて pass TEXRUN_REQUIRE_SANDBOX=1の container testtexrun-sandbox: unit 40 + container 21 を 3 回繰り返し、すべて passtexrun-texliveのcontainer/scenarios/security: 14 / 11 / 14、passtexrun-previewのcontainer/real_tools: 4 / 13、pass- CLI の
container: 8、pass - 終了後、label
org.texrun.sandboxの container は 0 件でした
- この Mac の
ioreg -rd1 -c IOPlatformExpertDeviceの出力は約 1.9 KB で、IOPlatformUUIDの行は 1 行だけでした。64 KiB の上限には十分な余裕があります。 - CI はすべて green です。
確認した点(問題なし)
Linux の machine と boot
- machine を記録するのは、初期 PID namespace にいて、
/.dockerenvも/run/.containerenvも無い場合だけです。初期 PID namespace は、1 つの kernel に 1 つしかありません。そのため、同じ kernel の中で machine と boot が同じなら、host(boot ID + ns)も必ず同じになり、SamePidSpaceに入ります。--pid=hostの container や hostPID の pod で marker が無い場合も、PID は実際に比較できるので、判定は正しいです。 - 別 boot と判定される(
OtherBoot)には、ラベルの boot が今と違うことが必要です。今の boot で生きている texrun の label は、今の boot ID を持ちます。そのため、同じ kernel の中で、生きている creator がOtherBootと判定されることはありません。OtherBootになりうる「生きている creator」は、machine-id が同じ別の kernel が runtime を共有している場合だけです。その場合の保険が.Created < btimeです。 - 時計の扱い。
/proc/statのbtimeは「今の wall clock − uptime」なので、時計を step したときは一緒に動きます。同じ kernel の daemon(rootful / rootless Docker、Podman)では、.Createdと同じ時計です。前の boot の時計が進んでいた場合は、.Createdが後ろにずれて残る側に倒れます。また、今の boot で作ったものは、そもそもOtherBootになりません。したがって、時計のずれで誤って消える経路は、上の別 kernel の場合に限られます(nit 1)。btimeは OnceLock に入れて最初の値を使い続けますが、その後に時計を進めても、判定が厳しくなるだけです。 ctimeは所有者が任意の値にできません。変えられるのは「今」への更新だけで、これは残す側です。scratch directory は、自分の euid の 0700 のものに限られます。- 壊れた
.machine/.boot/.startedは、?で候補から外れます(host が同じでも外れます)。
macOS
- 同じ machine で host 名だけが違う場合は、PID で判定します。再起動の後に PID が再利用されていれば「生きている」とみなすので、残ります。開始時刻が無いことも、残す方向にしか働きません。消えるのは、この Mac でその PID が使われていない場合だけです。
- machine の hash には
linux-machine/macos-machineの接頭辞が入るので、OS をまたいで一致することはありません。 ioregの起動: path は固定で、is_fileを確かめます。shell は使いません。Specの既定はenv_clear()の後の空の allowlist です。timeout は 5 秒、stdout は 64 KiB までで、上限を超えたらNoneです。stderr は捨てます。stop、失敗した終了、truncate のいずれでもNoneになり、machine 無し(Unknown、従来どおり host だけで判定)に倒れます。parse は、行頭(trim 後)の"IOPlatformUUID" = "から閉じ引用符までを取り、8-4-4-4-12 の hex で全て 0 でないことを確かめます。十分堅牢です。
互換性と ps の絞り込み
- #49 形式の label(machine 無し)で host が違うものは、
Unknownで残ります。#49 より前の形式(.host無し)は、label(LABEL_HOST)?で残ります。scratch の名前では、#49 形式(host の後が 16 hex の 1 要素だけ)を machine・boot 無しとして読みます。新しい形式を #49 形式と読み違えた場合も、条件が厳しくなるだけです。 psの絞り込みを.uidまでにしたことで、候補(別 host の同じ uid のもの)は増えます。ただしinspectは読むだけです。消すかどうかは、これまでどおりcandidate(label、uid、host または machine の関係、名前、停止状態)、is_gone、--force無しのrmで決まります。安全性は下がっていません。--type containerも付きました。.Createdの parser: Docker のZと、Podman の offset 付き(符号の扱いも正しい)の両方を正しく読みます。小数は 9 桁で切り捨てます。不正な形式、1970 年より前、offset の無いものはNoneで、別 boot の回収だけが行われません。日付の検証は月ごとの日数を見ていませんが(2 月 31 日を受け付けます)、こうした値は繰り上がって後ろの時刻になるだけなので、消す方向には働きません。{{json .Created}}が空白を含む形になった場合は、label の JSON の parse ごと失敗して、その行は候補になりません。
テスト
only_stopped_...から件数の assert を外したことで、検証が弱くなってはいません。並行する別 test の回収も同じ判定を使うので、「消えたこと」と「残ったこと」を名前で確かめれば十分です。新しい test の「残す」container(同じ machine で別 boot、別 machine、壊れた label、#49 形式)は、並行する他の test の回収でも残ります。macOS のrenamedは、他の test が先に消しても期待どおりです。
should-fix
1. Linux で「machine はあるが boot が無い」状態ができうる。両側がそうなると、btime の保険を通らずに PID で判定される
relation は、machine が一致し、両側とも boot が無い場合を SamePidSpace(macOS の想定)にします。しかし、その前提(boot が無いのは macOS だけ)は、コードでは強制されていません。
local()では、host_id()とmachine_and_boot()が/proc/sys/kernel/random/boot_idを 別々に 読みます。host の読み取りが成功しても、2 回目の読み取りが一時的に失敗すれば(fd の枯渇など)、machine: Some, boot: Noneの Creator ができ、その状態で label や名前に記録されます。- 両側がこの状態になると、machine が同じで host が違う Linux の creator(=別 boot)を、
.Created < btimeを確かめずに PID と開始時刻で判定します。開始時刻は boot ごとの tick なので、ほぼ必ず違い、「gone」になります。同じ kernel ならこの判定でも結果は正しいです。しかし、この PR が保険を設けた「machine-id が同じ別 kernel」の場合には、その保険が外れます。
起きる確率は低いものの、判定の安全性が暗黙の不変条件に依存しているので、強制してください。
修正案(どちらか、できれば両方):
machine_and_bootの Linux 分岐で、boot がNoneなら machine もNoneにする(例:let machine = boot.and(machine);)。boot ID はhost_idと共有して 1 回だけ読むと、なおよいです。relationの(None, None) => SamePidSpaceを macOS に限る。例えばcfg!(target_os = "macos")を条件にして、それ以外はUnknownにする。あわせて unit test に「Linux で machine のみの両側は Unknown」を足してください(OS によって期待値が変わるので、cfg で分けるか、relationに OS を引数で渡せる形にする)。
nit
- 「別 kernel を排除する」の表現と、時計の前提。 owner.rs の module doc は「which rules out another live kernel that happens to share the
machine-id」と書いていますが、実際に排除できるのは「こちらの boot の後に作られたもの」だけです。security.md も「事実上起きない」と書いています。しかし、別 kernel の texrun が一時停止(SIGSTOP/ Ctrl-Z など)していて、こちらの boot より前に作った container が止まったまま残っている場合は、その container を消しえます(影響は、その texrun が終了状態や OOM を読めなくなる程度です)。また、この比較は daemon の時計(.Created)とこちらの kernel の時計(btime)の比較です。そのため、別 kernel の構成では、両者の時計が合っていることが前提になります。rustdoc と §4 を「こちらの boot の後に作られたものを除外する(runtime の時計とこの kernel の時計が合っていることが前提)」という趣旨に直すと、正確になります。 - macOS の複製 VM。
IOPlatformUUIDが同じ macOS の複製 VM が runtime の socket を共有している場合、machine が同じなので、host 名が違っても PID で判定されます(#49 でも、host 名が同じ複製 VM なら同じ状況だったので、この PR で生じた問題ではありません)。docs の「残すもの / 判定の前提」に一言書いておくとよいと思います。将来的には、/usr/sbin/sysctl -n kern.bootsessionuuidを boot として記録できます(ioregと同じ起動方法で、unsafeは不要です)。そうすれば、macOS でも「同じ machine・同じ boot → PID」「別 boot →kern.boottimeとの比較」と、Linux と同じ保険を掛けられます。 - container test の後始末。
containers_of_this_machine_are_judged_by_boot_and_creation(と既存のonly_stopped_...)は、assert が失敗すると、それ以降の container をrmせずに panic します。偽装した label の container が daemon に残るので、作った名前をDropでrm --forceする guard にすると確実です。 - development.md の表現。 「
/etc/machine-idが読めない場合」に、macOS の「IOPlatformUUIDが読めない場合」も並べると、security.md §2 の 5 と揃います。 - Linux の正の経路の検証。
another_boot_of_this_machine_needs_an_earlier_creationは、machine が無い環境(dev コンテナ、macOS)では早期 return します。実際に machine を記録した状態で通るのは、CI のtest (linux)/sandbox(GitHub の runner VM は初期 PID namespace で動きます)だけです。その前提を test のコメントに書いておくと、後で runner が container に変わったときに、検証されなくなったことに気づけます。
…macOS Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
レビューありがとうございます。指摘に対応しました。 should-fix 1
nit
確認
補足: 同じ daemon で main の版の |
nishide-dev
left a comment
There was a problem hiding this comment.
Verdict: APPROVE
PR #58 の再レビューです(head a41708f、fix(sandbox): record the machine only with the boot, and the boot on macOS)。前回の should-fix 1 件は解消しました。nit 1〜5 もすべて対応されています。新しく入った macOS の boot(kern.bootsessionuuid / kern.boottime)も、「消してはいけないものを消す」方向には働かないことを確認しました。APPROVE とします。
実行結果
clone した最新の head を使い、engine image は label 無しの texrun-engine:latest です。host は macOS(OrbStack)です。
cargo fmt --check/cargo clippy --workspace --all-targets --all-features --locked -D warnings/cargo test --workspace --all-features --locked: すべて pass- dev コンテナ(
docker-compose run --rm dev cargo test --workspace --all-features --locked): すべて pass TEXRUN_REQUIRE_SANDBOX=1の container testtexrun-sandbox: unit 41 + container 21 を 3 回繰り返し、すべて passtexrun-texliveのcontainer/scenarios/security: 14 / 11 / 14、passtexrun-previewのcontainer/real_tools: 4 / 13、pass- CLI の
container: 8、pass - 終了後、label
org.texrun.sandboxの container は 0 件でした
- macOS で
another_boot_of_this_machine_needs_an_earlier_creationが早期 return せずに実行されることを確かめました(machine と boot の両方が記録されます)。 - この Mac の
/usr/sbin/sysctl -n kern.bootsessionuuid kern.boottimeの実際の出力は、「UUID の行」と「{ sec = N, usec = M } 日付」の 2 行で、macos_bootが想定する形と一致しました。 - CI はすべて green です。
前回の指摘の確認
- S1: 解消。
- Linux では、
boot_idを 1 回だけ読み、host と boot の両方をそこから作ります。boot が読めなければ identity 自体がNoneになります。 local()でmachine = boot.and(machine)としたので、machine だけの記録はどの OS でも作られません。relation_inは、machine と boot が両側に揃っている場合しかUnknown以外を返しません。(None, None)は全ての OS でUnknownです。- 同じ machine・同じ boot・host 違いを
SamePidSpaceにするのは、ONE_PID_SPACE_PER_BOOT(cfg!(target_os = "macos"))の場合だけです。これで、前提がコードで強制されるようになりました。 - 判定表は、Linux と macOS の両方の期待値を
relation_inで直接確かめています。片側に machine や boot が無い場合も、両方の値でUnknownを確かめています。 - host の hash の入力(Linux の
linux\n<boot_id>\n<ns>、macOS の<os>\n<node>)は変わっていません。そのため、#49 の label との互換性は保たれています。前回の commit の形式(macOS の machine のみ)は merge されていないので、互換性の問題はありません。
- Linux では、
- nit 1(btime の保険の範囲と時計の前提): rustdoc と §4 に正確に書かれました。
- nit 2(macOS の複製 VM):
kern.bootsessionuuidは boot ごとに作られます。そのため、IOPlatformUUIDが同じ複製 VM でも、別の boot として btime(kern.boottime)の保険の対象になります。 - nit 3:
RemoveOnDropで、assert が失敗しても偽装した label の container が残らなくなりました。 - nit 4・5: development.md の列挙と、test の SKIPPED / CI の前提のコメントが追加されました。
macOS の sysctl / ioreg の取得(run_small)
- 起動する program は固定の絶対 path(
/usr/sbin/ioreg、/usr/sbin/sysctl)で、is_fileを確かめます。引数は固定の argv で、shell は使いません。Specの既定はenv_clear()の後の空の allowlist です。cwd は/、timeout は 5 秒、stdout は 64 KiB まで、stderr は捨てます。 - stop、失敗した終了、truncate、UTF-8 でない出力のいずれでも
Noneです。sysctlの日付の部分は locale や TZ に依存しますが、parse では読まずに捨てるので、空の環境でも問題ありません。 macos_bootは次のどれか 1 つでも満たさなければNoneにします。- 1 行目が UUID(8-4-4-4-12、全て 0 でない)
- 2 行目が
{ sec = <10 進>, usec = <10 進 < 1,000,000> }で始まる - 3 行目が無い
- 取得に失敗すると、boot が無く、したがって machine も無い状態になり、host だけの判定(#49 と同じ)に戻ります。残す側です。
新しい判定表の評価
- 同じ host: 従来どおり、PID と開始時刻で判定します。
- 同じ machine・同じ boot・host 違い(macOS): 同じ kernel の同じ boot なので、PID は比較できます。PID が使われていれば残し、開始時刻が無いことも残す方向にしか働きません。Linux では、初期 PID namespace の制約によりこの組み合わせは起きないので、
Unknownで残すのが正しいです。 - 同じ machine・別 boot: 今の boot で生きている texrun の label は、今の boot を持ちます。そのため、同じ kernel の中で生きている creator がこの分類に入ることはありません。入りうるのは、machine の識別子が同じ別の kernel だけです。その場合も、今の boot の開始より後に作られたもの(
.Created/ctime)は残ります。docs に書かれた残余(一時停止した別 kernel の texrun の、こちらの boot より前の container)は、影響が小さく、明記されているので、受け入れられます。 - 時計: 同じ kernel では、時計の step や前の boot の時計の進みは、作成時刻を後ろにずらして残す側に倒れるだけです。macOS では
.Createdは runtime の VM の時計です。前の boot のものは通常kern.boottimeより前になり、VM の時計が遅れていても、影響しうるのは別 kernel の場合だけです(docs の前提どおり)。 - macOS の scratch directory(
/var/folders/.../Tは再起動しても残る)も、別 boot のものはctime < kern.boottimeで回収されます。同じ boot のものは PID で判定されます。
nit(任意。merge を止めるものではありません)
fsops.rsのreclaim_scratch_dirsの rustdoc で、same machine and boot), and no process with its PID and start time; or, #56,の行だけが他の行より長くなっています(rustfmt はコメントを折り返さないので、通っています)。次に触るときに折り返してください。
## 概要 `v*` の tag を push するだけで、検証 → engine image の公開 → **release notes 付き** の GitHub release の作成(source tar 添付)まで完了するようにする。release notes は前の版の tag から今回の tag までの commit(= squash merge した PR タイトル、Conventional Commits)を git-cliff で分類して生成し、インストール方法・image の tag / digest・`gh attestation verify`・source tar の説明を定型で付ける。既存 release の notes だけを作り直す workflow も追加する(v0.1.0 の notes を埋めるのに使う)。 ## 変更内容 - `cliff.toml`(新規): git-cliff の設定。type で分類(`feat` → Features / `fix` → Bug fixes / `perf` → Performance / `docs` → Documentation / `refactor`・`test`・`build`・`chore` → Other changes)。`chore(deps)` は Dependencies に「N dependency updates: #a, #b」の 1 行にまとめる(PR 番号はタイトル行の末尾の `(#N)` だけから取る。番号の無いものは件数にだけ数える)。`!` / `BREAKING CHANGE:` は Breaking changes にも載せる。Conventional でない commit も Other changes に残す。**すべての行は commit のタイトル(1 行目 = PR タイトル)だけから作り**、PR 本文や footer の文面は載せない。末尾の `(#N)` を PR へのリンクにし、`@name` は mention にならないよう code にし、前の版との compare リンクを付ける。 - `.github/scripts/release-notes-test.sh` / `release-notes-test.expected.md`(新規): 使い捨ての repository に main の squash merge と同じ形の fixture の commit(PR 本文付き、実際の Dependabot 形式の本文付き(単独・group)、PR 番号の無い `chore(deps)`、日本語の `BREAKING CHANGE:` footer + attribution、GitHub の Revert、`@name` を含むタイトル)を作り、notes の「What's changed」を期待値と比べる。PR の `notes` job で毎回実行する。 - `.github/scripts/release-notes.sh`(新規): `release-notes.sh <tag> [<digest>]` で notes の Markdown を出力する。 - 安定版は前の安定版から(間の prerelease を畳み込む: `--ignore-tags '^v.*-'`)、prerelease は直前の tag から、最初の版は全履歴。git-cliff の `--context` から対象 tag の release だけを選んで `--from-context` で描画するので、HEAD が tag より先(main)でも同じ notes になる。 - tag がまだ無い場合は「最後の tag 〜 HEAD」をその版としてプレビューする。digest を省略すると placeholder。 - tag が HEAD の祖先でない、semver でない、digest の形式が違う、対象の commit が無い、などはエラー。 - `.github/workflows/engine-image.yml` - `publish` が `digest` を output する。 - `release` が checkout(`fetch-depth: 0`)→ git-cliff(`taiki-e/install-action` を SHA pin、`[email protected]`。install-action が checksum を検証)→ notes 生成(job summary にも出す)→ release の作成(`--notes-file`。版に `-` があれば prerelease にする既存の扱いを維持)。 - release が既にある場合(手で作った / 再実行)は、notes を生成したもので **上書き** してから asset を upload する。 - `.github/workflows/release-notes.yml`(新規): notes の生成だけを行う workflow。image の公開・release の作成はしない。 - `pull_request`(`cliff.toml`・script・この workflow の変更時): fixture の test の後、PR の head commit(merge ref ではなく。`Merge … into …` の行が入らない)で、最後の tag(現状 v0.1.0、全履歴)の notes と、次の版(patch + 1)としての「最後の tag 以降」の notes を job summary と artifact `release-notes` に出す。digest は GHCR から引く(未公開の版は placeholder)。 - `workflow_dispatch`(`tag`、`update`): `update=false`(既定)は dry run。`update=true` は `gh release edit --notes-file` で既存 release の notes を置き換える(main か tag 上の実行のみ。image が GHCR に無い版は失敗)。 - 権限: 生成する `notes` job は `contents: read`。書き込む `update` job だけが `contents: write` で、repository の code は実行しない(artifact を受け取って `gh release edit` するだけ)。 - docs - `docs/development.md`: release 手順を「tag を push するだけ」に更新し、「release notes」節(分類の規則、notes の文面は PR タイトルで決まること、ローカルでの生成方法、作り直し方)を追加。 - `CONTRIBUTING.md`: PR タイトルが release notes の 1 行になること、type / description の書き方の注意、notes の PR check を追記。 - `docs/security.md`(権限の記述)、`docs/engine-image.md`(digest は release notes に載る)を追随。 ## 設計判断 - **git-cliff を採用**(GitHub の自動生成 + `.github/release.yml` ではなく): この repo は PR にラベルを付けない運用で、GitHub の自動生成はラベルでしか分類できない。git-cliff は commit の type で分類でき、PR タイトル = commit タイトルの運用にそのまま合う。API を使わず(`--offline`)git の履歴だけで決まるので、PR 上やローカルでも同じ結果を再現できる。 - **既存 release の notes は上書き**: notes は git の履歴と公開済みの digest から決定的に作られるので、再実行で上書きしても結果は同じ。手で先に release を作った場合も、生成した notes に揃える(docs に明記。公開後の手修正は、作り直すと消える)。 - **CHANGELOG.md は置かない**: tag ごとに CHANGELOG 更新の commit / PR が必要になり、運用が増えるため。GitHub release を changelog とし、必要なら同じ `cliff.toml` から `git cliff` でいつでも全履歴を出せる。 - **notes の作り直しは別 workflow**: engine-image.yml の `workflow_dispatch` は image の公開と結び付いているので、notes だけの経路を分けた。image は再公開せず、digest は GHCR にある既存の版から引く。 - **notes の生成は image の公開後**: digest が要るため `release` job で生成する。設定の誤りは PR 上の `Release notes / notes` で先に検出する。万一 `release` で失敗しても image は公開済みで、`gh run rerun --failed` でやり直せる(既存の手順どおり)。 - **git-cliff の版**: `2.14.2` を両 workflow で固定(install-action の manifest の sha256 で検証)。install-action 自体は SHA pin で、Dependabot の対象。 ## 確認方法 - [x] `actionlint`(全 workflow)、`shellcheck .github/scripts/release-notes.sh` - [x] ローカルで git-cliff 2.14.2(公式 release の tar を sha512 で確認)を使って生成 - `release-notes.sh v0.1.0 sha256:b611…` → 下記(v0.1.0 までの全履歴、32 commit) - `release-notes.sh v0.1.1` → v0.1.0 以降の差分(この PR の commit のみ)のプレビュー - 使い捨ての clone で `v0.2.0-rc.1` / `v0.2.0-rc.2` / `v0.2.0` を打って確認: rc.2 は rc.1 からの差分、v0.2.0 は v0.1.0 からの全部(rc の分を畳み込む)。tag が HEAD の祖先でない場合・semver でない tag・不正な digest はエラーになる - `release-notes-test.sh`: 期待値どおり(下記)。修正前の `cliff.toml` に戻して実行すると、Dependabot の行が `3 dependency updates (Dependabot):,,` に、Breaking changes が日本語の footer + `🤖 Generated with …` に、Revert の行が本文付きに、`@octocat` が mention になり、test が失敗することを確認した - レビュー対応の後も v0.1.0 の notes は変わらない(前回の出力と diff なし) - [x] `CONTRIBUTING.md` / `docs/development.md`: タイトルだけが載ること、`@name` を書かないこと、`jq` が要ること、`update` は通常 `--ref main` で実行すること(v0.1.0 の tag の上には workflow が無い)、fixture の test を追記 - [x] PR 上の `Release notes / notes` が、v0.1.0 と v0.1.1(プレビュー)の notes を job summary と artifact に出す(GHCR から v0.1.0 の digest を引く) - `workflow_dispatch` の dry run は、新規 workflow が default branch に入るまで dispatch できないため、merge 後に `gh workflow run release-notes.yml --ref main -f tag=v0.1.0` で確認する(PR 上の `pull_request` の実行が同じ生成を行う) - tag の push・release の作成 / 編集・publish を有効にした実行はしていない - Rust のコードは変更していない(cargo の品質ゲートは CI で確認) ### 生成例: v0.1.0(digest は GHCR の実際の値) <details> <summary>v0.1.0 の notes(全文)</summary> ````markdown ## What's changed ### Features - **core**: Define compile domain model and engine interface ([#20](#20)) - **workspace**: Add isolated compile workspaces ([#21](#21)) - **diagnostics**: Parse LaTeX logs into structured diagnostics ([#23](#23)) - **texlive**: Add latexmk engine ([#30](#30)) - **preview**: Render PDF pages to PNG previews ([#31](#31)) - **cli**: Add compile command ([#34](#34)) - **workspace**: Exclude nested output directories by path ([#38](#38)) - **diagnostics**: Locate missing packages and fold fatal errors ([#40](#40)) - **diagnostics**: Report BibTeX failures ([#42](#42)) - **process**: Apply resource limits before exec through a gate ([#44](#44)) - **process**: Limit CPU, memory and process count ([#45](#45)) - **sandbox**: Add a container backend for the TeX engine ([#50](#50)) - **sandbox**: Render previews inside the container ([#52](#52)) - **sandbox**: Reclaim containers left by killed runs and report the process limit ([#53](#53)) - **sandbox**: Reclaim leftovers from a previous boot ([#58](#58)) ### Bug fixes - **workspace**: Refine exclusion and collection edge cases ([#29](#29)) - **texlive**: Restore the build after #39 and #40 ([#43](#43)) - **sandbox**: Accept engine images without labels ([#55](#55)) - **sandbox**: Support rootless Podman and refuse rootless Docker ([#57](#57)) - **sandbox**: Detect OOM kills reliably on Docker ([#61](#61)) ### Documentation - Add contribution guidelines and MIT license ([#15](#15)) - Add initial README ([#18](#18)) - **security**: Define the MVP security model and execution limits ([#22](#22)) - Update README to reflect the completed MVP ([#37](#37)) - Rewrite the README ([#59](#59)) ### Other changes - Initialize repository - Bootstrap Rust workspace and toolchain ([#16](#16)) - **ci**: Add quality gates and dependency checks ([#19](#19)) - **docker**: Add TeX Live development environment ([#17](#17)) - Add TeX Live integration fixtures and CI job ([#33](#33)) - **process**: Extract shared subprocess execution ([#39](#39)) - **ci**: Publish the engine image to GHCR ([#51](#51)) ## Install ```bash cargo install --locked --git https://github.com/nishide-dev/texrun --tag v0.1.0 texrun ``` See the [README](https://github.com/nishide-dev/texrun/blob/v0.1.0/README.md#installation) for the requirements and the tools each backend needs. ## Engine image The container backend (`--backend container`) runs TeX in the engine image of this version, `ghcr.io/nishide-dev/texrun-engine:0.1.0` (linux/amd64, linux/arm64). texrun never pulls it; pull it once: ```bash docker pull ghcr.io/nishide-dev/texrun-engine:0.1.0 ``` Published versions are never overwritten. To use exactly this image, pin its digest: ```bash docker pull ghcr.io/nishide-dev/texrun-engine@sha256:b611748f16d50c00982da2e52b51939d50167bebbc22b35ab8741d1c39e00d1b texrun compile --backend container --container-image ghcr.io/nishide-dev/texrun-engine@sha256:b611748f16d50c00982da2e52b51939d50167bebbc22b35ab8741d1c39e00d1b main.tex ``` The image has an SBOM, SLSA provenance and a signed GitHub artifact attestation: ```bash gh attestation verify oci://ghcr.io/nishide-dev/texrun-engine:0.1.0 -R nishide-dev/texrun ``` ## Source of the engine image `texrun-engine-0.1.0-sources.tar` (below) has the Debian source packages (`.dsc`, `.orig.tar.*`, `.debian.tar.*`) of every package in the image, for both platforms, at exactly the installed versions (`packages.txt` and `SHA256SUMS` inside): the corresponding source of its GPL / AGPL programs. See [docs/engine-image.md](https://github.com/nishide-dev/texrun/blob/v0.1.0/docs/engine-image.md#licenses). ```` </details> ### 生成例: v0.1.0 以降の main の差分(次の版のプレビュー) ````markdown ## What's changed ### Bug fixes - **ci**: Build release notes lines from commit titles only ### Other changes - **ci**: Generate release notes from conventional commits - **ci**: Write release notes on tag push and add a notes-only workflow **Full diff**: [v0.1.0...v0.1.1](v0.1.0...v0.1.1) ```` (以下の Install / Engine image / Source は v0.1.0 と同じ形で、digest は placeholder。squash merge 後は 1 commit になる) ### 生成例: fixture(`release-notes-test.expected.md`) ````markdown ## What's changed ### Breaking changes - **cli**: Rename --json flag to --format json ([#4](#4)) ### Features - **cli**: Rename --json flag to --format json ([#4](#4)) ### Bug fixes - **diagnostics**: Report the error `@octocat` found ([#7](#7)) ### Other changes - Revert "fix(core): handle empty logs ([#5](#5))" ([#6](#6)) ### Dependencies - 3 dependency updates: [#2](#2), [#3](#3) **Full diff**: [v0.1.0...v0.2.0](v0.1.0...v0.2.0) ```` ## 補足 - merge 後、v0.1.0 の notes を埋めるには: `gh workflow run release-notes.yml --ref main -f tag=v0.1.0`(dry run、summary で確認)の後に `gh workflow run release-notes.yml --ref main -f tag=v0.1.0 -f update=true`。 - notes の文面は PR タイトルで決まる。merge 後に誤りに気付いた場合は release を手で編集できるが、作り直すと消える。 - 推奨(任意): `release-notes.yml` の `update` job にも、engine-image.yml と同様に `environment` を付けることを検討できる(docs/security.md の「release の入口」)。 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
概要
host の識別子(Linux は boot ID + PID namespace、macOS は host 名)が変わった後でも、同じマシン の残りもの(停止した sandbox container と preview の scratch directory)を回収できるようにします。Linux の再起動(電源断・kernel panic を含む)と macOS の host 名の変更が対象です。判定できない場合はこれまでどおり残します(安全側)。
変更内容
Creatorに machine と boot の識別子(どちらもOption、texrun 用の接頭辞付き FNV-1a hash)を追加/etc/machine-id(32 桁の hex。全 0 /uninitializedは不可)。texrun が 初期 PID namespace(pid:[4026531836])にいて、container の中でない(/.dockerenv・/run/.containerenvが無い)場合だけ記録する。boot は/proc/sys/kernel/random/boot_id。IOPlatformUUID。/usr/sbin/ioreg -rd1 -c IOPlatformExpertDeviceを path で起動(shell 無し、空の環境、timeout 5 秒、出力 64 KiB まで、texrun_process::run経由)。unsafeは使わない。boot は記録しない。owner::relation、Creator::is_gone(created))/proc/statのbtime)より前に作られた 場合だけ回収(container はinspectの.Created、scratch directory はctime)。machine-id を共有する別の kernel(複製した VM など)が runtime の socket を共有していても、動いている texrun のものを消さないためorg.texrun.sandbox.machine/.bootを追加(分かる場合のみ)。psの絞り込みは.uidまでにし(前の boot のものは.hostが違うため)、host / machine の照合はcandidateで行うtexrun-preview-<pid>-<start|x>-<host>-<machine|x>-<boot|x>-<random>に。Reclaim leftover sandbox containers and report the process limit in containers #49 形式(machine / boot 無し)の名前も読み、従来どおり host だけで判定する.host無し・random だけの名前)は回収しない(変更なし)reclaim_scratch_dirsの rustdoc を「per tree」に修正、回収のinspectに--type container.Createdの RFC 3339 parser を追加(Docker のZ、Podman の{{json .Created}}の offset 付きの両方)docs/security.md§2「sandbox backend で追加で保証する」の 5、§4「container のライフサイクル」「scratch directory の回収」、検証の表、docs/development.mdを更新HostConfigの照合(Test the container backend with rootless Podman and handle rootless Docker #47 の範囲)には触れていません確認方法
cargo check --workspace --all-targets --all-features --lockedcargo fmt --all -- --checkcargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo test --workspace --all-features --locked(host: macOS)cargo deny --locked checkdocker build -t texrun-engine:latest docker/engine、TEXRUN_REQUIRE_SANDBOX=1)texrun-sandbox: unit 40 + container 21(3 回繰り返し)texrun-texliveのcontainer/scenarios/security: 14 / 11 / 14texrun-previewのcontainer/real_tools: 4 / 13container: 8org.texrun.sandboxの container は 0 件docker-compose run --rm dev cargo test --workspace --all-features --locked): すべて pass追加した test:
owner.rs: 識別子の組み合わせごとのrelation(同 host、同 machine・別 boot → OtherBoot、別 machine、片側の machine / boot 欠落、同 machine・同 boot・別 host → Unknown、macOS の machine のみ)、before_boot、作成時刻が今の boot 以降なら別 boot でも回収しない、machine-idとioreg出力の検証、tag の新旧形式reclaim.rs: 同じ machine で host 違いの label の候補判定(壊れた label・別 machine・Reclaim leftover sandbox containers and report the process limit in containers #49 形式は残す)、.Createdの parsefsops.rs: Reclaim leftover sandbox containers and report the process limit in containers #49 形式の名前は従来どおり回収、別 boot(ctimeが今の boot 以降)・別 machine は残す、macOS では host 名の変わった同じ machine のものを回収containers_of_this_machine_are_judged_by_boot_and_creation: label を偽装した停止 container で、同 machine・別 boot(今作ったもの)、別 machine、壊れた label、machine 無しの別 host は残し、macOS では同 machine・別 host(dead PID)を回収することを実 daemon で確認関連 Issue
Closes #56
補足
machine-idは image のものを多くの container で共有しうるので、別の kernel の texrun と区別できないため、machine を記録しません。machine-id/IOPlatformUUIDが読めない環境も同様です。.Created < btimeを要求するのは、machine-idが同じ別の kernel が socket を共有しているという想定しにくい構成への保険です。電源断から再起動までの間に作られた container も、作成時刻は boot より前なので回収されます。ctimeが更新されるので以後は回収されません(手で消す。docs に記載)。inspectの format に{{json .Created}}を追加しました。Podman では.Createdが time 型ですが、JSON にすると RFC 3339 になるので同じ parser で読めます(Podman 実機では未確認。読めなければNoneで、別 boot の回収だけが行われない側に倒れます)。only_stopped_containers_of_gone_texrun_processes_are_reclaimedは、並行する別 test の回収と競合しうるので、返り値の件数の assert を外し、container の有無だけで確認するようにしました。🤖 Generated with Claude Code