#!/bin/sh # OpenBao proof (README defense step 4): policy allow/deny for every service + no root credential # in the application containers. Prints PASS/FAIL lines, never a token, share or secret value. # sh scripts/bao_check.sh (Windows: scripts\bao_check.cmd) set -u cd "$(dirname "$0")/.." export MSYS_NO_PATHCONV=1 # Git Bash: keep /run/secrets as a container path OPERATOR_DIR="${OPERATOR_DIR:-$HOME/.mtusi-lab7-operator/${COMPOSE_PROJECT_NAME:-mtusi-lab7}}" rc=0 for svc in api relay worker; do echo "== $svc" docker compose exec -T "$svc" python - < scripts/bao_check.py || rc=1 done echo echo "== root credential / unseal material in the application containers (values compared, never printed)" for svc in api relay worker; do # 1. no token-like variable in the container configuration names="$(docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' "$(docker compose ps -q "$svc" | head -1)" \ | cut -d= -f1 | grep -iE 'TOKEN|UNSEAL|ROOT' || true)" if [ -n "$names" ]; then echo " FAIL $svc: token-like env names: $names"; rc=1; else echo " PASS $svc: no *TOKEN*/*UNSEAL*/*ROOT* environment variable"; fi # 2. the operator's root token and unseal shares do not occur anywhere in the container's # secrets, code, temp files or process environment (fed via stdin, compared inside) # Positive control: the same search MUST find a value that is there (the service's own role_id), # otherwise "absent" below would prove nothing. found="$(docker compose exec -T "$svc" sh -c 'read -r v; grep -rlsF -- "$v" /run/secrets | head -1' < "secrets/bao/${svc}_role_id")" if [ -n "$found" ]; then echo " PASS control: own role_id found by the same search ($found)"; else echo " FAIL control search found nothing"; rc=1; fi for f in root-token unseal-share-1 unseal-share-2 unseal-share-3; do if [ ! -f "$OPERATOR_DIR/$f" ]; then echo " FAIL operator file $f missing in $OPERATOR_DIR"; rc=1; continue; fi found="$(docker compose exec -T "$svc" sh -c 'read -r v; for p in /run/secrets /app /tmp /proc/1/environ; do grep -rqsF -- "$v" "$p" && echo "$p"; done; true' < "$OPERATOR_DIR/$f")" if [ -n "$found" ]; then echo " FAIL $svc: $f found in $found"; rc=1; else echo " PASS $svc: $f absent (/run/secrets, /app, /tmp, PID 1 environment)"; fi done echo " $svc /run/secrets: $(docker compose exec -T "$svc" ls /run/secrets | tr '\n' ' ')" done [ "$rc" = 0 ] && echo "PASS: OpenBao allow/deny and no root credential in the application" || echo "FAIL" exit "$rc"