Skip to content

Task container ignores docker.runOptions and runs as non-root in a root-owned work dir → "Permission denied" #39

Closed

Description

@scttfrdmn

Summary

After #37/#38 fixed input staging, a containerized nf-core task now finds its inputs but fails to write its work dir:

ln: failed to create symbolic link 'SRR059377_stool_SRR059377_raw_1.gz': Permission denied
.command.sh: line 12: versions.yml: Permission denied

(FASTQC, exit 1.)

Two interacting causes in SpawnTaskHandler:

  1. buildRunLine ignores Nextflow's docker.runOptions. It emits a fixed argv:

    'docker run --rm -v "${LOCAL_DIR}":"${LOCAL_DIR}" -w "${LOCAL_DIR}" ' + image + ' bash .command.sh ...'

    So a pipeline's docker { runOptions = '--user root' } (and any other run options) is silently dropped. The container therefore runs as the image's default user — which for biocontainers/nf-core images is typically a non-root user.

  2. The work dir is root-owned. buildStagingScript does sudo mkdir -p "${LOCAL_DIR}" && sudo chown "$(id -u):$(id -g)" "${LOCAL_DIR}" — and the staging script runs as root (EC2 user-data), so id -u is 0 → /var/lib/nf-work is owned by root. The staged input files (aws s3 cp, also root) are root-owned too.

Net: a non-root container process is -w'd into a root-owned dir and can't create the symlinks .command.sh makes, nor write versions.yml. Every stock module that symlinks inputs or writes outputs into the task dir hits this.

Note the only process that works is one that sets its container user itself or runs tooling as root inside its own script — i.e. the same self-help pattern that masked #37.

Repro

nf-spawn 0.2.9, Nextflow 26.04.x, AL2023 arm64, workDir = s3://…, a process with a container directive and docker { runOptions = '--user root' } in config (e.g. nf-core/taxprofiler FASTQC). Input staging succeeds (#38); the task fails at the first write with Permission denied.

Suggested fix (either, or both)

  1. Honor docker.runOptions (and ideally the other docker {} scope settings) in buildRunLine, e.g. splice task.config.getContainerOptions() / the session's docker.runOptions into the docker run argv. That alone fixes the reported case (--user root → container is root → can write the root-owned dir).
  2. Make the work dir writable by the container user regardless — e.g. chmod 0777 "${LOCAL_DIR}" after staging (or run the container with --user $(id -u):$(id -g) and own the dir to that uid). Belt-and-suspenders for images whose default user is non-root and pipelines that don't set --user root.

(1) restores expected Nextflow semantics; (2) avoids surprising users who rely on the image's default user. Doing both is probably ideal.

Context

Found validating #38 against the aws-microbiome-demo taxprofiler pipeline (the #37 reporter). Good news in the same run: #38's input staging works (FASTQC now finds its reads), and the native arm64 container pulled and ran fine — this permissions gap is the next thing in the way. Happy to test a fix; same one-line plugin-version bump on my side.

  • Observed 2026-06-13. nf-spawn 0.2.9.

Activity

  1. added
    bug
    on Jun 13, 2026
  2. scttfrdmn commented on Jun 13, 2026

    @scttfrdmn
    CollaboratorAuthor

    Fixed and released in v0.2.10 (#40) — ZIP is live: https://github.com/spore-host/nf-spawn/releases/tag/v0.2.10

    Did both halves you recommended:

    1. Honors run options. A new resolveDockerRunOptions(task) collects both docker.runOptions (engine scope, from the task's ContainerConfig) and the per-process containerOptions directive, and buildRunLine now splices them verbatim before the image — so --user root (or anything else you set) is applied.
    2. Work dir is writable regardless. The staging script chmod 0777s the work dir before the container runs, so even a non-root image user can write its outputs into the bind-mounted dir.

    Both are best-effort/null-safe: if options can't be resolved, the task just runs with none (prior behavior) rather than aborting.

    To re-validate: bump your TARGET_NF_SPAWN_VERSION to 0.2.10. This should clear the Permission denied you hit on FASTQC. If that unblocks it, the remaining open thread is the .gz rename caveat from #37 — let me know if it still bites once the run completes end-to-end.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions