visit
#key.json
{
"Version": 1,
"AccessKeyId": "NOTAREALKEYID,
"SecretAccessKey": "NOTAREALSECRET
}
#encrypt.sh
openssl aes-256-cbc -a -salt -in ${1} -out ${1}.enc -k "password"
# yes it is just "password" its a demo script! \
# Store this in an environment variable
# or something safer than the script.
#decrypt.sh
#!/bin/bash -eu
#this will take the encrypted file passed to it decrypt it, and echo it
openssl aes-256-cbc -d -a -in $1 -k "password"
# yes it is just "password" its a demo script! \
# Store this in an environment variable
# or something safer than the script.
$ ./encrypt.sh key.json
# creates key.json.enc
#~/.aws/config
[profile mine-encrypted]
credential_process = /Users/MYUSERNAME/decrypt.sh /Users/MYUSERNAME/key.json.enc
export AWS_PROFILE=mine-encrypted
Lastly we will verify the whole process worked. aws sts get-caller-identity
We can take this in another direction as well. Let's say there is a process out there that will issue the credentials for you and then stash them in your aws profile. I would like to at least make the storing of those credentials a little bit better. So here is a whole pretty script that will handle that. You will provide the shell script with the named account profile that one would reference to use that account. This script also relies on having the decrypt.sh script we talked about earlier. #wrap up and harden local aws keys
function _encrypt() {
openssl aes-256-cbc -a -salt -in ${1} -out ${1}.enc -k "password"
filestats=( $( ls -Lon "${1}" ) ) # to get size
dd if=/dev/urandom of=${1} bs=${filestats[3]} count=1 &>/dev/null
rm ${1}
}
function _shape(){
id=$1
key=$2
session=$3
json=$(cat << DATA
{
"Version": 1,
"AccessKeyId": "$id",
"SecretAccessKey": "$key",
"SessionToken": "$session"
}
DATA
)
echo "$json"
}
function _cleanup(){
aws configure set profile.$1.aws_access_key_id "xxxx"
aws configure set profile.$1.aws_secret_access_key "xxxx"
aws configure set profile.$1.aws_session_token "xxxx"
}
function _set_encrypted(){
aws configure set credential_process "/Users/$(pwd)/aws-crypt/decrypt.sh /Users/$(pwd)/aws-crypt/$1.json.enc" --profile "$1-encrypted"
}
profile=$1
raw_aws=$(grep "\[$profile\]" ~/.aws/credentials -A 5 | awk 'NR == 1 || /^aws/' | awk '{print $3}' | tr '\r\n' ' '|sed 's/ //')
full_json=$(_shape $raw_aws)
if [ -f "$profile.json" ]; then
rm "$profile.json"
fi
echo "$full_json" >>"$profile.json"
_encrypt "$profile.json"
_cleanup $profile
_set_encrypted $profile
HACK THE PLANET!