Created
May 21, 2018 17:00
-
-
Save mitchelldavis/93773661454746d1b42d804bb0d61baf to your computer and use it in GitHub Desktop.
A Bash script to clean out the Identity Whitelist from Hashicorp Vault's AWS Auth Provider
This file contains hidden or 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
#! /bin/bash | |
WHITELIST=$(vault list -format=json auth/aws-ec2/identity-whitelist | jq -r '.[]') | |
INSTANCES=$(aws ec2 describe-instances) | |
INSTANCE_LIST=$(echo $INSTANCES | jq -r '.Reservations[].Instances[] | .InstanceId') | |
for item in $WHITELIST; do | |
if echo $INSTANCE_LIST | grep -w $item > /dev/null; then | |
echo "Skipping..." | |
else | |
echo "Delete $item" | |
curl -X DELETE -H "X-VAULT-TOKEN: $VAULT_TOKEN" $VAULT_ADDR/v1/auth/aws-ec2/identity-whitelist/$item | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment