Skip to content

Instantly share code, notes, and snippets.

@davespanton
Last active October 4, 2016 07:33
Show Gist options
  • Save davespanton/18ff2a2e3ab17f27fca5602a9b318061 to your computer and use it in GitHub Desktop.
Save davespanton/18ff2a2e3ab17f27fca5602a9b318061 to your computer and use it in GitHub Desktop.
Temp AWS creds with MFA via Yubikey Oath.
#! /usr/bin/fish
function aws_temp_creds -a mfa_arn aws_acc_nos -d "Sets AWS temp credentials with MFA via a Yubikey."
for i in (env | grep AWS | cut -f 1 -d "=")
set -e $i
end
set -l MFA (yubioath show $aws_acc_nos | tail -c 7)
count $MFA > /dev/null; or return 1
set -l RES (aws sts get-session-token --duration 3600 --serial-number $mfa_arn --token-code $MFA --output text | awk '{printf "%s\n%s\n%s", $2, $4, $5}');
count $RES > /dev/null; or return 1
set -gx AWS_ACCESS_KEY_ID $RES[1]
set -gx AWS_SECRET_ACCESS_KEY $RES[2]
set -gx AWS_SESSION_TOKEN $RES[3]
set -gx AWS_SECURITY_TOKEN $RES[3]
echo -e "All set. Now using $RES[1].\n:D"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment