Files
dizi a8edaf058d
CI / verify (pull_request) Successful in 14m53s
chore: finalize lab7 security verification
2026-11-06 22:00:42 +03:00

42 lines
1003 B
Bash
Executable File

#!/bin/sh
set -eu
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
. "$script_dir/openbao-common.sh"
if [ "$#" -ne 2 ]; then
echo "usage: $0 <api|worker> <replacement-secret-json>" >&2
exit 2
fi
service=$1
secret_file=$2
case "$service" in
api|worker) ;;
*) fail "service must be api or worker" ;;
esac
require_command "$BAO_BIN"
require_command python3
require_runtime_path "$secret_file"
require_private_file "$secret_file"
require_unsealed
load_operator_token
python3 - "$secret_file" <<'PY'
import json
import sys
with open(sys.argv[1], encoding="utf-8") as source:
value = json.load(source)
if not isinstance(value, dict) or not value:
raise SystemExit("replacement secret must be a non-empty JSON object")
PY
"$BAO_BIN" kv put -mount=secret "messenger/$service" @"$secret_file" >/dev/null
"$script_dir/openbao-issue-approle.sh" "$service" "$openbao_runtime_dir/approle/$service"
echo "$service secret rotated; OpenBao Agent will render the new KV version"