This commit is contained in:
@@ -6,5 +6,7 @@ script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
repo_dir=$(CDPATH= cd -- "$script_dir/.." && pwd)
|
||||
env_file=${ENV_FILE:-$repo_dir/lab7.env.example}
|
||||
|
||||
"$script_dir/sync-docker-workspace.sh"
|
||||
|
||||
exec docker compose --project-directory "$repo_dir" --env-file "$env_file" run --rm --no-deps -T \
|
||||
-v "$repo_dir:$repo_dir:ro" openbao-cli "$@"
|
||||
|
||||
@@ -20,14 +20,17 @@ if [ ! -f "$repo_dir/.runtime/security/openbao/tls.crt" ]; then
|
||||
fi
|
||||
|
||||
"$script_dir/openbao-seed.sh" "$env_file"
|
||||
"$script_dir/sync-docker-workspace.sh"
|
||||
compose up -d security-bootstrap openbao-permissions openbao
|
||||
openbao_address=$(compose port openbao 8200)
|
||||
BAO_ADDR="https://$openbao_address"
|
||||
if [ -z "${BAO_ADDR:-}" ]; then
|
||||
openbao_address=$(compose port openbao 8200)
|
||||
BAO_ADDR="https://$openbao_address"
|
||||
fi
|
||||
BAO_CACERT="$repo_dir/.runtime/security/openbao/ca.crt"
|
||||
export BAO_ADDR BAO_CACERT ENV_FILE="$env_file"
|
||||
|
||||
remaining=60
|
||||
until curl --silent --show-error --cacert "$BAO_CACERT" \
|
||||
until curl --silent --show-error --connect-timeout 2 --max-time 3 --cacert "$BAO_CACERT" \
|
||||
--output /dev/null "$BAO_ADDR/v1/sys/health"; do
|
||||
remaining=$((remaining - 1))
|
||||
[ "$remaining" -gt 0 ] || {
|
||||
@@ -40,7 +43,7 @@ done
|
||||
ENV_FILE="$env_file" "$script_dir/openbao-init.sh"
|
||||
ENV_FILE="$env_file" "$script_dir/openbao-unseal.sh"
|
||||
remaining=60
|
||||
until curl --fail --silent --show-error --cacert "$BAO_CACERT" \
|
||||
until curl --fail --silent --show-error --connect-timeout 2 --max-time 3 --cacert "$BAO_CACERT" \
|
||||
--output /dev/null "$BAO_ADDR/v1/sys/health"; do
|
||||
remaining=$((remaining - 1))
|
||||
[ "$remaining" -gt 0 ] || {
|
||||
|
||||
@@ -56,8 +56,10 @@ mkdir -p "$runtime_dir"
|
||||
chmod 0700 "$repo_dir/.runtime/evidence" "$runtime_dir"
|
||||
trap restore EXIT HUP INT TERM
|
||||
|
||||
openbao_address=$(compose port openbao 8200)
|
||||
BAO_ADDR="https://$openbao_address"
|
||||
if [ -z "${BAO_ADDR:-}" ]; then
|
||||
openbao_address=$(compose port openbao 8200)
|
||||
BAO_ADDR="https://$openbao_address"
|
||||
fi
|
||||
BAO_CACERT="$repo_dir/.runtime/security/openbao/ca.crt"
|
||||
export BAO_ADDR BAO_CACERT
|
||||
|
||||
|
||||
@@ -90,4 +90,3 @@ done
|
||||
"$script_dir/openbao-issue-approle.sh" worker "$openbao_runtime_dir/approle/worker"
|
||||
|
||||
echo "OpenBao policies, AppRoles and KV v2 secrets configured"
|
||||
|
||||
|
||||
@@ -30,7 +30,9 @@ require_file() {
|
||||
|
||||
require_private_file() {
|
||||
require_file "$1"
|
||||
permissions=$(stat -f '%Lp' "$1" 2>/dev/null || stat -c '%a' "$1")
|
||||
if ! permissions=$(stat -c '%a' "$1" 2>/dev/null); then
|
||||
permissions=$(stat -f '%Lp' "$1")
|
||||
fi
|
||||
case "$permissions" in
|
||||
600|400) ;;
|
||||
*) fail "file must have permissions 0600 or 0400: $1" ;;
|
||||
@@ -88,4 +90,3 @@ require_unsealed() {
|
||||
[ "$initialized" = "true" ] || fail "OpenBao is not initialized"
|
||||
[ "$sealed" = "false" ] || fail "OpenBao is sealed"
|
||||
}
|
||||
|
||||
|
||||
@@ -43,4 +43,3 @@ mv "$init_file" "$openbao_operator_file"
|
||||
|
||||
echo "OpenBao initialized; operator material saved to .runtime/openbao/operator/init.json"
|
||||
echo "Keep this file offline and run scripts/openbao-unseal.sh"
|
||||
|
||||
|
||||
@@ -79,9 +79,9 @@ if [ -n "$old_accessor" ]; then
|
||||
fi
|
||||
|
||||
if [ "$output_dir" = "$openbao_runtime_dir/approle/$service" ]; then
|
||||
"$script_dir/sync-docker-workspace.sh"
|
||||
docker compose --project-directory "$repo_dir" --env-file "${ENV_FILE:-$repo_dir/lab7.env.example}" \
|
||||
run --rm --no-deps -e SERVICE="$service" openbao-identity-install
|
||||
fi
|
||||
|
||||
echo "issued short-lived AppRole credentials for $service in ${output_dir#"$repo_dir/"}"
|
||||
|
||||
|
||||
@@ -39,4 +39,3 @@ PY
|
||||
"$script_dir/openbao-issue-approle.sh" "$service" "$openbao_runtime_dir/approle/$service"
|
||||
|
||||
echo "$service secret rotated; OpenBao Agent will render the new KV version"
|
||||
|
||||
|
||||
@@ -137,4 +137,3 @@ expect_status worker GET sys/policies/acl 403
|
||||
expect_status worker POST auth/token/renew-self 200 '{}'
|
||||
|
||||
echo "OpenBao AppRole allow/deny and renewal checks passed"
|
||||
|
||||
|
||||
@@ -48,4 +48,3 @@ openbao_status "$status_file"
|
||||
[ "$(json_field "$status_file" sealed)" = "false" ] || fail "OpenBao remains sealed"
|
||||
|
||||
echo "OpenBao unsealed"
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ if [ -z "$image_list" ]; then
|
||||
fi
|
||||
|
||||
mkdir -p "$runtime_dir" "$cache_dir"
|
||||
"$script_dir/sync-docker-workspace.sh"
|
||||
|
||||
docker run --rm \
|
||||
-v "$repo_dir:/src:ro" \
|
||||
@@ -50,6 +51,8 @@ for image in $image_list; do
|
||||
image_reports="$image_reports $image=$report"
|
||||
done
|
||||
|
||||
"$script_dir/sync-docker-workspace.sh" --pull-scan
|
||||
|
||||
python3 - "$raw_file" "$summary_file" $image_reports <<'PY'
|
||||
import datetime
|
||||
import json
|
||||
|
||||
+2
-1
@@ -5,7 +5,8 @@ set -eu
|
||||
: "${TARGET_INSTANCE_ID:?TARGET_INSTANCE_ID is required}"
|
||||
|
||||
for container in $(docker compose ps -q api); do
|
||||
instance=$(docker inspect --format '{{.Config.Hostname}}' "$container")
|
||||
instance=$(docker exec "$container" wget -S -q -O /dev/null http://127.0.0.1:8082/health/live 2>&1 |
|
||||
sed -n 's/^[[:space:]]*X-Instance-Id:[[:space:]]*//p' | tr -d '\r')
|
||||
if [ "$instance" = "$TARGET_INSTANCE_ID" ]; then
|
||||
docker stop --time 6 "$container" >/dev/null
|
||||
exit 0
|
||||
|
||||
Executable
+51
@@ -0,0 +1,51 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -eu
|
||||
|
||||
[ "${DOCKER_WORKSPACE_MIRROR:-0}" = "1" ] || exit 0
|
||||
|
||||
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
repo_dir=$(CDPATH= cd -- "$script_dir/.." && pwd)
|
||||
mode=${1:-sync}
|
||||
|
||||
case "$mode" in
|
||||
sync|--pull-scan) ;;
|
||||
--clean)
|
||||
case "$repo_dir" in
|
||||
/tmp/mtusi2026lab7-*) ;;
|
||||
*) echo "cleanup is restricted to temporary CI workspaces" >&2; exit 2 ;;
|
||||
esac
|
||||
run_id=${repo_dir#/tmp/mtusi2026lab7-}
|
||||
case "$run_id" in
|
||||
''|*[!0-9]*) echo "invalid CI workspace name" >&2; exit 2 ;;
|
||||
esac
|
||||
docker run --rm --network none -v "$repo_dir:/workspace" alpine:3.24.2 \
|
||||
find /workspace -mindepth 1 -delete
|
||||
exit 0
|
||||
;;
|
||||
*) echo "usage: $0 [--pull-scan|--clean]" >&2; exit 2 ;;
|
||||
esac
|
||||
|
||||
[ -f "$repo_dir/compose.yaml" ] || {
|
||||
echo "repository checkout is incomplete" >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
container=$(docker create --network none \
|
||||
-v "$repo_dir:/workspace" \
|
||||
alpine:3.24.2 /bin/true)
|
||||
|
||||
cleanup() {
|
||||
docker rm -f "$container" >/dev/null 2>&1 || true
|
||||
}
|
||||
|
||||
trap cleanup EXIT HUP INT TERM
|
||||
|
||||
if [ "$mode" = "--pull-scan" ]; then
|
||||
destination=$repo_dir/evidence/runtime/security-scan
|
||||
mkdir -p "$destination"
|
||||
docker cp "$container:/workspace/evidence/runtime/security-scan/." "$destination"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
docker cp "$repo_dir/." "$container:/workspace"
|
||||
@@ -25,6 +25,7 @@ compose_rotated() {
|
||||
}
|
||||
|
||||
install_security_material() {
|
||||
"$script_dir/sync-docker-workspace.sh"
|
||||
compose run --rm --no-deps security-bootstrap >/dev/null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user