close
Skip to content

Add --revoke-sso-token flag to export-credentials#10259

Open
jviehhauser wants to merge 1 commit intoaws:v2from
jviehhauser:feature/sso-revoke-after-export
Open

Add --revoke-sso-token flag to export-credentials#10259
jviehhauser wants to merge 1 commit intoaws:v2from
jviehhauser:feature/sso-revoke-after-export

Conversation

@jviehhauser
Copy link
Copy Markdown

@jviehhauser jviehhauser commented Apr 28, 2026

Fixes #10258.

Description of changes

  • Add a new --revoke-sso-token flag to aws configure export-credentials. When set, after credentials are emitted, the SSO access token used to resolve them is server-side revoked via sso.Logout and its ~/.aws/sso/cache/<digest>.json file is removed.
  • Surgical: only the cache file for the active profile's sso_session (or legacy sso_start_url) is touched. Other profiles and concurrent SSO sessions are untouched.
  • Best-effort: revoke failures are logged at DEBUG and do not change the exit status, since the credentials have already been written to the caller.
  • No default behavior changes; flag is opt-in.
  • Refactored the existing sso.Logout call site in awscli/customizations/sso/logout.py into a small reusable helper revoke_sso_token(...) so both aws sso logout and the new flag share one revocation path. aws sso logout's behavior is unchanged.

Description of tests

  • New TestRevokeSSOTokenFlag class in tests/unit/customizations/configure/test_exportcreds.py covers: sso-session profile, legacy SSO profile, non-SSO profile (no-op), missing cache file, Logout API client error, output unaffected on revoke failure, and flag-off baseline.
  • Existing tests/unit/customizations/sso/test_logout.py continues to pass (24 tests) — the refactor preserves aws sso logout behavior.
  • Existing tests/unit/customizations/configure/test_exportcreds.py continues to pass (20 baseline tests).

By submitting this PR, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jviehhauser jviehhauser marked this pull request as ready for review April 28, 2026 12:32
When set, after credentials are emitted, the IAM Identity Center
access token used to resolve them is server-side revoked via
sso.Logout and its on-disk cache file is removed.

The flag is opt-in and surgical: only the cache file for the active
profile's sso_session (or legacy sso_start_url) is touched. Other
profiles and concurrent SSO sessions are untouched. The cache key
is derived identically to botocore's SSOTokenLoader so the file we
look at is always the file aws sso login wrote.

Best-effort error handling: credentials have already been emitted
when revoke runs, so any failure must not change the exit status.
Both the narrow ClientError path inside revoke_sso_token (which is
also used by aws sso logout, with unchanged behavior) and broader
transport-level errors (BotoCoreError, EndpointResolutionError,
etc.) are swallowed.

Use case: when aws configure export-credentials runs as a
credential_process, the SSO token's on-disk lifetime collapses
from the IAM Identity Center session duration (8h default) to
the duration of a single STS exchange. Each refresh requires a
new aws sso login flow.

The existing sso.Logout call site in awscli/customizations/sso/
logout.py is refactored into a reusable helper revoke_sso_token.
aws sso logout's behavior is unchanged.

Tests pin the cache filename contract to botocore's
SSOTokenLoader._generate_cache_key directly, so any drift between
this command's lookup logic and botocore's storage logic surfaces
as a test failure rather than a silent file-path mismatch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jviehhauser jviehhauser force-pushed the feature/sso-revoke-after-export branch from 94ed917 to 400eb18 Compare April 28, 2026 12:47
@jviehhauser jviehhauser marked this pull request as draft April 28, 2026 12:48
@jviehhauser jviehhauser marked this pull request as ready for review April 28, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant