Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions bin/devrun
Original file line number Diff line number Diff line change
Expand Up @@ -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/*'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}"]
Expand Down
4 changes: 3 additions & 1 deletion docs/hygiene.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions tests/integration-devrun
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/test_devrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down
Loading