fix: copy sudo binary before setting setuid bit#9
Merged
megheaiulian merged 1 commit intomainfrom Feb 10, 2026
Merged
Conversation
symlinkJoin creates ./bin/sudo as a symlink into the Nix store. tar (without --dereference) archives symlinks as-is, so the fakeroot-tracked setuid bit on the target is silently lost. Replace the symlink with a real copy of the binary so that fakeroot can record mode 4755 on a regular file and tar faithfully preserves it in the Docker layer.
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.
Summary
/bin/sudo must be owned by uid 0 and have the setuid bit setwhen using the Nix image in Coder.symlinkJoincreates./bin/sudoas a symlink into the Nix store.tar(without--dereference) archives symlinks as-is, so thefakeroot-tracked setuid bit on the target is silently lost. This addscp --remove-destinationbeforechmod 4755to replace the symlink with a real file copy that tar can faithfully archive with the setuid bit preserved.Root Cause
buildLayeredImageWithNixDbusessymlinkJoininternally, which creates./bin/sudoas a symlink pointing to/nix/store/...-sudo-.../bin/sudo. ThefakeRootCommandsblock runs underfakeroot, and the resulting tar is created with--hard-dereferencebut not--dereference. Since--hard-dereferenceonly affects hard links (not symlinks), the symlink is archived as-is and symlinks in tar don't carry permission bits — the setuid bit set bychmod 4755is lost.Fix
Replace the symlink with a real copy of the binary before setting the setuid bit:
cp --remove-destination "$(readlink -f ./bin/sudo)" ./bin/sudo chmod 4755 ./bin/sudo