diff --git a/bin/devrun b/bin/devrun index 98dfced..e67cd39 100755 --- a/bin/devrun +++ b/bin/devrun @@ -326,7 +326,7 @@ mode="$1"; shift export_patch="$1"; shift cd /work git_q() { git -c user.name=devrun -c user.email=devrun@invalid -c commit.gpgsign=false -c init.defaultBranch=main "$@"; } -mkdir -p "$HOME" +mkdir -p "$HOME" "$TMPDIR" if [ "$mode" = history ]; then git_q init -q . git_q fetch -q /scratch/in/history.bundle '+refs/*:refs/devrun/*' @@ -364,7 +364,7 @@ if [ "$1" = 1 ]; then find /target -mindepth 1 -delete; fi # Phase 1. Runs no repository-chosen code: the copy has no cargo config or toolchain file, and the # environment pins the compiler and clears the wrappers (docs/hygiene.md section 3). -FETCH_COMMAND = ["bash", "-c", 'mkdir -p "$HOME" && exec cargo fetch --locked'] +FETCH_COMMAND = ["bash", "-c", 'mkdir -p "$HOME" "$TMPDIR" && exec cargo fetch --locked'] class Docker: @@ -409,6 +409,12 @@ class Docker: "--mount", f"type=volume,src={self.project}-work,dst=/work", "--mount", f"type=volume,src={self.project}-scratch,dst=/scratch", "--env", "HOME=/tmp/home", + # Docker mounts --tmpfs noexec by default, so test binaries (rustdoc's doctests) + # cannot run from /tmp. TMPDIR is a separate tmpfs that allows execution, capped at + # 1 GiB like /tmp. It is not under /scratch: preparation empties /scratch and could + # not remove a mount point there. + "--tmpfs", "/exec-tmp:rw,nosuid,nodev,exec,size=1g,mode=1777", + "--env", "TMPDIR=/exec-tmp", "--workdir", "/work"] for k, v in (env or {}).items(): args += ["--env", f"{k}={v}"] diff --git a/docs/hygiene.md b/docs/hygiene.md index 60ed5eb..74c43be 100644 --- a/docs/hygiene.md +++ b/docs/hygiene.md @@ -51,7 +51,9 @@ image build and a smoke test. - Non-root user with a fixed UID (`10001`), `--user 10001:10001`. - `--cap-drop ALL`, `--security-opt no-new-privileges`. - `--read-only` root filesystem. Writable places: `/work` (the copy, at the - root of the work volume), `/scratch`, `/tmp` (tmpfs with a size limit), the + root of the work volume), `/scratch`, `/tmp` (tmpfs with a size limit, `noexec`), + `/exec-tmp` (`TMPDIR`: an `exec` tmpfs, also 1 GiB, so test binaries such as doctests + can run), the other named volumes in section 5, and Docker's own `/dev/shm` and `/dev/mqueue`. - **No writable directory above the copy.** Cargo reads `.cargo/config.toml` in diff --git a/tests/integration-devrun b/tests/integration-devrun index aa1c0a5..5ace57b 100755 --- a/tests/integration-devrun +++ b/tests/integration-devrun @@ -44,6 +44,10 @@ probe='set -e test "$(id -u)" = 10001 test "$(pwd)" = /work test -d "$HOME" && touch "$HOME/probe" +test "$TMPDIR" = /exec-tmp +printf "#!/bin/sh\necho ran\n" > "$TMPDIR/exe" +chmod +x "$TMPDIR/exe" +test "$("$TMPDIR/exe")" = ran if touch /devrun-probe 2>/dev/null; then echo "the parent of /work is writable" >&2; exit 18; fi test -f README && test -L README.link && test "$(cat README.link | head -1)" = hello test -d .git # created inside the container by devrun, empty baseline only diff --git a/tests/test_devrun.py b/tests/test_devrun.py index c84be11..bb4c23f 100644 --- a/tests/test_devrun.py +++ b/tests/test_devrun.py @@ -211,6 +211,8 @@ def test_run_container_mounts_the_copy_at_work_with_home_set(self): create = self.calls[-1] self.assertIn("type=volume,src=geordi-work,dst=/work", create) self.assertIn("HOME=/tmp/home", create) + self.assertIn("TMPDIR=/exec-tmp", create) + self.assertIn("/exec-tmp:rw,nosuid,nodev,exec,size=1g,mode=1777", create) self.assertEqual(create[create.index("--workdir") + 1], "/work")