skip to content

How does the AWS CLI obtain credentials for a profile created by `aws configure sso`, and what does running `aws sso login` actually do?

level: middleimportance: nice to knowfreq 45%

answer

  1. nothing secret on disk
  2. browser sign-in, then a cached token
  3. two expiries, not one
  4. account id plus permission set name
  5. expired in the morning, log in again

basics

~20 s

aws configure sso writes an sso-session block plus a profile naming an account and permission set. aws sso login opens a browser sign-in and caches a short-lived SSO token locally; the CLI exchanges that token for temporary role credentials per command.

solid answer

~40 s

`aws configure sso` writes two things into `~/.aws/config`: an `[sso-session <name>]` block holding `sso_start_url`, `sso_region` and `sso_registration_scopes`, and one or more `[profile <name>]` blocks that point at that session and name an `sso_account_id` plus an `sso_role_name`. No secret is written anywhere. Running `aws sso login --profile <name>` starts a browser authorisation flow against the portal and caches the resulting **SSO access token** under `~/.aws/sso/cache`. From then on, any command using that profile exchanges the cached token for temporary credentials for that account and permission set, and caches those separately. When the token expires you get an expired-or-invalid-token error and simply run `aws sso login` again — there is nothing to rotate and nothing in `~/.aws/credentials`.

code

ini · 16 lines
ini
[sso-session corp]
sso_start_url = https://d-9067f2a1b3.awsapps.com/start
sso_region = eu-west-1
sso_registration_scopes = sso:account:access

[profile prod-admin]
sso_session = corp
sso_account_id = 111122223333
sso_role_name = AdministratorAccess
region = eu-west-1

[profile dev-readonly]
sso_session = corp
sso_account_id = 444455556666
sso_role_name = ReadOnly
region = eu-west-1

go deeper

for a junior

Know the two commands — aws configure sso to set the profile up, aws sso login when it stops working in the morning — and that no secret key is stored on disk.

for a middle

Explain the two-stage exchange: a browser sign-in produces a cached portal token, and each profile trades that token for temporary credentials for its account and permission set.

for a senior

Show awareness that the cached token is itself a bearer credential with real blast radius, and that tools without SSO support should consume exported temporary credentials rather than a reintroduced long-lived key.

for a principal

Frame local developer credentials as a fleet concern: standard profile naming, an approved way to bridge legacy tools, disk encryption, and session durations set as a deliberate trade between friction and revocation lag.

## Two layers of expiry The thing that confuses people about SSO profiles is that there are **two** short-lived artefacts, not one: 1. The **SSO access token**, obtained by signing in through the browser. It represents "this human is authenticated to the portal" and is shared by every profile that names the same `sso-session`. 2. The **role credentials** — an access key ID, secret and session token for one specific account and permission set, obtained by presenting the SSO token. Their lifetime is the permission set's session duration. Signing in once therefore lights up every account you have been assigned, and each profile mints its own role credentials on demand. ## What lands in ~/.aws/config ```ini [sso-session corp] sso_start_url = https://d-9067f2a1b3.awsapps.com/start sso_region = eu-west-1 sso_registration_scopes = sso:account:access [profile prod-admin] sso_session = corp sso_account_id = 111122223333 sso_role_name = AdministratorAccess region = eu-west-1 ``` Note what is *not* there: no access key, no secret, no password. `sso_role_name` is the **permission set name**, not a role ARN — Identity Center resolves it to the provisioned role in that account. Older configurations put `sso_start_url` and `sso_region` directly inside the profile with no `sso-session` block. That legacy form still works, but the session block is the one to write today because it supports token refresh and is shared across profiles. ## What `aws sso login` does It registers the CLI as an OIDC client with the portal, starts an authorisation flow, and opens your browser (or prints a URL and a user code when it cannot). You authenticate against whatever the identity source is — including the MFA that source enforces — and approve the request. The CLI polls until the flow completes, then writes a JSON blob containing the access token and its expiry into `~/.aws/sso/cache/`. That directory contents are sensitive: the cached token is a bearer credential for the portal for the rest of its lifetime. It is short-lived, which is the point, but it is not nothing. ## What happens on each command When you run, say, `aws s3 ls --profile prod-admin`, the credential resolution chain sees an SSO profile, loads the cached token, and calls the portal to fetch role credentials for the configured account and permission set. Those credentials are cached on disk too, and reused until they expire. Only then does the actual S3 call go out, signed with the temporary credentials. Modern AWS SDKs implement the same provider, so application code and tools such as Terraform can consume an SSO profile through `AWS_PROFILE` without any bespoke wrapper. Tools that cannot are usually handled with `aws configure export-credentials`, which prints the resolved temporary credentials in a chosen format — still short-lived, still no stored key. ## The failure you will actually hit The next morning, the first command fails with an error about the SSO token being expired or invalid, sometimes phrased as a request to log in again. The fix is one command: ```bash aws sso login --profile prod-admin ``` The wrong reactions, which interviewers do hear, are "run `aws configure` and paste keys" (that reintroduces exactly the long-lived secret you removed), or "raise the session duration" (that has a hard ceiling and is a security budget, not a convenience dial). `aws sso logout` clears the cached token and role credentials — worth knowing for a shared or borrowed machine. ## Useful details around the edges - `aws sso login --sso-session corp` authenticates the session without naming a profile, refreshing every profile that uses it. - The portal APIs used are ordinary AWS APIs: the CLI lists your assigned accounts and roles through them, which is how `aws configure sso` can offer you a picker instead of asking you to type account numbers. - Because the profile stores the permission set *name*, renaming a permission set breaks every profile that references it — a real operational cost of renaming. ## The shape of a good answer Name the two layers — portal token then role credentials — say that nothing long-lived is written to disk, and describe the expiry symptom and its one-command fix. That is the whole mechanism.

  • Does `sso_role_name` hold a role ARN?
    No — it holds the permission set name, and Identity Center resolves it to the provisioned role in that account. That is why the same profile shape works across accounts where the underlying role ARN differs, and also why renaming a permission set breaks everyone's profiles.
  • How would you run a tool that has no idea what an SSO profile is?
    Two routes. Point it at the profile through AWS_PROFILE if its SDK is modern enough to implement the SSO provider — most are. Otherwise use `aws configure export-credentials` to emit the already-resolved temporary credentials into the environment. Both keep the credential short-lived; pasting a long-lived key back into the config is the answer to avoid.
  • Is the cached SSO token something to worry about on a laptop?
    Yes, within its lifetime. It is a bearer token for the access portal, so anyone who copies it can mint role credentials for every account you are assigned until it expires. That is a strong argument for full-disk encryption and short durations, and for `aws sso logout` on a shared machine.

saying these in an interview costs you the question

  • aws sso login writes an access key into ~/.aws/credentials
  • One login only covers the single profile you named
  • sso_role_name must be a full role ARN
  • Fix an expired token by pasting keys with aws configure
  • Session duration can be raised to days to avoid re-login

context