Skip to content

feat: make gosu optional in docker entrypoint for hardened containers#2495

Open
R-Panic wants to merge 1 commit intoopentensor:mainfrom
R-Panic:main
Open

feat: make gosu optional in docker entrypoint for hardened containers#2495
R-Panic wants to merge 1 commit intoopentensor:mainfrom
R-Panic:main

Conversation

@R-Panic
Copy link

@R-Panic R-Panic commented Mar 12, 2026

Description

Fixes issue where containers running with hardened security context (non-root user) fail because gosu cannot switch users from a non-root context.

Problem

When Kubernetes/OCP securityContext specifies:

securityContext:
  runAsUser: 10001
  runAsGroup: 10001
  fsGroup: 10001
  runAsNonRoot: false

The entrypoint fails with:

error: failed switching to "subtensor": operation not permitted

Solution

  1. Auto-detect if already running as subtensor user and skip gosu
  2. Add SKIP_GOSU=true environment variable for explicit control
  3. Maintain backward compatibility with root-to-non-root transitions

Changes

scripts/docker_entrypoint.sh:

  • Check current user before calling gosu
  • Skip gosu if running as subtensor user or SKIP_GOSU=true

Testing

  • Backward compatible: root containers still use gosu
  • Non-root containers with subtensor user skip gosu
  • Works with Kubernetes hardened security contexts
  • SKIP_GOSU=true provides explicit override

Fixes #2475

Signed-off-by: R-Panic bot@term.com

When containers run with hardened security context (runAsUser: 10001,
runAsGroup: 10001), the entrypoint fails because gosu cannot switch
users from non-root.

Changes:
- Auto-detect if already running as subtensor user and skip gosu
- Add SKIP_GOSU environment variable to explicitly skip gosu
- Maintains backward compatibility with root-to-non-root transitions

Fixes opentensor#2475

Signed-off-by: R-Panic <bot@term.com>
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.

Make gosu optional in Dockerfile for already hardened security context environments

1 participant