This CLI tool helps you to configure your AWS access in CI/CD environments. You can set the region, the IAM profile to use or assume IAM roles with one CLI call.
The tool prints environment variables to the console to use in subsequent calls. By using eval you can set the environment in one call.
To install this tool you need NodeJS and NPM installed on your machine.
You can then execute npm install -g aws-authenticate to install the aws-authenticate executable.
To use a profile configured in your ~/.aws/config file, issue the following command:
eval "$(aws-authenticate auth --profile myprofile)"
To assume a role using your default config you call it like:
eval "$(aws-authenticate auth --role MyRole)"
To assume a role in another account, use:
eval "$(aws-authenticate auth --role MyRole --roleAccount 123456789012)"
To assume a role in another account using a different policy, call:
eval "$(aws-authenticate auth --role MyRole --roleAccount 123456789012 --roleSessionPolicy 'arn:aws:iam::aws:policy/AdministratorAccess')"
To clear all AWS related environment variable and use the defaults, call:
eval "$(aws-authenticate clear)"
If you do not want to pollute your environment with settings, you can use a sub-shell to only configure AWS for several calls:
#!/bin/bash -e
...
(
eval "$(aws-authenticate auth --profile myprofile)"
aws s3 ls
)
...If you want to do something for a accounts in an organization, use the following code:
#!/bin/bash -e
export accounts=$(aws-authenticate accounts)
echo "${accounts}" | while read account; do
(
id=$(echo "${account}" | cut -d ',' -f 1)
safeName=$(echo "${account}" | cut -d ',' -f 4)
echo "Doing stuff for account ${id} with safe name ${safeName}"
eval "$(aws-authenticate auth --roleAccount ${id} --role master --region eu-central-1)"
aws-authenticate set-alias --name "${safeName}"
)
done
If you have a tag called Alias on your accounts, you can set the account alias with the following script:
#!/bin/bash -e
export accounts=$(aws-authenticate accounts --tags Alias)
echo "${accounts}" | while read account; do
(
id=$(echo "${account}" | cut -d ',' -f 1)
alias=$(echo "${account}" | cut -d ',' -f 6)
eval "$(aws-authenticate auth --roleAccount ${id} --role master --region eu-central-1)"
aws-authenticate set-alias --name "${alias}"
)
done
aws-authenticate <command> [options]
The auth command is used to configure credentials or assume roles.
Valid options are:
--role <role>- The IAM role to assume--roleAccount <accountId>- The AWS account owning the role to assume. If not specified, your current account is used.--region <region>- The region to configure for subsequent calls--profile <profile>- The profile configured in~/.aws/configto use--targetProfile <profile>- The profile in~/.aws/configto write the new credentials to--externalId <id>- The external ID to use when assuming roles--duration <seconds>- The number of seconds the temporary credentials should be valid. Default is 3600.--roleSessionName <name>- The name of the session of the assumed role. Defaults toAWS-Auth-<xyz>withxyzbeing the current milliseconds since epoch.--roleSessionPolicy <str>- The ARN or filename of the policy to use for the assumed session--id- Print the final user information to the console for debugging purpose
With the id command, the tool prints the currently configured IAM principal to the console
$ aws-authenticate id
# Account: 123456789012 - User: arn:aws:iam::123456789012:user/johndoeThe clear command creates a bash snippet to clear all AWS related environment vafriables.
The accounts command lists AWS accounts withing the currect organization.
Accounts are printed one account per line with the following fields in a CSV format.
<ID>,<EMAIL>,<NAME>,<SAFENAME>,<STATUS>
The safe name is the name with only alphanumeric characters and the rest being replaced with dashes.
123456789012,acc1@example.com,My Example Account,my-example-account,ACTIVE
210987654321,acc2@example.com,My Sub Account,my-sub-account,ACTIVE
Valid options are:
--parent <parent>- Limit the account list to the given orga parent (OU)--tags key1,key2- Show account tags as additional columns
The update-idp command is used to create or update the given SAML identity provider
Valid options are:
--name <name>- Name of the IdP to configure. Defaults toSAML--metadata <file>- The file to use as SAML metadata
The set-alias command enables you to configure an AWS account alias.
Valid options are:
--name <name>- Name of the alias to configure
See Github releases
- update deps
- add support to write auth to new profile
- update deps
- fix
--roleAccountwhen account id has leading zeros
- add
--roleSessionPolicyto provide IAM policies when assuming roles - add
--tagsto account list
- remove
--scriptoption as it is completely broken. Use sub-shells instead. BREAKING CHANGE
- add
--scriptoption to run bash scripts directly - add
accountscommand to list AWS accounts - add
update-idpcommand to manage SAML IdP - add
set-aliascommand to manage SAML IdP - fix
clearcommand
- add README and
helpcommand
- Initial project implementation
-
Ensure the bug was not already reported by searching on GitHub under Issues.
-
If you're unable to find an open issue addressing the problem, open a new one. Be sure to include a title and clear description, as much relevant information as possible, and a code sample demonstrating the expected behavior that is not occurring.
-
Open a new GitHub pull request with the patch.
-
Ensure the PR description clearly describes the problem and solution. Include the relevant issue number if applicable.
Changes that are cosmetic in nature and do not add anything substantial to the stability, functionality, or testability will normally not be accepted.
-
Suggest your change under Issues.
-
Do not open a pull request on GitHub until you have collected positive feedback about the change.
- Just file a PR with your recommended changes