31 lines
1.3 KiB
Bash
31 lines
1.3 KiB
Bash
#!/usr/bin/env bash
|
|
# Check the agent can write where it keeps data, seed the OSCAL snapshot, then
|
|
# run the agent.
|
|
set -euo pipefail
|
|
|
|
# The agent runs as an unprivileged user. A volume mounted over a data
|
|
# directory keeps the ownership it was created with, so a volume made by an
|
|
# older image that ran as root is not writable. Say how to fix it instead of
|
|
# failing on the first upload.
|
|
for dir in "${ARTIFACT_STORE_BASE_PATH:?}" "${BREAKPILOT_SNAPSHOT_DIR:?}"; do
|
|
if ! mkdir -p "$dir" 2>/dev/null || [ ! -w "$dir" ]; then
|
|
echo "agent-entrypoint: $dir is not writable by uid $(id -u)." >&2
|
|
echo "agent-entrypoint: fix the volume once with: chown -R $(id -u):$(id -g) <volume>" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# Seed the OSCAL control-catalog snapshot. The image ships a catalog snapshot so
|
|
# control mapping works without the breakpilot-compliance backend
|
|
# (BREAKPILOT_BASE_URL unset). Copy-if-absent, so a snapshot refreshed from a
|
|
# live backend (or a mounted volume) always wins.
|
|
for f in /opt/breakpilot/oscal-snapshot/*.json; do
|
|
[ -e "$f" ] || continue
|
|
if [ ! -e "$BREAKPILOT_SNAPSHOT_DIR/$(basename "$f")" ]; then
|
|
cp "$f" "$BREAKPILOT_SNAPSHOT_DIR/" \
|
|
&& echo "agent-entrypoint: seeded $(basename "$f") into $BREAKPILOT_SNAPSHOT_DIR"
|
|
fi
|
|
done
|
|
|
|
exec compliance-agent "$@"
|