Simplified Configuration of SSO Profiles in AWS CLI Using SSO Sessions
For some time now, configuring Single Sign-On (SSO) profiles in AWS CLI has been simplified thanks to the introduction of SSO sessions. Traditionally, setting up SSO profiles required specifying the SSO endpoint for each profile individually. The new approach uses the sso-session section in the configuration file to group SSO endpoint variables, which profiles can reference. This avoids redundant information and makes the configuration process easier.
Benefits of Using SSO Sessions
SSO sessions offer several advantages over previous methods:
Why Choose SSO Sessions Over IAM Users?
Using SSO sessions (IAM Identity Center) in AWS CLI offers significant advantages over traditional IAM users:
Configuring a Profile Using the aws configure sso Wizard
The easiest way to configure an SSO profile using SSO sessions is with the aws configure sso wizard. This command guides users through the setup process, including:
After completing the process, a new entry will appear in the ~/.aws/config file with the following structure. Notice how the profile references the session.
[profile my-new-profile]
sso-session = myorg
sso-account-id = 123456789012
sso-role-name = AdministratorAccess
[sso-session myorg]
sso-start-url = https://myorg.awsapps.com/start
sso-region = us-east-1
sso-registration-scopes = sso:account:access
In practice, the new configuration differs from the old one in that sso-session can be reused across multiple profiles. Previously, everything had to be defined together, duplicating information across profiles in the same organization.
Here’s how the old configuration looked:
; old config, don't use it
[profile my-old-profile]
sso_start_url = https://myorg.awsapps.com/start
sso_region = us-east-1
sso_account_id = 123456789012
sso_role_name = AdministratorAccess
credential_process = aws-sso-util credential-process --profile my-old-profile
Logging In and Using an SSO Profile
After configuring an SSO profile, users can log in using the aws sso login command. This command opens the default browser to authenticate the user. Once logged in, the credentials are cached, enabling AWS CLI to securely fetch AWS credentials for the specified IAM role.
Example usage of an SSO profile:
领英推荐
aws s3 ls --profile my-new-profile
If you use environment variables, you can still set the profile as the default:
export AWS_PROFILE=my-new-profile
BTW: I manage this setup with the direnv tool, allowing me to use different profiles in different directories.
Configuring Additional SSO Profiles
If you noticed in the screenshot, I have access to nine AWS accounts. To configure a profile for another account, I simply run the aws configure sso command again.
Then, I type the previously created SSO session name. This allows me to select another account from the list without re-entering the SSO URL or other session details. No manual edits or copying AWS account numbers from the web console to the config file are needed.
Logging Out of an SSO Session
After finishing with an SSO profile, users can log out using the aws sso logout command. This clears cached credentials.
My Experience with IAM Identity Center
In my AWS organization, I decided to enable IAM Identity Center specifically to use SSO sessions instead of IAM users with static access keys. I must admit, for many years, out of convenience and habit, I didn’t regularly rotate my access keys ?? (see the image below). However, security concerns pushed me to change my approach. The new authentication method via SSO sessions is significantly more secure, eliminating risks associated with long-term access keys. I now sleep easier knowing my AWS accounts are better protected.
Gradual Transition to SSO and Temporary IAM Key Deactivation
When transitioning from IAM users with static access keys to SSO sessions, you can temporarily deactivate your access keys (Access Key and Secret Access Key) associated with the IAM user. Deactivation prevents the keys from being used for AWS operations but allows later reactivation without generating new keys. This approach provides flexibility during migration—you can configure SSO sessions on your system while disabling IAM keys as a security measure. If needed, you can quickly revert to traditional keys by reactivating them with one click in the AWS console. This makes the SSO migration process safer and less risky, allowing an emergency fallback to the old setup if required.
CloudPouch Supports the New SSO Profile Configuration
CloudPouch is an application for viewing costs and automatically identifying savings on AWS accounts. I’m excited to announce that starting with version 1.36.0, I’ve added support for the new SSO profiles, making it 100% compatible with configurations created by aws configure sso.
Summary
SSO sessions simplify the configuration and management of profiles in AWS CLI. Users can leverage the aws configure sso wizard to quickly and easily set up SSO sessions. This makes managing access to AWS resources more efficient, secure, and user-friendly.