Skip to content

fix(docker): only sudo to nobody when running as root - #2100

Open
hamodywe wants to merge 1 commit into
supabase:mainfrom
hamodywe:fix/run-sh-non-root
Open

fix(docker): only sudo to nobody when running as root#2100
hamodywe wants to merge 1 commit into
supabase:mainfrom
hamodywe:fix/run-sh-non-root

Conversation

@hamodywe

Copy link
Copy Markdown

Closes #2063.

run.sh drops to nobody with an unconditional sudo before running migrations and the self-host seed. The image sets no USER, so the container normally starts as root and that works.

It breaks under an orchestrator that already starts the container as a non-root user. With Kubernetes runAsNonRoot: true and allowPrivilegeEscalation: false, the kernel ignores sudo's setuid bit, so the call fails and the container never starts.

This guards both calls on the effective uid: when we are root, drop to nobody exactly as before; when we are already unprivileged, run the command directly, since there is nothing to drop. Since the image sets no USER, this only changes behaviour for orchestrators that already override the runtime UID.

Verification

Built an image mirroring this one (sudo installed, /app owned by nobody, no USER) and ran both paths:

  • Started as root: migrate runs as nobody (uid 65534) both before and after the change — behaviour unchanged.
  • Started with --user 1000:1000 --security-opt no-new-privileges --cap-drop ALL: the current code fails with sudo: The "no new privileges" flag is set, which prevents sudo from running as root (exit 1), while the guarded version runs as uid 1000 (exit 0).

bash -n run.sh is clean.

run.sh drops to `nobody` with an unconditional `sudo` before running
migrations and the self-host seed. The image sets no USER, so the
container normally starts as root and that works.

It breaks under an orchestrator that already starts the container as a
non-root user. With Kubernetes `runAsNonRoot: true` and
`allowPrivilegeEscalation: false`, the kernel ignores sudo's setuid bit,
so the call fails and the container never starts.

Guard both calls on the effective uid: when we are root, drop to nobody
exactly as before; when we are already unprivileged, run the command
directly, since there is nothing to drop.

Verified in containers: started as root, migrate still runs as nobody
(uid 65534) with and without this change. Started with --user 1000:1000
--security-opt no-new-privileges, the old call fails with sudo's "no new
privileges" error while the guarded one runs as uid 1000.
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.

Error running on Kubernetes with runAsNonRoot: true and allowPrivilegeEscalation: false

1 participant