Skip to content

fix(taskproto): create bind-mount dirs with privilege (#564), and document the real staging contract - #649

Merged
scttfrdmn merged 2 commits into
mainfrom
docs/620-task-run-staging-help
Oct 4, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
docs/620-task-run-staging-help

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Refs #620. Deliberately not Fixes — see the last section.

The gap

task run --help said only "the manifest dirs are bind-mounted", which reads as though any path works for any image. The reporter on #620 named it as exactly what led them to the wrong conclusion twice.

What verifying their points turned up

I checked both facts against the code before writing them down, and both constraints have already been lifted. Documenting them as asked would have encoded obsolete advice into the help text:

claim status
"the container runs as the image's user (bioconda = mambauser uid 57439)" No longer true. #555 (ac5655a, 2026-09-02) added --user "$(id -u):$(id -g)", evaluated in the same shell as stage-in, so the container runs as the instance user by construction — not, as #565 argued, "by luck of the AMI".
"output parents are never mkdir-ed, so dockerd creates them as root" (#564) Fixed by c327274 (2026-09-03).
"the container gets EPERM unlinking a staged input" (#565) Fixed by the same commit — whose title names both: "create output-only mount dirs and fix staged-input ownership (#564, #565)".

Confirmed by generating a wrapper with a directory output under a distinct parent and reading the emitted script:

mkdir -p '/other'
mkdir -p '/out/results'
mkdir -p '/work'
  aws s3 cp 's3://b/in.fq' '/work/in.fq' || STAGE_RC=$?
  sudo chown "$(id -u):$(id -g)" '/work/in.fq' 2>/dev/null || true
  sudo docker run --rm --user "$(id -u):$(id -g)" -v '/other':'/other' -v '/out/results':'/out/results' -v '/work':'/work' …
  aws s3 cp --recursive '/out/results/' 's3://b/results/' || OUT_RC=$?

Every mount dir is pre-created as the instance user; every staged input is chown'd to that uid; the container runs as that uid; a trailing-slash manifest stages recursively in both directions.

So the help text now says the opposite of the workaround: any absolute path works, the image's USER is irrelevant, and staged paths do not need to be kept flat in /tmp.

What is still true, and is the actually useful part

resources.disk_gib sizes the root EBS volume (pkg/taskproto/taskspec.go:48), so it governs an ordinary path like /work. /tmp on AL2023 is a tmpfs, capped near half of instance memory — so a 40 GiB index staged into /tmp fails on a 32 GiB box no matter how large disk_gib is.

The reporter's measurement is what makes this worth stating rather than leaving to inference: sizing for a staging footprint in memory tends to pick the instance family rather than just its size (m8g.2xlarge at 44% less than the c8g.4xlarge the vCPU count alone implied). The two choices are not interchangeable on cost.

Why #564 and #565 stay open

Their fixes are in the code, but I am not closing them on a code read. Both were reported from real instances, and #606 is the standing lesson in this repo that real-hardware validation catches what code-tracing and dry-runs miss. They want a real run to confirm.

Worth noting why they looked open: PR #568 merged the fixes on 2026-09-03 with no closing keyword in its body, so neither issue auto-closed — the same bookkeeping gap that left #615 open after #634. The fixes shipped; the issues just never got updated.

Verification

gofmt, go vet, full go test -short ./..., make check-docs (regenerated docs-gen/task.md is committed in the same commit, as the gate requires), and semgrep scan --config=auto --error . → 0 findings. Rendered output read back from the built binary via task run --help.


Fixes #564
Refs #620, #565

…omes from

`task run --help` said only "the manifest dirs are bind-mounted", which reads as
though any path works for any image. The reporter on #620 identified it as
exactly what led them to the wrong conclusion twice.

Verifying their two points against the code turned up something better than a
docs gap: both constraints they wanted documented have already been lifted, and
documenting them would have encoded obsolete advice.

  - "The container runs as the image's user (bioconda = mambauser uid 57439)" is
    no longer true. #555 (ac5655a, 2026-09-02) added
    `--user "$(id -u):$(id -g)"`, evaluated in the same shell as stage-in, so the
    container runs as the instance user BY CONSTRUCTION rather than by luck.
  - "Output parents are never mkdir-ed, so dockerd creates them as root" and
    "the container gets EPERM unlinking a staged input" were both fixed by
    c327274 (2026-09-03) — whose title names both issues: "create output-only
    mount dirs and fix staged-input ownership (#564, #565)". Confirmed by
    generating a wrapper with a directory output under a distinct parent: every
    mount dir gets `mkdir -p` as the instance user, every staged input a
    `sudo chown "$(id -u):$(id -g)"`, and a trailing-slash manifest stages with
    `aws s3 cp --recursive` in both directions.

So the help text now says the opposite of the workaround: any absolute path
works, the image's USER is irrelevant, and staged paths do NOT need to be kept
flat in /tmp.

The genuinely non-obvious fact that remains true is documented plainly:
resources.disk_gib sizes the ROOT EBS volume, so it governs an ordinary path like
/work — while /tmp on AL2023 is a tmpfs capped near half of instance memory, so a
40 GiB index staged into /tmp fails on a 32 GiB box regardless of disk_gib. The
reporter's measurement that sizing for a staging footprint in MEMORY tends to
pick the instance family rather than its size (m8g.2xlarge at 44% less than the
c8g.4xlarge vCPU count implied) is the reason that distinction is worth stating
rather than leaving to inference.

#564 and #565 are left OPEN deliberately. Their fixes are in the code, but these
were reported from real instances and #606 is the standing lesson that
real-hardware validation catches what code-tracing misses — so they want a real
run to confirm before closing, not my reading of the generated script.

Refs #620
@codecov

codecov Bot commented Oct 4, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…aths work

Real-AWS validation of #564/#565 found that my earlier reading of the code was
wrong, and that only one of the two was actually fixed.

#565 IS fixed. On a real t4g.medium:

    uid=1000 gid=1000 groups=1000
    drwxrwxrwt  11 0    0    320 /tmp          <- sticky 1777
    -rw-r--r--   1 1000 1000  42 /tmp/staged.bin
    rm exit=0 / PASS-565

--user does override the image's declared USER (alpine declares root; the
container ran as 1000) and the staged input is owned by that uid, so the
sticky-bit unlink succeeds.

#564 was NOT fixed, and the mkdir I pointed at as proof is the bug:

    mkdir: cannot create directory ‘/out’: Permission denied
    spawn: [...] stage-in done rc=0            <- failure swallowed
    drwxr-xr-x 2 0 0 /out/results              <- docker -v made it, as root
    sh: can't create /out/results/a.txt: Permission denied

The mkdir IS emitted, but it runs as the unprivileged instance user, so it
cannot create a directory whose parent it does not own — every top-level path:
/out, /data, /work. So the auto-creation-as-root that the loop exists to prevent
happened anyway, 90 seconds later, as a container permission error with nothing
pointing at the host-side failure. spawn's own documented /data + /work example
could not work, and /tmp was in practice the only usable staging location, which
is what forced callers to keep staged paths flat.

A code read cannot catch this: the mkdir is present either way, and only a real
instance shows it returning non-zero. #606 is the standing lesson and I repeated
it — asserting on the issue that #564's premise was false before testing it.

Fix: try the unprivileged mkdir first and escalate to `sudo mkdir -p` plus a
chown to the invoking uid only when that fails, so no privilege is used where
none is needed. A directory that still cannot be created sets STAGE_RC, failing
the task AT stage-in as staging_error rather than running the command against an
unwritable mount.

The chown is gated on the directory not already existing, and that guard is
load-bearing rather than an optimization: a destination of /tmp/staged.bin
yields a mount dir of /tmp, and chowning THAT would strip the sticky ownership
every other user on the box depends on — far worse than the bug being fixed.
TestMountDirNeverChownsAnExistingDirectory executes the generated block against
an existing directory and asserts sudo is never invoked.

Re-validated on real AWS with the same spec: state=completed, exit 0,
/out/results now drwxr-xr-x 2 1000 1000 (was root), and the directory output
staged recursively to S3 including its subdirectory (a.txt, sub/c.txt). Both
instances terminated and leak-checked (zero instances, no orphaned volumes);
~$0.004 total.

The --help text in this branch is now true rather than aspirational: it ships
with the fix that makes "any absolute path works" correct. The exec-based
wrapper tests gained a `sudo` stand-in, deliberately narrow — it passes
everything through EXCEPT mkdir/chown, because a blanket pass-through also
swallowed `sudo docker run` and masked a user command's real exit code.

Also updated the test's placement-mount assertion: FSxMountPoint only takes
effect alongside an FSxLustreID, so my first version asserted nothing.

Fixes #564
Refs #620, #565
@scttfrdmn scttfrdmn changed the title docs(task): explain the bind-mount contract and where staging space comes from fix(taskproto): create bind-mount dirs with privilege (#564), and document the real staging contract Oct 4, 2026
@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Scope changed: this now carries the #564 fix, because the docs I wrote were wrong

Pushed 8ba018b. Do not read the original PR description as current — I retitled this and the docs text has changed.

I wrote "any absolute path works ... you do not need to keep staged paths flat in /tmp" based on a code read. A real-AWS run disproved it. The two issues came apart:

#565 — fixed, confirmed on a real t4g.medium

uid=1000 gid=1000 groups=1000
drwxrwxrwt  11 0    0    320 /tmp
-rw-r--r--   1 1000 1000  42 /tmp/staged.bin
rm exit=0  /  PASS-565 staged input deleted, no EPERM

#564 — NOT fixed, and the mkdir I cited as proof is the bug

mkdir: cannot create directory ‘/out’: Permission denied
spawn: [...] stage-in done rc=0            <- failure swallowed
drwxr-xr-x 2 0 0 /out/results              <- docker -v made it, as ROOT
sh: can't create /out/results/a.txt: Permission denied

The mkdir is emitted — that part of my reading was right — but it runs as the unprivileged instance user, so it cannot create a directory whose parent it does not own. That is every top-level path: /out, /data, /work. The auto-creation-as-root the loop exists to prevent happened anyway, 90s later, as a container permission error with nothing pointing at the host-side failure.

A code read cannot catch this — the mkdir is present either way; only a real instance shows it returning non-zero. #606 is the standing lesson in this repo and I repeated it.

The fix

Unprivileged mkdir first, escalating to sudo mkdir -p + chown to the invoking uid only when that fails, so no privilege is used where none is needed. A directory that still cannot be created sets STAGE_RC, failing the task at stage-in as staging_error rather than running the command against an unwritable mount.

The chown is gated on the directory not already existing, and that guard is load-bearing. A destination of /tmp/staged.bin yields a mount dir of /tmp; chowning that would strip the sticky ownership every other user on the box depends on — far worse than the bug being fixed. TestMountDirNeverChownsAnExistingDirectory executes the generated block against an existing directory and asserts sudo is never invoked.

Re-validated on real AWS, same spec

state=completed, exit 0; /out/results went from drwxr-xr-x 2 0 0 to drwxr-xr-x 2 1000 1000; and the directory output staged recursively to S3 including its subdirectory:

val/out-20261004004658/a.txt
val/out-20261004004658/sub/c.txt

Both instances terminated and independently leak-checked (zero running instances, no orphaned volumes). ~$0.004 total.

So the --help text now ships with the fix that makes it true, rather than describing behaviour that did not exist.

Two smaller notes: the exec-based wrapper tests gained a sudo stand-in that is deliberately narrow — it passes everything through except mkdir/chown, because a blanket pass-through also swallowed sudo docker run and masked a user command's real exit code. And my first placement-mount assertion was vacuous: FSxMountPoint only applies alongside an FSxLustreID.

My own changelog gate also caught a duplicate ### Fixed group here, which is the second time it has earned its keep.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

task: directory outputs (Manifest source ending in /) cannot work on the container path

1 participant