Skip to content

HashiCorp Vault — alert when a service token is about to expire

A service VAULT_TOKEN is close to expiry (no auto-renewal, or non-renewable=true). The service hits Vault — and one day it gets 403 and loses access to its secrets.

Recipe

bash
#!/usr/bin/env bash
# /etc/cron.d/vault-token
# 0 */6 * * * root /opt/vault-token.sh

export VAULT_ADDR=${VAULT_ADDR}
export VAULT_TOKEN=${VAULT_TOKEN}
WARN_HOURS=${WARN_HOURS:-24}

# `token lookup` returns ttl in seconds
TTL=$(vault token lookup -format=json | jq '.data.ttl')
LEFT_HOURS=$((TTL / 3600))

if [ "$LEFT_HOURS" -lt "$WARN_HOURS" ]; then
  curl -fsS "$HEARTBEAT_URL" --data "vault_ttl_h=$LEFT_HOURS,threshold=$WARN_HOURS"
  exit 2
fi
echo "OK (TTL=${LEFT_HOURS}h)"

Same thing in Enterno.io

Wire to an Enterno heartbeat on a 6-hour schedule — learn about a "forgot to renew" before the service starts failing.

Set up HTTP monitor → ← All recipes

Related recipes