Skip to content

Instantly share code, notes, and snippets.

@avoidik
Forked from mazenovi/vault-tree
Created June 18, 2019 10:36
Show Gist options
  • Select an option

  • Save avoidik/c2f77e8f1afa38d20723a46a88b833d2 to your computer and use it in GitHub Desktop.

Select an option

Save avoidik/c2f77e8f1afa38d20723a46a88b833d2 to your computer and use it in GitHub Desktop.
explore recursively your vault by HashiCorp
#!/usr/bin/env bash
function walk() {
for secret in $(vault list $1 | tail -n +3)
do
if [[ ${secret} == *"/" ]] ; then
walk "${1}${secret}"
else
echo "${1}${secret}"
fi
done
}
query="${1}"
if [[ ${query} != *"/" ]] ; then
query=${query}/
fi
echo "${1}"
walk ${query}
@avoidik

avoidik commented Jun 18, 2019

Copy link
Copy Markdown
Author
vault read -format=json sys/mounts | jq -r '.data | with_entries(select(.value.type=="kv")) | map_values(.type)'
#
vault read -format=json sys/mounts | jq -r '.data | with_entries(select(.key|match("secret"))) | map_values(.options)'

@avoidik

avoidik commented Aug 2, 2021

Copy link
Copy Markdown
Author
# same for secrets
vault read -format=json sys/mounts | jq -r '.data | with_entries(select(.value.type=="aws")) | map_values(.type)'
# same for auth
vault read -format=json sys/auth | jq -r '.data | with_entries(select(.value.type=="aws")) | map_values(.type)'

@avoidik

avoidik commented Aug 2, 2021

Copy link
Copy Markdown
Author
# get all AWS access-keys associated with Vault AWS secrets
for item in $(vault read -format=json sys/mounts | jq -r '.data | with_entries(select(.value.type=="aws")) | keys[]'); do
  vault read -format=json $item/config/root | jq -r '.data.access_key'
done
# get all AWS access-keys associated with Vault AWS auth
for item in $(vault read -format=json sys/auth | jq -r '.data | with_entries(select(.value.type=="aws")) | keys[]'); do
  vault read -format=json auth/$item/config/client | jq -r '.data.access_key'
done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment