Sub topic 2
How IAM Identity Center issues access
This chapter assumes you know what an AWS account and an IAM role are, and that you have used the AWS CLI with access keys. It explains how IAM Identity Center turns a person's sign-in into short-lived credentials for a role in an AWS account. The later chapters cover the configuration steps.
The problem it solves
An IAM user access key is a fixed pair of values. It works from any machine until someone rotates or deletes it. IAM Identity Center works the other way. You prove who you are, and AWS hands out credentials that expire on their own. Nothing long-lived has to be stored in ~/.aws/credentials.
The key idea is that Identity Center does not give you a new kind of credential. It gives you ordinary temporary credentials for an IAM role, the same kind AWS Security Token Service (STS) produces. The sign-in flow is only the way you obtain them.
The parts
Four pieces take part in every sign-in.
| Part | What it is | What it does |
|---|---|---|
| Identity source | The directory that holds your users and groups | Authenticates you. It can be the built-in Identity Center directory, Microsoft Active Directory, or an external identity provider connected with SAML. |
| AWS access portal | A web page at your organization's start URL | Shows the accounts and roles you may use and lets you sign in. |
| Permission set | A reusable template of permissions | Defines what a user can do once inside an account. |
| Assignment | A link between a user or group, a permission set, and an account | Grants access. Without an assignment, nothing appears in the portal. |
Identity Center is enabled once per AWS Organizations organization, in one Region, and that Region is called the home Region of the instance. This Region appears later as sso_region in your CLI configuration. It does not have to match the Region where your resources run.
Permission sets and assignments are covered in detail in the next chapter. For now, treat an assignment as the statement "this person may act as this role in that account."
What happens in each account
When you assign a permission set to an account, Identity Center creates an IAM role in that account. The role name follows a fixed pattern:
AWSReservedSSO_<PermissionSetName>_<random-suffix>The role lives under the path /aws-reserved/sso.amazonaws.com/. Its trust policy allows a SAML provider that Identity Center created in the account to assume it. You do not edit these roles. Identity Center owns them, and it updates or deletes them when you change the permission set or the assignment.
You can see these roles from inside an account if you have IAM read access:
aws iam list-roles \
--path-prefix /aws-reserved/sso.amazonaws.com/ \
--query 'Roles[].RoleName' \
--output textEach role name in the output maps to one permission set assigned to that account.
When you later run aws sts get-caller-identity, the ARN shows this role as an assumed role. The session name at the end of the ARN is your user name from the identity source:
{
"UserId": "AROAEXAMPLEID:[email protected]",
"Account": "111122223333",
"Arn": "arn:aws:sts::111122223333:assumed-role/AWSReservedSSO_ReadOnlyAccess_1a2b3c4d5e6f7a8b/[email protected]"
}The user name in the ARN is what appears in CloudTrail logs. Because each person gets a named session, you can trace an API call to a person. A shared access key cannot do that.
From sign-in to credentials
The CLI works in two stages. Do not confuse the credentials from each stage, because they last for different times and are used for different things.
- Sign-in. You authenticate in a browser. The CLI receives an access token that proves you signed in to the access portal. This token cannot call S3, EC2, or any other service API.
- Role credentials. The CLI presents that access token to the portal service and asks for credentials for one account and one role. It receives an access key ID, a secret access key, and a session token. These are what the CLI signs requests with.
Here is what each step does.
- Client registration. The CLI registers itself with the Identity Center OIDC service (OpenID Connect, a standard sign-in protocol built on OAuth 2.0). It does this so the service knows which application is asking for a token. With an
sso-sessionconfiguration, the registration is cached and reused. - Authorization. Current CLI v2 releases use an authorization code flow with PKCE (a safeguard that ties the request to the process that made it). The CLI opens your browser and listens for the response on a local address. If a browser cannot be launched, for example over SSH on a remote host, the device code flow is the fallback. The CLI prints a URL and a short code, and you enter the code on any device that has a browser.
aws sso login --use-device-codeforces this mode. - Token creation. After you approve in the browser, the CLI exchanges the result for an access token. With an
sso-sessionconfiguration the CLI also receives a refresh token. This lets it renew the access token without opening the browser again, until the portal session itself ends. - Role credentials. The CLI calls the portal's
GetRoleCredentialsoperation with the access token, an account ID, and a role name. The portal returns temporary credentials together with an expiration time.
The role credentials are fetched on demand. If you run a command with a profile and the cached credentials are missing or expired, the CLI fetches new ones using the access token. You do not sign in again unless the access token can no longer be used or renewed.
Why this is safer
Several properties follow from this design.
- The credentials the CLI signs requests with expire, and the default lifetime is one hour. A leaked copy stops working on its own.
- The password and multi-factor authentication (MFA) steps happen in the browser at your identity source. The CLI never sees them.
- Access is controlled in one place. Removing a user's assignment, or disabling the user in the identity source, stops new credentials from being issued. Credentials already issued stay valid until they expire.
- Every session is tied to a named person in CloudTrail.
The last point under the removal bullet matters in incident response. Disabling a user does not revoke role credentials that were already issued. If you need to cut access immediately, you must also deal with those active sessions, and the permission set's session duration limits how long they can last.
Two clocks, two lifetimes
There are two separate time limits. The portal session is the period during which your access token and refresh token stay usable. The role credentials session is the lifetime of one set of credentials for one role. Administrators set both: the portal session duration in Identity Center settings, and the role session duration on each permission set. A later chapter covers the defaults and limits. For now, remember that signing in again and getting new role credentials are different events, and that either can be the one that expired.
Common misunderstandings
- "SSO credentials are stored in
~/.aws/credentials." They are not. The CLI caches the access token and role credentials under~/.aws/sso/cacheand~/.aws/cli/cache. A later chapter on caching explains this. - "The access token lets me call AWS services." It does not. It only lets the CLI request role credentials.
- "The Region I configure is where my resources are."
sso_regionis the Identity Center home Region. Theregionin a profile is the default Region for API calls. - "Each account needs its own sign-in." One sign-in to the portal covers every account and role assigned to you. You pick the account and role per request when the CLI asks for role credentials.
- "I can edit the
AWSReservedSSO_role in IAM to change access." Identity Center manages those roles and overwrites manual changes. Change the permission set instead.
Exercise
You run aws sso login and sign in successfully. A teammate says the CLI now holds long-lived credentials for your account. Describe what the CLI actually holds at this point, and what it must do before it can call aws s3 ls.
Show answer
After sign-in the CLI holds an access token (and, with an sso-session configuration, a refresh token). The access token only proves you signed in to the access portal and cannot call service APIs. Before running aws s3 ls, the CLI must call GetRoleCredentials with the access token, the account ID, and the role name from the profile. That call returns an access key, secret key, and session token that expire, with a default lifetime of one hour. The CLI signs the S3 request with those credentials.
Exercise
An administrator disables your user in the identity source at 10:00. Your role credentials were issued at 09:30 with a one-hour session. Can you still call AWS APIs at 10:15? Can you get fresh credentials at 10:45?
Show answer
At 10:15 you probably can, because the role credentials were already issued and stay valid until they expire at 10:30. Disabling the user does not revoke issued credentials. At 10:45 you cannot get fresh credentials, because the portal will no longer issue them for a disabled user.