forked from mtusi2026/mtusi2026lab7
36 lines
1.0 KiB
Bash
Executable File
36 lines
1.0 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
project_root=$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)
|
|
cd "$project_root"
|
|
|
|
role_id=$(cat secrets/openbao/api_role_id.txt)
|
|
secret_id=$(cat secrets/openbao/api_secret_id.txt)
|
|
token=$(docker compose exec -T openbao bao write -field=token auth/approle/login \
|
|
role_id="$role_id" secret_id="$secret_id")
|
|
|
|
bao_api() {
|
|
docker compose exec -T -e BAO_TOKEN="$token" openbao bao "$@"
|
|
}
|
|
|
|
bao_api kv get secret/api >/dev/null
|
|
printf '%s\n' "PASS: API AppRole reads its own path"
|
|
|
|
if bao_api kv get secret/worker >/dev/null 2>&1; then
|
|
printf '%s\n' "FAIL: API AppRole read worker path" >&2
|
|
exit 1
|
|
fi
|
|
printf '%s\n' "PASS: API AppRole cannot read worker path"
|
|
|
|
if bao_api policy list >/dev/null 2>&1; then
|
|
printf '%s\n' "FAIL: API AppRole listed policies" >&2
|
|
exit 1
|
|
fi
|
|
printf '%s\n' "PASS: API AppRole cannot administer policies"
|
|
|
|
if bao_api kv put secret/api probe=denied >/dev/null 2>&1; then
|
|
printf '%s\n' "FAIL: API AppRole wrote its read-only path" >&2
|
|
exit 1
|
|
fi
|
|
printf '%s\n' "PASS: API AppRole cannot write secrets"
|