Skip to content

Instantly share code, notes, and snippets.

@mitchelldavis
Created May 21, 2018 17:00
Show Gist options
  • Save mitchelldavis/93773661454746d1b42d804bb0d61baf to your computer and use it in GitHub Desktop.
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
#! /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