sandbox: detect Podman via platform name and accept symlinked sockets

docker version has no .Server.Engine field, so the previous check never
matched. Read .Server.Platform.Name instead and run detection even when
DOCKER_HOST is explicit, so the unverified-Podman warning also fires for
the common compat-socket setup.

Docker Desktop publishes /var/run/docker.sock as a symlink, so stop
refusing symlinked sockets; test -S follows them and find -L checks the
target's mode.
This commit is contained in:
00xcyd 2026-12-02 21:15:03 +00:00
parent e9c8a988b0
commit 0fd8ff579f
3 changed files with 68 additions and 53 deletions

View file

@ -204,45 +204,44 @@ resolve_docker_sock(){
DOCKER_ENGINE_PODMAN=0
case "${DOCKER_HOST:-}" in
"") ;;
unix://*) ;;
unix://*) sock="${DOCKER_HOST#unix://}" ;;
*) die "the sandbox runner needs a local Unix Docker socket, but DOCKER_HOST=${DOCKER_HOST} cannot be mounted into a container. Unset DOCKER_HOST or point it at a unix:// socket" ;;
esac
# An explicit Unix DOCKER_HOST is authoritative; only resolve from the engine
# when the operator has not named a socket.
if [ -n "${DOCKER_HOST:-}" ]; then
sock="${DOCKER_HOST#unix://}"
fi
# The CLI has no .Server.Engine field; the platform name is where Docker and
# Podman identify themselves ("Docker Engine - Community", "Podman Engine").
# Detection also runs for an explicit DOCKER_HOST so the warning below covers
# the common Podman-compat setup.
engine="$(docker version --format '{{.Server.Platform.Name}}' 2>/dev/null || true)"
case "$engine" in
*[Pp]odman*) DOCKER_ENGINE_PODMAN=1 ;;
esac
# Podman advertises itself in docker version output even through its compat
# socket, so ask it where the API socket actually is.
if [ -z "$sock" ]; then
engine="$(docker version --format '{{.Server.Engine}}' 2>/dev/null || true)"
case "$engine" in
*podman*)
DOCKER_ENGINE_PODMAN=1
if command -v podman >/dev/null 2>&1; then
sock="$(podman info --format '{{.Host.RemoteSocket.Path}}' 2>/dev/null || true)"
fi
[ -n "$sock" ] || sock="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/podman/podman.sock"
;;
esac
# Podman advertises a Docker-compatible socket; ask it where its API socket
# actually is instead of assuming the Docker default.
if [ "$DOCKER_ENGINE_PODMAN" = 1 ] && [ -z "$sock" ]; then
if command -v podman >/dev/null 2>&1; then
sock="$(podman info --format '{{.Host.RemoteSocket.Path}}' 2>/dev/null || true)"
fi
[ -n "$sock" ] || sock="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/podman/podman.sock"
fi
[ -n "$sock" ] || sock="/var/run/docker.sock"
if [ -L "$sock" ]; then
die "refusing a symlinked Docker API socket: $sock"
fi
# Docker Desktop on macOS publishes /var/run/docker.sock as a symlink into
# ~/.docker/run, so follow it (test -S and find -L) instead of refusing it.
if [ ! -S "$sock" ]; then
die "no Docker API socket at $sock; if the engine uses another path, set DOCKER_HOST=unix:///path/to.sock and rerun (issue #742)"
fi
if [ ! -r "$sock" ] || [ ! -w "$sock" ]; then
die "the Docker API socket $sock is not readable and writable by $(id -un); add that user to the engine's group or run a rootless engine"
fi
if find "$sock" -maxdepth 0 -perm -0002 2>/dev/null | grep -q .; then
if find -L "$sock" -maxdepth 0 -perm -0002 2>/dev/null | grep -q .; then
die "the Docker API socket $sock is world-writable; run 'chmod o-w $sock' and rerun"
fi
DOCKER_SOCK_RESOLVED="$sock"
if [ "$DOCKER_ENGINE_PODMAN" = 1 ]; then
warn "Podman detected: the API socket is supported, but task networking, cgroup limits and port publishing are not verified yet (#742); run one task and report what breaks"
fi
}
# persist_docker_sock records the resolved socket in .env. The default path is
@ -256,9 +255,6 @@ persist_docker_sock(){
fi
set_env ARTEX_DOCKER_SOCK "$DOCKER_SOCK_RESOLVED"
ok "Docker API socket: $DOCKER_SOCK_RESOLVED"
if [ "$DOCKER_ENGINE_PODMAN" = 1 ]; then
warn "rootless Podman: the API socket is supported, but task networking, cgroup limits and port publishing are not verified yet (#742); run one task and report what breaks"
fi
}
# ensure_docker_engine refuses a container engine the sandbox cannot use, before

View file

@ -11,8 +11,10 @@ ok_case(){ pass=$((pass+1)); printf ' ok %s\n' "$1"; }
bad_case(){ fail=$((fail+1)); printf ' FAIL %s\n' "$1"; }
die(){ printf '%s\n' "$*" >&2; exit 1; }
ok(){ :; }
warn(){ :; }
warnings=""
warn(){ warnings="$warnings $*"; }
set_env(){ printf 'SET_ENV %s=%s\n' "$1" "$2"; }
unset DOCKER_HOST
env_backup=""
if [ -f .env ]; then env_backup="$(mktemp)"; cp .env "$env_backup"; else : > .env; fi
@ -71,5 +73,26 @@ resolve_docker_sock
[ "$DOCKER_SOCK_RESOLVED" = "$sock_path" ] \
&& ok_case "unix DOCKER_HOST honoured" || bad_case "unix DOCKER_HOST honoured (got: $DOCKER_SOCK_RESOLVED)"
# 5. A symlinked socket is accepted (Docker Desktop publishes one on macOS).
sock_link="$sock_dir/docker.sock"
ln -s "$sock_path" "$sock_link"
export DOCKER_HOST="unix://$sock_link"
resolve_docker_sock
[ "$DOCKER_SOCK_RESOLVED" = "$sock_link" ] \
&& ok_case "symlinked socket accepted" || bad_case "symlinked socket accepted (got: $DOCKER_SOCK_RESOLVED)"
# 6. An explicit DOCKER_HOST served by Podman still warns that it is unverified.
export DOCKER_HOST="unix://$sock_path"
warnings=""
docker(){ echo "Podman Engine"; }
podman(){ return 1; }
resolve_docker_sock
[ "$DOCKER_ENGINE_PODMAN" = 1 ] && [ "$DOCKER_SOCK_RESOLVED" = "$sock_path" ] \
&& ok_case "explicit Podman DOCKER_HOST detected" || bad_case "explicit Podman DOCKER_HOST detected"
case "$warnings" in
*"not verified"*) ok_case "explicit Podman DOCKER_HOST warns" ;;
*) bad_case "explicit Podman DOCKER_HOST warns (got: $warnings)" ;;
esac
printf '\n%d passed, %d failed\n' "$pass" "$fail"
[ "$fail" -eq 0 ]

View file

@ -101,45 +101,44 @@ resolve_docker_sock(){
DOCKER_ENGINE_PODMAN=0
case "${DOCKER_HOST:-}" in
"") ;;
unix://*) ;;
unix://*) sock="${DOCKER_HOST#unix://}" ;;
*) die "the sandbox runner needs a local Unix Docker socket, but DOCKER_HOST=${DOCKER_HOST} cannot be mounted into a container. Unset DOCKER_HOST or point it at a unix:// socket" ;;
esac
# An explicit Unix DOCKER_HOST is authoritative; only resolve from the engine
# when the operator has not named a socket.
if [ -n "${DOCKER_HOST:-}" ]; then
sock="${DOCKER_HOST#unix://}"
fi
# The CLI has no .Server.Engine field; the platform name is where Docker and
# Podman identify themselves ("Docker Engine - Community", "Podman Engine").
# Detection also runs for an explicit DOCKER_HOST so the warning below covers
# the common Podman-compat setup.
engine="$(docker version --format '{{.Server.Platform.Name}}' 2>/dev/null || true)"
case "$engine" in
*[Pp]odman*) DOCKER_ENGINE_PODMAN=1 ;;
esac
# Podman advertises itself in docker version output even through its compat
# socket, so ask it where the API socket actually is.
if [ -z "$sock" ]; then
engine="$(docker version --format '{{.Server.Engine}}' 2>/dev/null || true)"
case "$engine" in
*podman*)
DOCKER_ENGINE_PODMAN=1
if command -v podman >/dev/null 2>&1; then
sock="$(podman info --format '{{.Host.RemoteSocket.Path}}' 2>/dev/null || true)"
fi
[ -n "$sock" ] || sock="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/podman/podman.sock"
;;
esac
# Podman advertises a Docker-compatible socket; ask it where its API socket
# actually is instead of assuming the Docker default.
if [ "$DOCKER_ENGINE_PODMAN" = 1 ] && [ -z "$sock" ]; then
if command -v podman >/dev/null 2>&1; then
sock="$(podman info --format '{{.Host.RemoteSocket.Path}}' 2>/dev/null || true)"
fi
[ -n "$sock" ] || sock="${XDG_RUNTIME_DIR:-/run/user/$(id -u)}/podman/podman.sock"
fi
[ -n "$sock" ] || sock="/var/run/docker.sock"
if [ -L "$sock" ]; then
die "refusing a symlinked Docker API socket: $sock"
fi
# Docker Desktop on macOS publishes /var/run/docker.sock as a symlink into
# ~/.docker/run, so follow it (test -S and find -L) instead of refusing it.
if [ ! -S "$sock" ]; then
die "no Docker API socket at $sock; if the engine uses another path, set DOCKER_HOST=unix:///path/to.sock and rerun (issue #742)"
fi
if [ ! -r "$sock" ] || [ ! -w "$sock" ]; then
die "the Docker API socket $sock is not readable and writable by $(id -un); add that user to the engine's group or run a rootless engine"
fi
if find "$sock" -maxdepth 0 -perm -0002 2>/dev/null | grep -q .; then
if find -L "$sock" -maxdepth 0 -perm -0002 2>/dev/null | grep -q .; then
die "the Docker API socket $sock is world-writable; run 'chmod o-w $sock' and rerun"
fi
DOCKER_SOCK_RESOLVED="$sock"
if [ "$DOCKER_ENGINE_PODMAN" = 1 ]; then
warn "Podman detected: the API socket is supported, but task networking, cgroup limits and port publishing are not verified yet (#742); run one task and report what breaks"
fi
}
# persist_docker_sock records the resolved socket in .env. The default path is
@ -153,9 +152,6 @@ persist_docker_sock(){
fi
set_env ARTEX_DOCKER_SOCK "$DOCKER_SOCK_RESOLVED"
ok "Docker API socket: $DOCKER_SOCK_RESOLVED"
if [ "$DOCKER_ENGINE_PODMAN" = 1 ]; then
warn "rootless Podman: the API socket is supported, but task networking, cgroup limits and port publishing are not verified yet (#742); run one task and report what breaks"
fi
}
# ensure_docker_engine refuses a container engine the sandbox cannot use, before