Skip to content

Instantly share code, notes, and snippets.

@juffaz
Created March 27, 2024 14:20
Show Gist options
  • Save juffaz/da9027b801010d8e16bcd75cbff30529 to your computer and use it in GitHub Desktop.
Save juffaz/da9027b801010d8e16bcd75cbff30529 to your computer and use it in GitHub Desktop.
vault-policy-search-secret.sh
#!/bin/bash
DATABASES=("db/postdb" "db/camunda" "secret/mydb")
read_policy() {
local policy_name=$1
local policy_content=$(vault policy read $policy_name)
echo "$policy_content" | while read -r line; do
for database in "${DATABASES[@]}"; do
if [[ $line == *"$database"* ]]; then
echo "Policy $policy_name found database: $database"
break
fi
done
done
}
policies=$(vault policy list)
for policy_name in $policies; do
read_policy $policy_name
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment