Skip to content

Instantly share code, notes, and snippets.

@maxmanders
Created January 24, 2020 13:38
Show Gist options
  • Save maxmanders/1a95fd5ef4b08847062b1d696a3b45ab to your computer and use it in GitHub Desktop.
Save maxmanders/1a95fd5ef4b08847062b1d696a3b45ab to your computer and use it in GitHub Desktop.
Recursively walk a Vault secret path prefix
#!/usr/bin/env bash
export VAULT_ADDR="http://${VAULT_IP}:${VAULT_PORT}"
vaultwalk() {
local prefix
local secret_keys
prefix="${1}"
if [ -z "${prefix}" ]; then
prefix="secret/"
fi
if [ "${prefix: -1}" != "/" ]; then
prefix="${prefix}/"
fi
secret_keys=$(vault list ${prefix} | tail -n+3)
while IFS= read -r key; do
local secret_key
secret_key="${prefix}${key}"
if [ "${secret_key: -1}" != "/" ]; then
echo -n "${secret_key}: "
vault read --format=json "${secret_key}" | jq -r ".data.value"
else
vaultwalk "${prefix}${key}"
fi
done <<< "${secret_keys}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment