Last active
May 12, 2018 02:51
-
-
Save jefferai/6233c2963f9407a858d84f9c27d725c0 to your computer and use it in GitHub Desktop.
Script to find and destroy Consul tokens created by Vault
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 | |
# Tested with jq 1.5. Should work with jq >= 1.4. | |
# Note: this script is an example to show how tokens can be listed | |
# and managed by jq into a removal function. You should not use this | |
# script as-is, in particular without examining the list output to | |
# exclude unwanted tokens from being removed. For instance, if | |
# your management token for Vault itself (storage, or the Consul | |
# dynamic backend) has a name that begins with "Vault", this | |
# script will not differentiate. | |
set -e | |
CONSUL_TOKEN="test" | |
CONSUL_ADDR="http://127.0.0.1:8500" | |
for i in $(curl -s -X GET -H "X-Consul-Token: ${CONSUL_TOKEN}" "${CONSUL_ADDR}/v1/acl/list" | jq -r 'map(select(.Name | startswith("Vault")))|.[].ID') | |
do | |
echo "${i}" | |
# Commented out for safety | |
#curl -X PUT -H "X-Consul-Token: ${CONSUL_TOKEN}" "${CONSUL_ADDR}/v1/acl/destroy/${i}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment