add vault token auto-renewal script and LaunchAgent

This commit is contained in:
Viktor Barzin 2026-03-15 18:07:17 +00:00
parent d7a2a384cf
commit 91e81da944
2 changed files with 41 additions and 0 deletions

View file

@ -0,0 +1,15 @@
#!/bin/bash
# Auto-renew Vault token if it exists and is renewable
VAULT_TOKEN_FILE="$HOME/.vault-token"
if [ ! -f "$VAULT_TOKEN_FILE" ]; then
exit 0
fi
export VAULT_ADDR="https://vault.viktorbarzin.me"
export VAULT_TOKEN="$(cat "$VAULT_TOKEN_FILE")"
# Check if token is still valid and renewable, then renew
if vault token lookup -format=json 2>/dev/null | /usr/bin/python3 -c "import sys,json; d=json.load(sys.stdin)['data']; sys.exit(0 if d.get('renewable') else 1)" 2>/dev/null; then
vault token renew > /dev/null 2>&1
fi