Light, fluffy, and always free - The AWS Local Emulator alternative
fix(docker): allow explicit root for restricted sockets (#3558)
Alexy Grabovd8e7382d5bef
diff --git a/docker/entrypoint.sh b/docker/entrypoint.shindex 0667cd98f7..b1393e5591 100755--- a/docker/entrypoint.sh+++ b/docker/entrypoint.sh@@ -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" "$@"+ fifiif [ "${LOCALSTACK_PARITY:-true}" != "false" ]; thendiff --git a/docker/test-entrypoint.sh b/docker/test-entrypoint.shindex 3307c92c0a..f8ab5c1148 100644--- a/docker/test-entrypoint.sh+++ b/docker/test-entrypoint.sh@@ -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 $*"EOFchmod +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" \diff --git a/docs/configuration/docker.md b/docs/configuration/docker.mdindex fa7839ac6e..5a459d7d95 100644--- a/docs/configuration/docker.md+++ b/docs/configuration/docker.md@@ -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 AuthenticationAny 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.