CLI tool which enables you to login and retrieve AWS temporary credentials using a SAML IDP
CLI tool which enables you to login and retrieve AWS temporary credentials using a SAML IDP
CLI tool which enables you to login and retrieve AWS temporary credentials using with ADFS or PingFederate Identity Providers.
This is based on python code from How to Implement a General Solution for Federated API/CLI Access Using SAML 2.0.
The process goes something like this:
Aside from Okta, most of the providers in this project are using screen scraping to log users into SAML, this isn't ideal and hopefully vendors make this easier in the future. In addition to this there are some things you need to know:
--session-duration flag.AWS_STS_REGIONAL_ENDPOINTS enviornment variable to regional when calling saml2aws so that aws-sdk-go uses a regional STS endpoint instead of the global one. See the note at the bottom of Signing AWS API requests and AWS STS Regionalized endpoints.If you're on macOS you can install saml2aws using homebrew!
brew install saml2aws
saml2aws --versionIf you're on Windows you can install saml2aws using chocolatey!
choco install saml2aws
saml2aws --versionWhile brew is available for Linux you can also run the following without using a package manager.
Some users of Ubuntu have reported issue with the Others Install instruction and reported the following to work (may required using sudo command like for the "mv" function)
CURRENT_VERSION=$(curl -Ls https://api.github.com/repos/Versent/saml2aws/releases/latest | grep 'tag_name' | cut -d'v' -f2 | cut -d'"' -f1)
wget https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws_${CURRENT_VERSION}_linux_amd64.tar.gz
tar -xzvf saml2aws_${CURRENT_VERSION}_linux_amd64.tar.gz
mv saml2aws /usr/local/bin/
chmod u+x /usr/local/bin/saml2aws
saml2aws --versionFor U2F support, replace wget line above with wget https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws-u2f_${CURRENT_VERSION}_linux_amd64.tar.gz
mkdir -p ~/.local/bin
CURRENT_VERSION=$(curl -Ls https://api.github.com/repos/Versent/saml2aws/releases/latest | grep 'tag_name' | cut -d'v' -f2 | cut -d'"' -f1)
wget -c "https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws_${CURRENT_VERSION}_linux_amd64.tar.gz" -O - | tar -xzv -C ~/.local/bin
chmod u+x ~/.local/bin/saml2aws
hash -r
saml2aws --versionIf saml2aws --version does not work as intended, you may need to update your terminal configuration file (like ~/.bashrc, ~/.profile, ~/.zshrc) to include export PATH="$PATH:$HOME/.local/bin/" at the end of the file.
For U2F support, replace wget line above with wget -c "https://github.com/Versent/saml2aws/releases/download/v${CURRENT_VERSION}/saml2aws-u2f_${CURRENT_VERSION}_linux_amd64.tar.gz" -O - | tar -xzv -C ~/.local/bin
You will need Go Tools (you can check your package maintainer as well) installed and the Go Lint tool
Clone this repo to your $GOPATH/src directory
Now you can install by running
make
make installThe saml2aws tool is available in AUR (saml2aws-bin), so you can install it using an available AUR helper:
$ pamac build saml2aws-binIf you are on Void Linux you can use xbps to install the saml2aws package!
xbps-install saml2awssaml2aws can generate completion scripts.
Add the following line to your .bash_profile (or equivalent):
eval "$(saml2aws --completion-script-bash)"Add the following line to your .zshrc (or equivalent):
eval "$(saml2aws --completion-script-zsh)"Install the AWS CLI see, in our case we are using homebrew on macOS.
brew install awscli…saml2aws scriptIf the script sub-command is called, saml2aws will output the following temporary security credentials:
export AWS_ACCESS_KEY_ID="ASIAI....UOCA"
export AWS_SECRET_ACCESS_KEY="DuH...G1d"
export AWS_SESSION_TOKEN="AQ...1BQ=="
export AWS_SECURITY_TOKEN="AQ...1BQ=="
export AWS_CREDENTIAL_EXPIRATION="2016-09-04T38:27:00Z00:00"
SAML2AWS_PROFILE=samlPowershell, sh and fish shells are supported as well.
Env is useful for all AWS SDK compatible tools that can source an env file. It is a powerful combo with docker and the --env-file parameter.
If you use eval $(saml2aws script) frequently, you may want to create a alias for it:
zsh:
alias s2a="function(){eval $( $(command saml2aws) script --shell=bash --profile=$@);}"bash:
function s2a { eval $( $(which saml2aws) script --shell=bash --profile=$@); }env:
docker run -ti --env-file <(saml2aws script --shell=env) amazon/aws-cli s3 lssaml2aws execIf the exec sub-command is called, saml2aws will execute the command given as an argument:
By default saml2aws will execute the command with temp credentials generated via saml2aws login.
The --exec-profile flag allows for a command to execute using an aws profile which may have chained
"assume role" actions. (via 'source_profile' in ~/.aws/config)
options:
--exec-profile Execute the given command utilizing a specific profile from your ~/.aws/config fileThis is the new way of adding IDP provider accounts, it enables you to have named accounts with whatever settings you like and supports having one default account which is used if you omit the account flag. This replaces the --provider flag and old configuration file in 1.x.
To add a default IdP account to saml2aws just run the following command and follow the prompts.
$ saml2aws configure
? Please choose a provider: Ping
? AWS Profile myaccount
? URL https://example.com
? Username [email protected]
? Password
No password supplied
account {
URL: https://example.com
Username: [email protected]
Provider: Ping
MFA: Auto
SkipVerify: false
AmazonWebservicesURN: urn:amazon:webservices
SessionDuration: 3600
Profile: myaccount
Region: us-east-1
}
Configuration saved for IDP account: defaultThen to login using this account.
saml2aws loginYou can also add named accounts, below is an example where I am setting up an account under the wolfeidau alias, again just follow the prompts.
saml2aws configure -a wolfeidauYou can also configure the account alias without prompts.
saml2aws configure -a wolfeidau --idp-provider KeyCloak --username [email protected] -r cn-north-1 \
--url https://keycloak.wolfe.id.au/auth/realms/master/protocol/saml/clients/amazon-aws --skip-promptThen your ready to use saml2aws.
Log into a service (without MFA).
…Log into a service (with MFA).
…If you are using WSL1 or WSL2, you might get the following error when attempting to save the credentials into the keychain
No such interface “org.freedesktop.DBus.Properties” on object at path /This happens because the preferred keyring back-end - uses the gnome-keyring by default - which requires X11 - and if you are not
No open issues yet, or sync has not completed.