-
-
Notifications
You must be signed in to change notification settings - Fork 153
fix: resolve AWS profile SSO interference and --identity flag regression #2087
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f1323f
fix: resolve AWS profile SSO interference and --identity flag regression
aknysh ec8ab03
fix: address PR review feedback for auth fixes
aknysh 186337d
fix: address remaining PR feedback and improve test coverage
aknysh 48d7803
[autofix.ci] apply automated fixes
autofix-ci[bot] ff2a549
fix: address final PR review feedback
aknysh 81a31bb
fix: address final PR review feedback
aknysh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
docs/fixes/2026-02-17-aws-default-profile-sso-interference.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| # Fix AWS Default Profile Interference with SSO Authentication | ||
|
|
||
| **Date:** 2026-02-17 | ||
|
|
||
| **Related Issue:** Misleading error when `AWS_PROFILE` or `[default]` profile in `~/.aws/config` interferes | ||
| with SSO device authorization flow. | ||
|
|
||
| **Affected Atmos Version:** v1.160.0+ (introduced with Atmos Auth) | ||
|
|
||
| **Severity:** Medium — SSO authentication fails with a misleading error message when a user has a default AWS | ||
| profile configured, making the root cause difficult to diagnose. | ||
|
|
||
| ## Background | ||
|
|
||
| When running `atmos auth login`, the SSO provider loads an AWS config to initialize the OIDC client for | ||
| device authorization. The `LoadIsolatedAWSConfig` function was intended to completely isolate this config | ||
| loading from the user's existing AWS environment. However, the implementation had a gap: | ||
|
|
||
| - `WithIsolatedAWSEnv` correctly unsets `AWS_PROFILE`, `AWS_CONFIG_FILE`, `AWS_SHARED_CREDENTIALS_FILE`, | ||
| and credential env vars during config loading. | ||
| - `config.WithSharedConfigProfile("")` was used with the intent to "disable shared config loading," but | ||
| in the AWS SDK v2, an empty string means "use the default profile." | ||
| - The AWS SDK still loads `~/.aws/config` and `~/.aws/credentials` from their default filesystem paths | ||
| even when the corresponding env vars are unset. | ||
|
|
||
| This means if the user has a `[default]` profile in `~/.aws/config` that references SSO configuration, | ||
| credential processes, or other non-trivial settings, the SDK attempts to resolve those during | ||
| `LoadDefaultConfig` and may fail with a confusing error. | ||
|
|
||
| ## Symptoms | ||
|
|
||
| ``` | ||
| Error: failed to load AWS config | ||
|
|
||
| ## Explanation | ||
| Failed to load AWS configuration for SSO authentication in region 'us-west-2' | ||
|
|
||
| ## Hints | ||
| 💡 Verify that the AWS region is valid and accessible | ||
| 💡 Check your network connectivity and AWS service availability | ||
| ``` | ||
aknysh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The hints suggest region/network issues, but the actual cause is the `[default]` profile in | ||
| `~/.aws/config` (or `AWS_PROFILE` env var) interfering with config loading. | ||
|
|
||
| ## Root Cause | ||
|
|
||
| Two issues: | ||
|
|
||
| ### 1. Incomplete isolation in `LoadIsolatedAWSConfig` | ||
|
|
||
| `config.WithSharedConfigProfile("")` does **not** disable shared config file loading. In the AWS SDK v2, | ||
| an empty profile name resolves to the default profile (`[default]`). The SDK still reads `~/.aws/config` | ||
| and `~/.aws/credentials` from their default paths (`$HOME/.aws/config` and `$HOME/.aws/credentials`). | ||
osterman marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| The correct approach is to use `config.WithSharedConfigFiles([]string{})` and | ||
| `config.WithSharedCredentialsFiles([]string{})` to provide empty file lists, which prevents the SDK | ||
| from loading any shared config files. | ||
|
|
||
| ### 2. Misleading error message | ||
|
|
||
| The error at `sso.go:153-161` only hints at region/network issues. It does not mention: | ||
| - The `AWS_PROFILE` environment variable as a potential cause. | ||
| - The `~/.aws/config` default profile as a potential cause. | ||
| - That Atmos auth isolates from external AWS configuration (so the user knows this was attempted). | ||
|
|
||
| ## Fix | ||
|
|
||
| ### Approach | ||
|
|
||
| 1. Replace `config.WithSharedConfigProfile("")` with `config.WithSharedConfigFiles([]string{})` and | ||
| `config.WithSharedCredentialsFiles([]string{})` for complete filesystem isolation. | ||
| 2. Add a warning log when `AWS_PROFILE` is set or `~/.aws/config` exists with a default profile, | ||
| informing the user that these will be ignored during SSO auth. | ||
| 3. Improve the error message in the SSO provider to include hints about `AWS_PROFILE` and default | ||
| profiles in `~/.aws/config`. | ||
aknysh marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Implementation | ||
|
|
||
| #### 1. Fix `LoadIsolatedAWSConfig` (`pkg/auth/cloud/aws/env.go`) | ||
|
|
||
| Replace `config.WithSharedConfigProfile("")` with: | ||
| - `config.WithSharedConfigFiles([]string{})` | ||
| - `config.WithSharedCredentialsFiles([]string{})` | ||
|
|
||
| This completely prevents the AWS SDK from reading any shared config files during isolated operations. | ||
|
|
||
| #### 2. Add `WarnIfAWSProfileSet` helper (`pkg/auth/cloud/aws/env.go`) | ||
|
|
||
| New function that logs a warning when `AWS_PROFILE` is set, informing the user that it will be | ||
| ignored during Atmos auth. | ||
|
|
||
| #### 3. Improve SSO error message (`pkg/auth/providers/aws/sso.go`) | ||
|
|
||
| Add hints about: | ||
| - Checking if `AWS_PROFILE` environment variable is set. | ||
| - Checking for a `[default]` profile in `~/.aws/config`. | ||
| - The fact that Atmos auth operates in an isolated AWS environment. | ||
|
|
||
| #### 4. Call warning from SSO `Authenticate` method | ||
|
|
||
| Before loading the isolated config, call `WarnIfAWSProfileSet` to emit a debug-level warning. | ||
|
|
||
| ### Files changed | ||
|
|
||
| | File | Change | | ||
| |----------------------------------------------|----------------------------------------------------------------------| | ||
| | `pkg/auth/cloud/aws/env.go` | Fix `LoadIsolatedAWSConfig` isolation; add `WarnIfAWSProfileSet` | | ||
| | `pkg/auth/providers/aws/sso.go` | Improve error hints; call `WarnIfAWSProfileSet` before config load | | ||
| | `pkg/auth/cloud/aws/env_test.go` | Tests for isolation fix and warning detection | | ||
| | `pkg/auth/providers/aws/sso_test.go` | Tests for improved error messages | | ||
|
|
||
| ### Tests | ||
|
|
||
| | Test | What it verifies | | ||
| |---------------------------------------------------------|-------------------------------------------------------------------| | ||
| | `TestWithIsolatedAWSEnv_ClearsAllProblematicVars` | All problematic vars are cleared during execution and restored | | ||
| | `TestLoadIsolatedAWSConfig_IgnoresDefaultProfile` | Default profile in ~/.aws/config does not affect isolated config | | ||
| | `TestWarnIfAWSProfileSet_LogsWarning` | Warning is logged when AWS_PROFILE is set | | ||
| | `TestWarnIfAWSProfileSet_NoWarningWhenUnset` | No warning when AWS_PROFILE is not set | | ||
| | `TestSSOProvider_Authenticate_ErrorIncludesProfileHint` | Error message includes hint about AWS_PROFILE | | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.