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

@@ -33,6 +33,14 @@ cd /mnt/DATA/git/govoplan
tools/checks/security-audit/run.sh --mode full --scope govoplan tools/checks/security-audit/run.sh --mode full --scope govoplan
``` ```
When invoked from a Flatpak development environment without a sandbox-local
Docker CLI, the wrapper automatically uses `flatpak-spawn --host docker`. The
host account must still be allowed to open the Docker daemon socket. For a
conventional rootful installation this commonly means membership in the
`docker` group followed by a complete logout/login; that membership is
root-equivalent, so rootless Docker is preferable where the deployment policy
requires a smaller privilege boundary.
Reports are written to `audit-reports/`, which is intentionally ignored by git. Reports are written to `audit-reports/`, which is intentionally ignored by git.
Each run records tool versions, report checksums, and start/end repository Each run records tool versions, report checksums, and start/end repository
revision plus worktree fingerprints. A repository change during scanning makes revision plus worktree fingerprints. A repository change during scanning makes

View File

@@ -71,6 +71,32 @@ REBUILD="${REBUILD:-0}"
UPDATE="${UPDATE:-0}" UPDATE="${UPDATE:-0}"
BUILD_ONLY="${BUILD_ONLY:-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##*/}" IMAGE_NAME="${IMAGE##*/}"
if [[ "$IMAGE_NAME" == *:* ]]; then if [[ "$IMAGE_NAME" == *:* ]]; then
IMAGE_REPOSITORY="${IMAGE%:*}" IMAGE_REPOSITORY="${IMAGE%:*}"
@@ -95,21 +121,21 @@ build_image() {
if [[ "$UPDATE" == "1" ]]; then if [[ "$UPDATE" == "1" ]]; then
build_args=(--pull --no-cache "${build_args[@]}") build_args=(--pull --no-cache "${build_args[@]}")
fi 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" echo "Building security audit toolbox image: $FINGERPRINT_IMAGE"
build_image build_image
else else
echo "Reusing security audit toolbox image: $FINGERPRINT_IMAGE" echo "Reusing security audit toolbox image: $FINGERPRINT_IMAGE"
if ! docker image inspect "$IMAGE_ALIAS" >/dev/null 2>&1; then if ! "${DOCKER_CLI[@]}" image inspect "$IMAGE_ALIAS" >/dev/null 2>&1; then
docker tag "$FINGERPRINT_IMAGE" "$IMAGE_ALIAS" "${DOCKER_CLI[@]}" tag "$FINGERPRINT_IMAGE" "$IMAGE_ALIAS"
fi fi
fi fi
if [[ "$BUILD_ONLY" == "1" ]]; then 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 exit 0
fi fi
@@ -123,7 +149,7 @@ else
EXTRA_ENV=() EXTRA_ENV=()
fi fi
docker run --rm \ "${DOCKER_CLI[@]}" run --rm \
--user "$(id -u):$(id -g)" \ --user "$(id -u):$(id -g)" \
-e HOME=/tmp/security-audit-home \ -e HOME=/tmp/security-audit-home \
-e SECURITY_AUDIT_SCOPE="$SCOPE" \ -e SECURITY_AUDIT_SCOPE="$SCOPE" \