Created
June 29, 2016 13:49
-
-
Save mlimotte/6422690a9d914c954068acca29df594a to your computer and use it in GitHub Desktop.
A bash function to get Vault (Hashicorp) credentials using AWS backend and set them in environment variables for use by the AWS cli.
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 | |
function vault-aws () { | |
VAULT_PATH=$1 | |
if [ -z "$VAULT_PATH" ]; then | |
echo "Missing VAULT_PATH argument.\nExample: `vault-aws documents-store`" | |
exit 1 | |
fi | |
if [ -z "$VAULT_ADDR" ]; then | |
echo "Missing VAULT_ADDR env variable" | |
exit 1 | |
fi | |
CREDS=$(vault read aws/creds/$VAULT_PATH) | |
export AWS_ACCESS_KEY_ID=$(echo $CREDS | grep -o 'access_key [^ ]*' | awk '{print $2}') | |
export AWS_SECRET_ACCESS_KEY=$(echo $CREDS | grep -o 'secret_key [^ ]*' | awk '{print $2}') | |
DURATION=$(echo $CREDS | grep -o 'lease_duration [^ ]*' | awk '{print $2}') | |
echo Credentials good for $DURATION seconds. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment