Files
mtusi2026lab7/tests/openbao_policy.sh
T
d1frend cc41f601e3
Skeleton contracts / contracts (pull_request) Canceled after 0s
на оценку 4
2026-11-22 23:33:11 +03:00

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"