Skip to content

bug: enableUserNamespaces causes sandbox creation to fail with "setgroups: Invalid argument" #2520

Description

@2000krysztof

Agent Diagnostic

Skills loaded: debug-openshell-cluster create-github-issue

Investigation findings:

Testing confirmation:

  • Tested on OpenShift with enableUserNamespaces=false: ✅ SUCCESS
  • Tested on OpenShift with enableUserNamespaces=true: ❌ FAILS with "setgroups: Invalid argument"

Root cause analysis:

When server.enableUserNamespaces=true, the Kubernetes driver correctly sets hostUsers: false and adds SETUID/SETGID capabilities. However, the supervisor's drop_privileges() function unconditionally calls initgroups() when dropping to a named user identity.

In Kubernetes user namespaces (hostUsers: false):

  1. Container runtime creates user namespace and writes /proc/<pid>/gid_map
  2. Kernel sets /proc/<pid>/setgroups to "deny" (privilege escalation prevention)
  3. Once gid_map is written, /proc/self/setgroups cannot be changed to "allow"
  4. Supervisor calls initgroups() → internally calls setgroups() → fails with EINVAL
  5. Container exits during startup

Technical details:

  • File: crates/openshell-supervisor-process/src/process.rs
  • Line: 1431 - nix::unistd::initgroups(user_cstr.as_c_str(), target_gid).into_diagnostic()?;
  • Call is only skipped on macOS/iOS/Haiku/Redox, not for Linux user namespaces
  • No detection of /proc/self/setgroups restriction exists

Proposed fix:

Before calling initgroups(), check if /proc/self/setgroups contains "deny". If so, skip the initgroups() call. In user namespace context, supplementary groups are already appropriately isolated, so skipping is safe.

Note: Original feature commit 1f35abbe claimed validation on OCP 4.22, but current testing shows the feature is broken on OpenShift.

Description

Actual behavior: When deploying OpenShell with --set server.enableUserNamespaces=true, all sandbox creation attempts fail during container startup with Error: container create failed: setgroups: Invalid argument.

Expected behavior: Sandboxes should start successfully with user namespace isolation enabled, providing defense-in-depth by mapping container UID 0 to an unprivileged host UID.

Reproduction Steps

  1. Deploy with user namespaces enabled:

    helm install openshell deploy/helm/openshell \
      --namespace openshell \
      --create-namespace \
      --set server.enableUserNamespaces=true \
      --wait
  2. Attempt to create a sandbox:

    openshell sandbox create --name test
  3. Observe failure:

    Created sandbox: test
    ✓ Sandbox allocated (3s)
    ✓ Image pulled (8s)
    ⠄ Starting sandbox... Error: container create failed: setgroups: Invalid argument (5s)
    

Environment

Logs

Expected container logs when inspecting the failed sandbox pod:

Error: setgroups: Invalid argument

Kernel behavior:

# Inside a user namespace pod (hostUsers: false)
$ cat /proc/self/setgroups
deny

# Attempting setgroups() in this state returns EINVAL

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions