Skip to content
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

fix(cli): can not assume role from 2-level SSO #23702

Merged
merged 2 commits into from
Jan 17, 2023
Merged

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Jan 16, 2023

The CLI used to support this:

[profile sso]
...

[profile one]
...
source_profile = sso

But not this:

[profile sso]
...

[profile one]
...
source_profile = sso

[profile two]
...
source_profile = one

The reason was that:

  • We have to do an explicit detection of SSO source profiles in our PatchedSharedIniFileCredentials because the upstream SharedIniFileCredentials has no SSO support at all; and
  • When we recursed we would recurse using the SharedIniFileCredentials class.

In combination, this means that we could only recurse one level, because in SharedIniFileCredentials we wouldn't support SSO profiles at all.

Fix this by recursing using PatchedSharedIniFileCredentials, so that we can support SSO source profiles an arbitrary amount of nesting levels deep.

While investigating this, also fixed the following issues:

  • SSO profiles would be detected using the incorrect key: sso_start_url can be specified either on the profile section, or a new [sso-session] section. sso_account_id however always must be on the profile section, so check on that.
  • Dropped support for reading the STS AssumeRole region from the [default] section. After investigating by both the JS SDK team and myself, noticed that the AWS CLI does not support reading the region from there. While we are both in agreement this is a bug, all customers expect the CDK CLI to behave exactly the same as the AWS CLI, so we have to keep bug-for-bug compatibility.
  • Drop the credentials/config file loading patch. The upstream SDK has fixed this behavior in the mean time, so we can rely on the passed-in profile data again.

Fixes #23520.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

The CLI used to support this:

```
[profile sso]
...

[profile one]
...
source_profile = sso
```

But not this:

```
[profile sso]
...

[profile one]
...
source_profile = sso

[profile two]
...
source_profile = one
```

The reason was that:

* We have to do an explicit detection of SSO source profiles in our
  `PatchedSharedIniFileCredentials` because the upstream
  `SharedIniFileCredentials` has no SSO support at all; and
* When we recursed we would recurse using the `SharedIniFileCredentials`
  class.

In combination, this means that we could only recurse **one level**,
because in `SharedIniFileCredentials` we wouldn't support SSO profiles
at all.

Fix this by recursing using `SharedIniFileCredentials`, so that we can
support SSO source profiles an arbitrary amount of nesting levels deep.

While investigating this, also fixed the following issues:

- SSO profiles would be detected using the incorrect key:
  `sso_start_url` can be specified either on the profile section,
  or a new `[sso-session]` section. `sso_account_id` however always
  must be on the profile section, so check on that.
- Drop the `credentials/config` file loading patch. The upstream SDK
  has fixed this behavior in the mean time, so we can rely on the
  passed-in profile data again.
- Dropped support for reading the STS AssumeRole `region` from the
  `[default]` section. After investigating by both the JS SDK team
  and myself, noticed that the AWS CLI does **not** support reading
  the region from there. While we are both in agreement this is
  a bug, all customers expect the CDK CLI to behave exactly the same
  as the AWS CLI, so we have to keep bug-for-bug compatibility.
@rix0rrr rix0rrr requested a review from a team January 16, 2023 13:54
@rix0rrr rix0rrr self-assigned this Jan 16, 2023
@gitpod-io
Copy link

gitpod-io bot commented Jan 16, 2023

@github-actions github-actions bot added the p2 label Jan 16, 2023
@aws-cdk-automation aws-cdk-automation requested a review from a team January 16, 2023 13:54
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Jan 16, 2023
Copy link
Collaborator

@aws-cdk-automation aws-cdk-automation left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request linter has failed. See the aws-cdk-automation comment below for failure reasons. If you believe this pull request should receive an exemption, please comment and provide a justification.

@rix0rrr rix0rrr added pr-linter/exempt-test The PR linter will not require test changes pr-linter/exempt-integ-test The PR linter will not require integ test changes labels Jan 16, 2023
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Jan 16, 2023

SDK auth is extremely awkward to test, because it hasn't really been design to be unit tested and integration tests require extensive setup and maintenance. You'll have to trust this has been tested by hand.

@rix0rrr rix0rrr added the pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested label Jan 17, 2023
@aws-cdk-automation aws-cdk-automation dismissed their stale review January 17, 2023 10:39

✅ Updated pull request passes all PRLinter validations. Dissmissing previous PRLinter review.

Copy link
Contributor

@Naumel Naumel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks out

@mergify
Copy link
Contributor

mergify bot commented Jan 17, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 7700065
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit c3a345b into main Jan 17, 2023
@mergify mergify bot deleted the huijbers/sso-auth-fix branch January 17, 2023 13:58
@mergify
Copy link
Contributor

mergify bot commented Jan 17, 2023

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS. p2 pr-linter/cli-integ-tested Assert that any CLI changes have been integ tested pr-linter/exempt-integ-test The PR linter will not require integ test changes pr-linter/exempt-test The PR linter will not require test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(cli): CDK CLI is not discovering SSO Credentials
3 participants