fix(audit): bridge Docker from Flatpak sandboxes

This commit is contained in:
2026-07-22 04:48:10 +02:00
parent 8906704dc0
commit d53db2da06
2 changed files with 40 additions and 6 deletions

View File

@@ -71,6 +71,32 @@ REBUILD="${REBUILD:-0}"
UPDATE="${UPDATE:-0}"
BUILD_ONLY="${BUILD_ONLY:-0}"
declare -a DOCKER_CLI=()
DOCKER_LOCATION=""
if command -v docker >/dev/null 2>&1; then
DOCKER_CLI=(docker)
DOCKER_LOCATION="current environment"
elif command -v flatpak-spawn >/dev/null 2>&1 \
&& flatpak-spawn --host sh -lc 'command -v docker >/dev/null 2>&1'; then
DOCKER_CLI=(flatpak-spawn --host docker)
DOCKER_LOCATION="Flatpak host"
else
echo "Docker is not available in this environment or through a Flatpak host bridge." >&2
echo "Install Docker, expose its CLI/socket, or run this script from the host." >&2
exit 1
fi
if ! DOCKER_VERSION_OUTPUT="$("${DOCKER_CLI[@]}" version --format '{{.Server.Version}}' 2>&1)"; then
echo "Docker was found on the $DOCKER_LOCATION, but its daemon is not accessible:" >&2
printf ' %s\n' "$DOCKER_VERSION_OUTPUT" >&2
if [[ "$DOCKER_LOCATION" == "Flatpak host" && "$DOCKER_VERSION_OUTPUT" == *"permission denied"* ]]; then
echo "Grant the host account access to the Docker socket, then fully log out and back in." >&2
echo "On a conventional rootful Docker installation: sudo usermod -aG docker \"$(id -un)\"" >&2
echo "Membership in the docker group is root-equivalent; use rootless Docker instead where that is preferred." >&2
fi
exit 1
fi
IMAGE_NAME="${IMAGE##*/}"
if [[ "$IMAGE_NAME" == *:* ]]; then
IMAGE_REPOSITORY="${IMAGE%:*}"
@@ -95,21 +121,21 @@ build_image() {
if [[ "$UPDATE" == "1" ]]; then
build_args=(--pull --no-cache "${build_args[@]}")
fi
docker build "${build_args[@]}" "$ROOT"
"${DOCKER_CLI[@]}" build "${build_args[@]}" "$ROOT"
}
if [[ "$REBUILD" == "1" ]] || ! docker image inspect "$FINGERPRINT_IMAGE" >/dev/null 2>&1; then
if [[ "$REBUILD" == "1" ]] || ! "${DOCKER_CLI[@]}" image inspect "$FINGERPRINT_IMAGE" >/dev/null 2>&1; then
echo "Building security audit toolbox image: $FINGERPRINT_IMAGE"
build_image
else
echo "Reusing security audit toolbox image: $FINGERPRINT_IMAGE"
if ! docker image inspect "$IMAGE_ALIAS" >/dev/null 2>&1; then
docker tag "$FINGERPRINT_IMAGE" "$IMAGE_ALIAS"
if ! "${DOCKER_CLI[@]}" image inspect "$IMAGE_ALIAS" >/dev/null 2>&1; then
"${DOCKER_CLI[@]}" tag "$FINGERPRINT_IMAGE" "$IMAGE_ALIAS"
fi
fi
if [[ "$BUILD_ONLY" == "1" ]]; then
docker image inspect "$FINGERPRINT_IMAGE" --format 'Built audit toolbox image {{.RepoTags}} {{.Id}}'
"${DOCKER_CLI[@]}" image inspect "$FINGERPRINT_IMAGE" --format 'Built audit toolbox image {{.RepoTags}} {{.Id}}'
exit 0
fi
@@ -123,7 +149,7 @@ else
EXTRA_ENV=()
fi
docker run --rm \
"${DOCKER_CLI[@]}" run --rm \
--user "$(id -u):$(id -g)" \
-e HOME=/tmp/security-audit-home \
-e SECURITY_AUDIT_SCOPE="$SCOPE" \