Skip to main content

Identity Governance is available only with Teleport Enterprise. Start your free trial.

Start your free trial

Using the AWS CLI tools with Teleport and AWS IAM Identity Center

Report an Issue

This guide will show you how to configure the aws command-line tool to use access granted via Teleport and AWS Identity Center.

How it works

For a deep dive into how Teleport manages AWS Identity Center access works you can read the main AWS IAM Identity Center guide. For the purposes of this guide, it's enough to understand that Teleport manages the creation and deletion of AWS Account Assignments based on a user's Account Assignment grants, either from their standing Teleport Roles, Access List membership or approved Access Requests.

You can access these Teleport-managed Accounts and Permission Set assignments with the AWS CLI tools by using sso login and AWS profiles.

Prerequisites

Before you begin, you will need:

  • A Teleport-managed AWS Identity Center organization. See our getting started guide for setting up an Identity Center integration.
  • The AWS CLI tools, installed as per the AWS installation guide
  • The SSO Start URL and AWS Region for your Identity Center organization. Ask your AWS administrator for the appropriate values.

Configuration

Choose one of the following setup flows. The tsh flow is the recommended option when using Teleport tsh client version 18.8.x or later.

The tsh aws-profile command automatically generates native AWS SSO profiles in ~/.aws/config from your AWS Identity Center integration data. It preserves existing non-Teleport entries, updates Teleport-managed AWS Identity Center sections, and removes stale Teleport-managed profiles and SSO sessions that are no longer available from the cluster you are currently logged into.

tip

Use tsh aws-profile --dry-run to preview the changes before they are written to your AWS config file.

  1. Run the following command to generate the profiles:
$ tsh aws-profile
AWS configuration updated at: /Users/alice/.aws/config

Profile                    Account Account ID   Role   SSO Session
-------------------------- ------- ------------ ------ ----------------
teleport-awsic-dev-admin   dev     123456789012 Admin  teleport-d-12345
teleport-awsic-prod-reader prod    098765432109 Reader teleport-d-12345
  1. Select a profile and export it to the AWS_PROFILE environment variable. For example:
$ export AWS_PROFILE=teleport-awsic-prod-reader
  1. Authenticate with AWS SSO:
$ aws sso login

This opens a browser window to complete the authentication process via Teleport.

  1. Switch to another profile by exporting a different AWS_PROFILE value:
$ export AWS_PROFILE=teleport-awsic-dev-admin

If the profiles use the same SSO session, you do not need to run aws sso login again.

Testing the profile

After completing one of the configuration flows above, test the profile by running aws sts get-caller-identity and verifying the returned user ID and assumed role.

If you have already exported AWS_PROFILE, run:

$ aws sts get-caller-identity

Or pass the profile explicitly. For example:

$ aws sts get-caller-identity --profile admin-on-staging
{
    "UserId": "AROA123456789AEXAMPLE:[email protected]",
    "Account": "058264527036",
    "Arn": "arn:aws:sts::058264527036:assumed-role/AWSReservedSSO_AdministratorAccess_69450ffeac834ef7/[email protected]"
}

Once you have validated that the profile is configured correctly, you can use the --profile argument in any aws subcommand to select it and use the corresponding Identity Center Account assignment in that operation.

info

You can also use this profile with other tools that support the standard AWS client environment variables. Set the profile by setting the AWS_PROFILE environment variable. For example:

$ AWS_PROFILE=admin-on-staging ./some-aws-tool

Troubleshooting

"Invalid Callback" error

If AWS presents you with an "invalid Callback URL" error message, the most likely problem is an incorrect AWS region in your sso-session configuration.

"Error loading SSO Token" error

The AWS cache directory has probably been deleted. Log in again with aws sso login --sso-session ${SSO_SESSION_NAME}, where ${SSO_SESSION_NAME} is the name of your configured SSO session.

Next Steps

Further reading

For a broader introduction to using the AWS CLI with IAM Identity Center, see the AWS Configuring IAM Identity Center authentication with the AWS CLI guide.