Add daily app-token renewal (script + systemd timer)

Periodic scoped tokens (~/.config/openbao/*.token) expired because nothing
renewed them within their period. renew-app-tokens.sh renews all of them via
auth/token/renew-self; openbao-token-renew.timer runs it daily (Persistent=true).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-08-01 10:20:12 +02:00
parent 63f864b68b
commit f2919cf50a
3 changed files with 51 additions and 0 deletions

29
scripts/renew-app-tokens.sh Executable file
View File

@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Renew every scoped OpenBAO app token so periodic tokens never lapse. Periodic
# tokens live only as long as they're renewed within their period; nothing was
# renewing these, so they expired (2026-08-01). Runs daily via a systemd timer.
#
# Best-effort: reads each ~/.config/openbao/*.token and calls renew-self. A dead
# token logs a failure but never aborts the rest. No secrets are printed.
set -uo pipefail
ADDR="${BAO_ADDR:-http://127.0.0.1:8200}"
DIR="$HOME/.config/openbao"
LOG="$DIR/token-renew.log"
ts="$(date '+%F %T %Z')"
shopt -s nullglob
renewed=0; failed=0
for tf in "$DIR"/*.token; do # *.token only — backup files (*.token.bak.*) don't match
tok="$(cat "$tf" 2>/dev/null)"
name="$(basename "$tf")"
[ -n "$tok" ] || { echo "$ts $name EMPTY" >> "$LOG"; failed=$((failed+1)); continue; }
resp="$(curl -sS --max-time 10 -H "X-Vault-Token: $tok" -X POST "$ADDR/v1/auth/token/renew-self" 2>/dev/null)"
ttl="$(printf '%s' "$resp" | jq -r '.auth.lease_duration // empty' 2>/dev/null)"
if [ -n "$ttl" ]; then
echo "$ts $name renewed ttl=${ttl}s" >> "$LOG"; renewed=$((renewed+1))
else
echo "$ts $name RENEW FAILED: $(printf '%s' "$resp" | jq -c '.errors // .' 2>/dev/null)" >> "$LOG"; failed=$((failed+1))
fi
done
echo "$ts summary: renewed=$renewed failed=$failed" >> "$LOG"
[ "$failed" -eq 0 ]

View File

@@ -0,0 +1,12 @@
[Unit]
Description=Renew scoped OpenBAO app tokens so periodic tokens never lapse
After=network-online.target docker.service
Wants=network-online.target
Requires=docker.service
[Service]
Type=oneshot
User=lutz
Group=lutz
ExecStart=/home/lutz/Projects/OpenBAO/scripts/renew-app-tokens.sh
# Renews ~/.config/openbao/*.token via auth/token/renew-self. Best-effort.

View File

@@ -0,0 +1,10 @@
[Unit]
Description=Daily renewal of scoped OpenBAO app tokens
[Timer]
OnCalendar=daily
Persistent=true
RandomizedDelaySec=1h
[Install]
WantedBy=timers.target