Repository navigation
fix(repo): the isolation probe writes its task list to a mktemp file - #145
Conversation
The probe script wrote the task names to a fixed file in /tmp and left it behind. Run outside a container, two probes on one machine shared it, and a file another user owned made the probe fail. It now writes to a mktemp file and removes it on exit. The test runs the probe with its own TMPDIR, checks that nothing is left there, and that an unwritable TMPDIR stops the probe. Signed-off-by: Anton Volkov <antonwolfy@gmail.com>
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #145 +/- ##
==========================================
+ Coverage 91.29% 91.38% +0.09%
==========================================
Files 216 216
Lines 26565 26722 +157
Branches 4337 4373 +36
==========================================
+ Hits 24252 24421 +169
+ Misses 1645 1636 -9
+ Partials 668 665 -3
🚀 New features to boost your workflow:
|
|
@exai-bot /review |
exai-bot
left a comment
There was a problem hiding this comment.
Note
AI-generated review of f22ed48b8684, requested by @vchamarthi, using the default review skill. It can be wrong: verify a finding before acting on it. React with a thumbs up or down on a finding to tell the bot whether it helped.
Model us.anthropic.claude-sonnet-5-5, effort default, 7 of 94 turns, 0.5 of 48 minutes, 99k in / 3k out tokens.
The probe now writes its task list to a mktemp file, removes it with an EXIT trap, and fails the task with probe: mktemp failed if mktemp fails. The script change is correct. The trap runs after exit $bad and keeps the exit status, and the failure path exits 1 so the task is reported rather than passed. The new test case depends on file permissions and will fail anywhere that doesn't enforce them, such as running as root.
2 findings are on the changed lines, as comments below.
Not verified
I did not run the test. I assumed the root failure from how mktemp and chmod behave for uid 0.
| (image / "usr/bin/fix_pip").write_text("", encoding="utf-8") # a task's name left in the image | ||
| named = probe("fix_pip") | ||
| assert named.returncode == 1 and "named like a task" in named.stdout, named.stdout | ||
| tmp.chmod(0o500) # the list is a mktemp file under TMPDIR: an unwritable one stops the probe |
There was a problem hiding this comment.
Minor (confirmed, tests): The unwritable-TMPDIR case fails when run as root or on a platform that ignores chmod
- Problem:
tmp.chmod(0o500)only stopsmktempfor a non-root user on a filesystem that enforces POSIX modes. As root, as in a typicaldocker rundev or CI container, the directory stays writable.mktempthen succeeds, the probe returns 0, and theprobe: mktemp failedassertion fails. - Platform: Windows ignores the chmod too, so the case would fail wherever this test runs with an
shon PATH. - Convention: other tests in the repo guard this with
os.geteuid() == 0skips:test_repo_run.py:492andtest_task_harnesses.py:940and:963. - Cost: the new case sits inside the existing test, so a root run loses the other probe assertions as well.
Suggested fix:
Move the unwritable-TMPDIR case into its own test, marked skipif for not hasattr(os, "geteuid") or os.geteuid() == 0 as the neighbouring tests do. Alternatively, point TMPDIR at a path that does not exist, which makes mktemp fail for every user on every platform.
| done | ||
| done | ||
| printf '%s\n' $EVAL_TASKS > /tmp/dokimi-tasks | ||
| names=$(mktemp) || { echo "probe: mktemp failed"; exit 1; } |
There was a problem hiding this comment.
Nit (plausible, maintainability): A missing mktemp binary is reported as "mktemp failed"
In a minimal task image without mktemp, names=$(mktemp) fails with 'not found' and the task is reported broken. Previously the probe worked in such an image, because it used only shell redirection. This is probably acceptable, since busybox and coreutils both ship mktemp. The changelog could still say that the image now needs mktemp.
napetrov
left a comment
There was a problem hiding this comment.
Right fix: mktemp + EXIT trap, loud failure if mktemp fails.
Pushed 428024e: the unwritable-TMPDIR case is skipped under root. Root writes through 0o500, so mktemp succeeds and the assertion would fail in a root container (docker ci-local, some self-hosted runners).
Root writes through a 0o500 directory, so mktemp succeeds there and the case would fail in a root container (docker ci-local, some runners). Signed-off-by: Nikolay Petrov <nikolay.a.petrov@intel.com>
The isolation probe that
repo tasks checkruns in a task's image wrote the task names to a fixed/tmp/dokimi-tasksfile and left it there. In the image that is harmless. But the test runs the same script with plainshoutside a container, and there:named like a taskassertion;/tmp/dokimi-tasksowned by another user makes the probe fail.Follow-up to the thread on #102 (#102 (comment)), where this was left out of scope.
Changes
selfcheck.py:_ISOLATION_SHwrites the list to amktempfile and removes it with anEXITtrap. Ifmktempfails, the probe printsprobe: mktemp failedand exits 1, so the task is reported, not passed.test_the_isolation_probe_script_reports_what_it_names: each probe runs with its ownTMPDIRundertmp_path, and the test checks that nothing is left there. A new case makesTMPDIRunwritable and expectsprobe: mktemp failed. That case fails if the script goes back to a fixed path.Fixed.Checks
make ci-localat the head: 26 passed, 0 failed, 4 skipped (docker-only, org-level and jobs that do not run on a PR).