Skip to content

Staged inputs land in sticky /tmp owned by the instance user, so a container running as another uid cannot rm them #565

Closed

Description

@scttfrdmn

What happened

Two tasks in a five-recipe batch died at the same line: rm of a staged input.

== verify staged reads against their pinned sha256 ==
ERR188026_sub_1.fq.gz: OK
ERR188026_sub_2.fq.gz: OK
rm: cannot remove 'star-index.tar': Operation not permitted

Identical failure in the sibling task (rm: cannot remove 'salmon-index.tar': Operation not permitted). Both tasks stage a ~0.6–1.6 GiB tar from S3, untar it, and delete the tar to hold peak disk down inside the 8 GiB root.

Why

Three facts compose into it:

  1. pkg/taskproto/wrapper.go:90 stages every input with aws s3 cp on the host, running as the instance user — writeContainerRun's own comment says "The command script runs as the unprivileged instance user (bootstrap runs it via su - <user>)".
  2. Host /tmp is 1777. It is also the only mount reliably writable from the container whatever user the image runs as, so it is where flat staged paths have to go.
  3. The container runs as the image's user — wrapper.go emits sudo docker run --rm with no --user in 0.102.0. Here that is mambauser (uid 57439) from the bioconda base.

Sticky-bit semantics: a user may only unlink files they own in a 1777 directory. So the container can read a staged input, can create and delete its own files, and cannot delete a staged one.

Reproduced on a real Linux filesystem (a macOS bind mount will not show this — Docker Desktop doesn't enforce sticky-bit ownership, which is how it passed seven local dry runs):

$ docker run --rm -u 0:0 --entrypoint bash quay.io/aarchbio/star@sha256:90331f64... -c '
  mkdir -p /work && chmod 1777 /work && cd /work && echo payload > staged.tar
  setpriv --reuid 57439 --regid 57439 --clear-groups rm -f staged.tar; echo "rm -f exit=$?"'
rm: cannot remove 'staged.tar': Operation not permitted
rm -f exit=1

Note rm -f exits 1: -f suppresses ENOENT, not EPERM. Any task body using set -e therefore dies, after its inputs have already verified — so the failure looks like it is in the science when it is in the plumbing.

#555 / 4a8386f (--user "$(id -u):$(id -g)") does not fix this: it makes the container run as the instance user's numeric uid, which is a different uid from the image's user but still not the owner in the general case — and where it does match, it matches by luck of the AMI, not by construction.

Suggested fix

Make the staged file owned by whoever the container will run as. Either:

The second also removes the reason recipes must keep every staged path flat in /tmp.

Mitigation in the meantime

Don't delete staged inputs — budget for holding them. That is what my two recipes now do, with a comment, and the disk arithmetic was comfortable anyway (3.2 of ~6.1 GiB for the larger one). Worth a line in the task docs either way, because the failure mode is invisible until it isn't.

Filed from the scientific-codes-cookbook project, spawn 0.102.0 / 3db242c, AL2023 arm64, c8g.2xlarge.

Activity

  1. scttfrdmn commented on Oct 4, 2026

    @scttfrdmn
    ContributorAuthor

    Confirmed fixed on real hardware, which is the standard this issue deserved — it was reported from a real run and argued specifically that the #555 fix would not be enough.

    Ran a container task in 942542972736/us-west-2 that stages an input into sticky /tmp and deletes it with rm -f under set -e — the exact shape that killed your two recipes at the rm of an index tar:

    uid=1000 gid=1000 groups=1000
    drwxrwxrwt  11 0    0    320 Oct  4 00:49 /tmp          <- sticky 1777, as reported
    -rw-r--r--   1 1000 1000  42 Oct  4 00:49 /tmp/staged.bin
    rm exit=0
    PASS-565 staged input deleted, no EPERM
    

    On the objection in the issue

    You wrote that --user "$(id -u):$(id -g)" "does not fix this: it makes the container run as the instance user's numeric uid, which is a different uid from the image's user but still not the owner in the general case — and where it does match, it matches by luck of the AMI, not by construction."

    That was right about #555 alone, and it is what c327274 closed. Two things now make the ownership hold by construction rather than by luck:

    1. --user "$(id -u):$(id -g)" is evaluated in the same shell as stage-in, so the uid passed to docker run is definitionally the uid that ran aws s3 cp.
    2. Every staged destination gets an explicit sudo chown "$(id -u):$(id -g)" right after it lands — your own "Suggested fix" option 1. It is a same-uid no-op in practice, emitted unconditionally precisely so the invariant doesn't depend on stage-in and docker run happening to share one uninterrupted shell session.

    Sticky-bit semantics then permit the unlink, because the container owns the file rather than merely sharing the directory.

    Your second suggestion — staging into a non-sticky per-task directory instead of relying on /tmp — turned out to be the more load-bearing one, and for a different reason than ownership: #564, which the same validation run showed was not fixed. /tmp was effectively the only usable staging location because the wrapper's mkdir for any other path ran unprivileged and failed silently. That is fixed in #649 (merged), so a non-/tmp staging path now works — which also removes the reason recipes had to keep every staged path flat.

    The rm -f/EPERM detail in this report was the sharpest part of it: -f suppresses ENOENT but not EPERM, so the failure landed after the science had already succeeded and looked like a tool problem. Worth keeping in mind that the macOS reproduction caveat you noted is real — Docker Desktop doesn't enforce sticky-bit ownership, so this class can only be validated on Linux.

    Instance terminated and leak-checked; ~$0.002.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions