Files
mtusi2026lab7/scripts/check-docker-hardening.sh
T
2026-11-26 23:34:55 +03:00

13 lines
516 B
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
cd "$(dirname "$0")/.."
image="${1:-postgres:16.15-alpine}"
scripts/docker.sh run --rm --network none --user "${PROBE_UID:-$(id -u)}:${PROBE_GID:-$(id -g)}" \
--read-only --cap-drop ALL --security-opt no-new-privileges:true \
--entrypoint /bin/sh "$image" -ec '
test "$(id -u)" -ne 0
grep -Eq "^NoNewPrivs:[[:space:]]+1$" /proc/self/status
grep -Eq "^CapEff:[[:space:]]+0+$" /proc/self/status
echo "PASS: non-root, read_only, cap_drop=ALL, NoNewPrivs=1"
'