Created
January 24, 2020 13:38
-
-
Save maxmanders/1a95fd5ef4b08847062b1d696a3b45ab to your computer and use it in GitHub Desktop.
Recursively walk a Vault secret path prefix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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