fix(docker): only sudo to nobody when running as root - #2100
Open
hamodywe wants to merge 1 commit into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2063.
run.shdrops tonobodywith an unconditionalsudobefore running migrations and the self-host seed. The image sets noUSER, 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: trueandallowPrivilegeEscalation: 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
nobodyexactly as before; when we are already unprivileged, run the command directly, since there is nothing to drop. Since the image sets noUSER, this only changes behaviour for orchestrators that already override the runtime UID.Verification
Built an image mirroring this one (sudo installed,
/appowned bynobody, noUSER) and ran both paths:nobody(uid 65534) both before and after the change — behaviour unchanged.--user 1000:1000 --security-opt no-new-privileges --cap-drop ALL: the current code fails withsudo: 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.shis clean.