fix(docker): allow explicit root for restricted sockets (#3558)

This commit is contained in:
Alexy Grabov authored and GitHub committed 2026-09-13 19:35:01 -05:00
1 parent 24e13f3831
commit d8e7382d5b
3 files changed
+63 -5

No files matched your search

+3 -1
View File
@@ -36,7 +36,9 @@ if [ "$(id -u)" = '0' ]; then
# group. Supplementary groups are set by number, so the group needs no /etc/group entry.
# --skip-chdir keeps the working directory (/app, where relative data paths resolve); GNU
# chroot would otherwise chdir to the new root.
exec chroot --userspec=1001:0 --groups="$groups" --skip-chdir / "$0" "$@"
if [ "${FLOCI_RUN_AS_ROOT:-false}" != 'true' ]; then
exec chroot --userspec=1001:0 --groups="$groups" --skip-chdir / "$0" "$@"
fi
fi
if [ "${LOCALSTACK_PARITY:-true}" != "false" ]; then
+37 -4
View File
@@ -3,10 +3,8 @@
# Run directly: sh docker/test-entrypoint.sh
# Exit 0 on success, non-zero on first failure summary.
#
# These tests run the entrypoint as an unprivileged user with
# LOCALSTACK_PARITY=false, so the root-only chroot block and the parity
# script (installed at an absolute path inside the image) stay out of
# the way. The root/chroot path is covered by the Docker image tests.
# These tests run as an unprivileged user with LOCALSTACK_PARITY=false.
# Stub id and chroot to check the root path without changing privileges.
set -eu
@@ -41,6 +39,41 @@ printf '%s\n' "java $*"
EOF
chmod +x "${WORK}/bin/java"
mkdir -p "${WORK}/root-bin"
cat > "${WORK}/root-bin/id" <<'EOF'
#!/bin/sh
if [ "$1" = '-u' ]; then
printf '0\n'
else
/usr/bin/id "$@"
fi
EOF
cat > "${WORK}/root-bin/chroot" <<'EOF'
#!/bin/sh
printf 'dropped privileges\n'
EOF
chmod +x "${WORK}/root-bin/id" "${WORK}/root-bin/chroot"
assert_eq "root drops privileges by default" \
"dropped privileges" \
"$(PATH="${WORK}/root-bin:${PATH}" FLOCI_STORAGE_PERSISTENT_PATH="${WORK}/absent" LOCALSTACK_PARITY=false sh "${SCRIPT}" echo preserved)"
assert_eq "false keeps the unprivileged default" \
"dropped privileges" \
"$(PATH="${WORK}/root-bin:${PATH}" FLOCI_RUN_AS_ROOT=false FLOCI_STORAGE_PERSISTENT_PATH="${WORK}/absent" LOCALSTACK_PARITY=false sh "${SCRIPT}" echo preserved)"
assert_eq "other values keep the unprivileged default" \
"dropped privileges" \
"$(PATH="${WORK}/root-bin:${PATH}" FLOCI_RUN_AS_ROOT=TRUE FLOCI_STORAGE_PERSISTENT_PATH="${WORK}/absent" LOCALSTACK_PARITY=false sh "${SCRIPT}" echo preserved)"
assert_eq "explicit root option preserves command arguments" \
"one two|three" \
"$(PATH="${WORK}/root-bin:${PATH}" FLOCI_RUN_AS_ROOT=true FLOCI_STORAGE_PERSISTENT_PATH="${WORK}/absent" LOCALSTACK_PARITY=false sh "${SCRIPT}" sh -c 'printf "%s|%s\n" "$1" "$2"' _ "one two" three)"
assert_eq "non-root process cannot elevate with root option" \
"one two" \
"$(FLOCI_RUN_AS_ROOT=true LOCALSTACK_PARITY=false sh "${SCRIPT}" echo one two)"
# --- explicit arguments are exec'd unchanged ---
assert_eq "explicit command is exec'd unchanged" \
"one two" \
+23
View File
@@ -25,6 +25,29 @@ services:
- /var/run/docker.sock:/var/run/docker.sock
```
The container normally switches to the unprivileged `floci` user (UID 1001), including when started with `--user root`. If the mounted socket is accessible only to root, set the entrypoint option `FLOCI_RUN_AS_ROOT=true` to keep Floci running as root:
```bash
docker run --rm -p 4566:4566 \
-v /var/run/docker.sock:/var/run/docker.sock \
-e FLOCI_RUN_AS_ROOT=true \
floci/floci:latest
```
In Docker Compose, use the same environment variable:
```yaml
services:
floci:
image: floci/floci:latest
volumes:
- /var/run/docker.sock:/var/run/docker.sock
environment:
FLOCI_RUN_AS_ROOT: "true"
```
Use this only when the socket's permissions require root. Without the option, Floci retains its unprivileged default. The setting applies to the container entrypoint, not to `floci.docker` configuration.
## Private Registry Authentication
Any service that pulls a container image from a private registry (Lambda image functions, custom OpenSearch images, private Postgres images, etc.) needs Docker credentials. Two approaches are supported and can be combined.