Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docker/alpine/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ RUN chmod u+s /usr/local/bin/fixuid && \
chown -R docker:docker /tmp/*

USER docker:docker

RUN touch /home/docker/aaa && \
touch /home/docker/zzz
3 changes: 3 additions & 0 deletions docker/centos/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ RUN chmod u+s /usr/local/bin/fixuid && \
chown -R docker:docker /tmp/*

USER docker:docker

RUN touch /home/docker/aaa && \
touch /home/docker/zzz
3 changes: 3 additions & 0 deletions docker/debian/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ RUN chmod u+s /usr/local/bin/fixuid && \
chown -R docker:docker /tmp/*

USER docker:docker

RUN touch /home/docker/aaa && \
touch /home/docker/zzz
2 changes: 1 addition & 1 deletion docker/fs-stage/usr/local/bin/fixuid-mount-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expected_gid=$2

rc=0

files="/home/docker/tmp/test-dir /home/docker/tmp/test-dir/test-file /home/docker/tmp/test-file"
files="/home/docker/mnt-dir/test-dir /home/docker/mnt-dir/test-dir/test-file /home/docker/mnt-dir/test-file /home/docker/mnt-file"
for file in $files
do
file_uid=$(stat -c "%u" $file)
Expand Down
2 changes: 1 addition & 1 deletion docker/fs-stage/usr/local/bin/fixuid-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ then
rc=1
fi

files="/tmp/test-dir /tmp/test-dir/test-file /tmp/test-file /home/docker"
files="/tmp/test-dir /tmp/test-dir/test-file /tmp/test-file /home/docker /home/docker/aaa /home/docker/zzz"
for file in $files
do
file_user=$(stat -c "%U" $file)
Expand Down
8 changes: 7 additions & 1 deletion fixuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,13 @@ func main() {

// prevent recursing into mounts - skip if it is not the same device as /
if sys.Dev != rootDev {
return filepath.SkipDir
if sys.Uid == containerUIDUint32 && sys.Gid == containerGIDUint32 {
logger.Println("skipping mounted path " + filePath)
}
if fileInfo.IsDir() {
return filepath.SkipDir
}
return nil
}

// only chown if file is containerUID:containerGID
Expand Down
6 changes: 3 additions & 3 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ echo "\ndebian run twice entrypoint"
docker run --rm --entrypoint fixuid fixuid-debian sh -c "fixuid-test.sh docker docker && fixuid fixuid-test.sh docker docker"

echo "\nalpine should not chown mount"
docker run --rm -v $(pwd)/docker/fs-stage/tmp:/home/docker/tmp -u 1234:1234 fixuid-alpine sh -c "fixuid-test.sh docker docker && fixuid-mount-test.sh $(id -u) $(id -g)"
docker run --rm -v $(pwd)/docker/fs-stage/tmp:/home/docker/mnt-dir -v $(pwd)/docker/fs-stage/tmp/test-file:/home/docker/mnt-file -u 1234:1234 fixuid-alpine sh -c "fixuid-test.sh docker docker && fixuid-mount-test.sh $(id -u) $(id -g)"
echo "\ncentos should not chown mount"
docker run --rm -v $(pwd)/docker/fs-stage/tmp:/home/docker/tmp -u 1234:1234 fixuid-centos sh -c "fixuid-test.sh docker docker && fixuid-mount-test.sh $(id -u) $(id -g)"
docker run --rm -v $(pwd)/docker/fs-stage/tmp:/home/docker/mnt-dir -v $(pwd)/docker/fs-stage/tmp/test-file:/home/docker/mnt-file -u 1234:1234 fixuid-centos sh -c "fixuid-test.sh docker docker && fixuid-mount-test.sh $(id -u) $(id -g)"
echo "\ndebian should not chown mount"
docker run --rm -v $(pwd)/docker/fs-stage/tmp:/home/docker/tmp -u 1234:1234 fixuid-debian sh -c "fixuid-test.sh docker docker && fixuid-mount-test.sh $(id -u) $(id -g)"
docker run --rm -v $(pwd)/docker/fs-stage/tmp:/home/docker/mnt-dir -v $(pwd)/docker/fs-stage/tmp/test-file:/home/docker/mnt-file -u 1234:1234 fixuid-debian sh -c "fixuid-test.sh docker docker && fixuid-mount-test.sh $(id -u) $(id -g)"