If your organization uses Azure Active Directory to provide SSO login to the AWS console, then there is no easy way to log in on the command line or to use the AWS CLI. This tool fixes that. It lets you use the normal Azure AD login (including MFA) from a command line to create a federated AWS session and places the temporary credentials in the proper place for the AWS CLI and SDKs.
Install Node.js v7.6.0 or higher. Then install aws-azure-login with npm:
npm install -g aws-azure-login
In Linux you can either install for all users or just the current user. In either case, you must first install Node.js v7.6.0 or higher and any puppeteer dependencies. Then follow the appropriate instructions.
Install aws-azure-login globally with npm:
sudo npm install -g aws-azure-login --unsafe-perm
Puppeteer doesn't install globally with execution permissions for all users so you'll need to modify them:
sudo chmod -R go+rx $(npm root -g)
First configure npm to install global packages in your home directory:
mkdir ~/.npm-global npm config set prefix '~/.npm-global' export PATH=~/.npm-global/bin:$PATH source ~/.profile echo 'export PATH=~/.npm-global/bin:$PATH' >> ~/.profile source ~/.profile
Then install aws-azure-login:
npm install -g aws-azure-login
A Docker image has been built with aws-azure-login preinstalled. You simply need to run the command with a volume mounted to your AWS configuration directory.
docker run --rm -it -v ~/.aws:/root/.aws dtjohnson/aws-azure-login
The Docker image is configured with an entrypoint so you can just feed any arguments in at the end.
You can also put the docker-launch.sh script into your bin directory for the aws-azure-login command to function as usual:
sudo curl -o /usr/local/bin/aws-azure-login https://raw.githubusercontent.com/dtjohnson/aws-azure-login/master/docker-launch.sh sudo chmod o+x /usr/local/bin/aws-azure-login
Now just run
To configure the aws-azure-login client run:
You'll need your Azure Tenant ID and the App ID URI. To configure a named profile, use the --profile flag.
aws-azure-login --configure --profile foo
You can optionally store your responses as environment variables:
To avoid having to
<Enter> through the prompts after setting these environment variables, use the
--no-prompt option when running the command.
HISTCONTROL environment variable to avoid storing the password in your bash history (notice the space at the beginning):
$ HISTCONTROL=ignoreboth $ export AZURE_DEFAULT_PASSWORD=mypassword $ aws-azure-login
Once aws-azure-login is configured, you can log in. For the default profile, just run:
You will be prompted for your username and password. If MFA is required you'll also be prompted for a verification code or mobile device approval. To log in with a named profile:
aws-azure-login --profile foo
Alternatively, you can set the
AWS_PROFILE environmental variable to the name of the profile just like the AWS CLI.
Once you log in you can use the AWS CLI or SDKs as usual!
If you are logging in on an operating system with a GUI, you can log in using the actual Azure web form instead of the CLI:
aws-azure-login --mode gui
Logging in with GUI mode is likely to be much more reliable.
Note: on Linux you will likely need to disable the Puppeteer sandbox or Chrome will fail to launch:
If behind corporate proxy, then just set https_proxy env variable.
Your Azure AD system admin should be able to provide you with your Tenant ID and App ID URI. If you can't get it from them, you can scrape it from a login page from the myapps.microsoft.com page.
The nature of browser automation with Puppeteer means the solution is bit brittle. A minor change on the Microsoft side could break the tool. If something isn't working, you can fall back to GUI mode (above). To debug an issue, you can run in debug mode (--mode debug) to see the GUI while aws-azure-login tries to populate it. You can also have the tool print out more detail on what it is doing to try to do in order to diagnose. aws-azure-login uses the Node debug module to print out debug info. Just set the DEBUG environmental variable to 'aws-azure-login'. On Linux/OS X:
set DEBUG=aws-azure-login aws-azure-login
Obviously, this tool only supports Azure AD as an identity provider. However, there is a lot of similarity with how other logins with other providers would work (especially if they are SAML providers). If you are interested in building support for a different provider let me know. It would be great to build a more generic AWS CLI login tool with plugins for the various providers.