forked from mtusi2026/mtusi2026lab7
27 lines
1.3 KiB
Bash
Executable File
27 lines
1.3 KiB
Bash
Executable File
#!/bin/sh
|
|
set -eu
|
|
|
|
BAO_ADDR=${BAO_ADDR:-http://127.0.0.1:8200}
|
|
export BAO_ADDR
|
|
echo "OpenBao bootstrap. Secrets are printed only to the operator terminal; do not commit them."
|
|
if ! bao status >/dev/null 2>&1; then
|
|
echo "OpenBao is unavailable at $BAO_ADDR" >&2; exit 2
|
|
fi
|
|
if [ "$(bao status -format=json | sed -n 's/.*\"initialized\":\([a-z]*\).*/\1/p')" = "false" ]; then
|
|
bao operator init -key-shares=3 -key-threshold=2
|
|
echo "Save the init output in an external password manager, then unseal with two shares."
|
|
exit 0
|
|
fi
|
|
echo "If sealed, run: bao operator unseal (twice, using different shares)."
|
|
bao secrets enable -path=secret kv-v2 2>/dev/null || true
|
|
bao policy write api infra/openbao/policies/api.hcl
|
|
bao policy write worker infra/openbao/policies/worker.hcl
|
|
bao auth enable approle 2>/dev/null || true
|
|
echo "Create short-lived AppRoles and inject only their wrapped secret_ids into the services."
|
|
echo "Example after authentication:"
|
|
echo " bao kv put secret/messenger/database_url database_url=..."
|
|
echo " bao kv put secret/messenger/cache_url cache_url=..."
|
|
echo " bao kv put secret/messenger/s3_access_key_id s3_access_key_id=..."
|
|
echo " bao kv put secret/messenger/s3_secret_access_key s3_secret_access_key=..."
|
|
echo "Then write the scoped token to secrets/openbao_token.txt (chmod 600), set OPENBAO_ENABLED=true and recreate api/worker."
|