Skip to content

fix(docker): skip gosu when running as non-root#2618

Open
ArtificialXai wants to merge 1 commit intoopentensor:devnet-readyfrom
ArtificialXai:artificialxai/dockerfile-optional-gosu
Open

fix(docker): skip gosu when running as non-root#2618
ArtificialXai wants to merge 1 commit intoopentensor:devnet-readyfrom
ArtificialXai:artificialxai/dockerfile-optional-gosu

Conversation

@ArtificialXai
Copy link
Copy Markdown

Summary

scripts/docker_entrypoint.sh unconditionally runs chown -R and exec gosu subtensor ..., which fails when the container itself is already running as a non-root user (e.g. a Kubernetes pod with securityContext.runAsUser: 10001 and externally-managed filesystem permissions). The container exits with operation not permitted before node-subtensor ever starts.

This PR wraps the privilege-changing branch in an id -u check:

  • As root (existing behavior, unchanged): chown the data dir + chain spec + /tmp/blockchain, then exec gosu subtensor node-subtensor "$@".
  • As non-root (new path): log the detected UID and exec node-subtensor "$@" directly.

This makes gosu effectively optional via auto-detection — no new flag or env var, no API surface change. Existing deployments that mount /data as root keep working bit-for-bit.

Closes #2475.

Diff size

scripts/docker_entrypoint.sh only — +27 / -15. No code changes anywhere else, no Cargo/runtime impact, no spec_version bump.

Test plan

  • sh -n scripts/docker_entrypoint.sh — clean.
  • Simulated root path: still echoes "ensuring permissions for base path" + "executing: gosu subtensor node-subtensor ...".
  • Simulated non-root path (UID 10001): echoes "running as non-root UID 10001; skipping chown + gosu" then "executing: node-subtensor ...".
  • Reviewer build of the Docker image and run with --user 10001 to confirm behavior end-to-end.

When the entrypoint detects it is already running as a non-root
UID (e.g. a Kubernetes pod with runAsUser: 10001 and externally
managed filesystem permissions), chown -R and gosu subtensor
both fail with "operation not permitted" and the container exits
before node-subtensor is ever executed.

Wrap the existing privilege-changing branch in an id -u check.
Root operators see no behavior change; non-root operators get a
clean exec without any chown/gosu calls.

This makes gosu effectively optional via auto-detection rather
than a new container flag, so existing deployments that mount
/data as root continue to work unchanged.

Closes opentensor#2475.
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.

1 participant