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

iam: SamlConsolePrincipal does not work for GovCloud or ADC regions #25723

Closed
nagmesh opened this issue May 24, 2023 · 4 comments · Fixed by #28704
Closed

iam: SamlConsolePrincipal does not work for GovCloud or ADC regions #25723

nagmesh opened this issue May 24, 2023 · 4 comments · Fixed by #28704
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2

Comments

@nagmesh
Copy link

nagmesh commented May 24, 2023

Describe the bug

While creating the SAML federation principal as below, the SAML attribute is hardcoded with https://signin.aws.amazon.com/saml or https://signin.amazonaws.cn/saml , which breaks in GovCloud, Iso and Iso-b partitions.

Expected Behavior

The construct SamlConsolePrincipal should check partition and supply the right URL.

Current Behavior

Only works in aws or aws-cn partition rest of the partition has to be changed.

Reproduction Steps

Use partition as aws-us-gov and the signon URL is https://signin.aws.amazon.com/saml

Possible Solution

Make a map from partition and push it in

llet samlSignOnUrl: string;
const partition = cdk.Aws.PARTITION;
if (partition === 'aws-cn') {
  samlSignOnUrl = 'https://signin.amazonaws.cn/saml';
} else if (partition === 'aws-us-gov') {
  samlSignOnUrl = 'https://signin.amazonaws-us-gov.com/saml';
} else if (partition === 'aws-iso-b') {
  samlSignOnUrl = 'https://signin.sc2shome.sgov.gov/saml';
} else if (partition === 'aws-iso') {
  samlSignOnUrl = 'https://signin.c2shome.ic.gov/saml';
} else {
  samlSignOnUrl = 'https://signin.aws.amazon.com/saml';
}

export class SamlConsolePrincipal extends SamlPrincipal {
  constructor(samlProvider: ISamlProvider, conditions: Conditions = {}) {
    super(samlProvider, {
      ...conditions,
      StringEquals: {
        'SAML:aud': samlSignOnUrl,
      },
    });
  }
...

or add saml signonUrl in fact-table and source it in SamlConsolePrincipal

Additional Information/Context

No response

CDK CLI Version

2.79.1

Framework Version

No response

Node.js Version

16

OS

macOS 12.6.5

Language

Typescript

Language Version

No response

Other information

Related issue: #22091

@nagmesh nagmesh added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels May 24, 2023
@github-actions github-actions bot added the @aws-cdk/aws-iam Related to AWS Identity and Access Management label May 24, 2023
@peterwoodworth peterwoodworth added good first issue Related to contributions. See CONTRIBUTING.md p2 effort/small Small work item – less than a day of effort and removed needs-triage This issue or PR still needs to be triaged. labels May 24, 2023
@peterwoodworth
Copy link
Contributor

I think this should be a similar fix to the PR on the related issue. We're happy to accept a contribution for this 🙂

@virajmavani
Copy link

I would like to work on this.

@peterwoodworth
Copy link
Contributor

Please feel free @virajmavani!

@mergify mergify bot closed this as completed in #28704 Jan 24, 2024
mergify bot pushed a commit that referenced this issue Jan 24, 2024
…ISO regions (#28704)

This PR addresses the issue where the SAML federation principal is hardcoded with URLs specific to standard AWS and China partitions, causing failures in GovCloud, Iso, and Iso-b partitions. The provided solution dynamically sets the SAML sign-on URL based on the partition.

```diff
-       'SAML:aud': cdk.Aws.PARTITION==='aws-cn'? 'https://signin.amazonaws.cn/saml': 'https://signin.aws.amazon.com/saml',
+       'SAML:aud': RegionInfo.get(samlProvider.stack.region).samlSignOnUrl ?? 'https://signin.aws.amazon.com/saml',
```

```ts
export const PARTITION_SAML_SIGN_ON_URL: Record<Partition, string> = {
  [Partition.Default]: 'https://signin.aws.amazon.com/saml',
  [Partition.Cn]: 'https://signin.amazonaws.cn/saml',
  [Partition.UsGov]: 'https://signin.amazonaws-us-gov.com/saml',
  [Partition.UsIso]: 'https://signin.c2shome.ic.gov/saml',
  [Partition.UsIsoB]: 'https://signin.sc2shome.sgov.gov/saml',
};
```



Closes #25723.

----

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

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

penniman26 pushed a commit to penniman26/aws-cdk that referenced this issue Jan 25, 2024
…ISO regions (aws#28704)

This PR addresses the issue where the SAML federation principal is hardcoded with URLs specific to standard AWS and China partitions, causing failures in GovCloud, Iso, and Iso-b partitions. The provided solution dynamically sets the SAML sign-on URL based on the partition.

```diff
-       'SAML:aud': cdk.Aws.PARTITION==='aws-cn'? 'https://signin.amazonaws.cn/saml': 'https://signin.aws.amazon.com/saml',
+       'SAML:aud': RegionInfo.get(samlProvider.stack.region).samlSignOnUrl ?? 'https://signin.aws.amazon.com/saml',
```

```ts
export const PARTITION_SAML_SIGN_ON_URL: Record<Partition, string> = {
  [Partition.Default]: 'https://signin.aws.amazon.com/saml',
  [Partition.Cn]: 'https://signin.amazonaws.cn/saml',
  [Partition.UsGov]: 'https://signin.amazonaws-us-gov.com/saml',
  [Partition.UsIso]: 'https://signin.c2shome.ic.gov/saml',
  [Partition.UsIsoB]: 'https://signin.sc2shome.sgov.gov/saml',
};
```



Closes aws#25723.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
SankyRed pushed a commit that referenced this issue Feb 8, 2024
…ISO regions (#28704)

This PR addresses the issue where the SAML federation principal is hardcoded with URLs specific to standard AWS and China partitions, causing failures in GovCloud, Iso, and Iso-b partitions. The provided solution dynamically sets the SAML sign-on URL based on the partition.

```diff
-       'SAML:aud': cdk.Aws.PARTITION==='aws-cn'? 'https://signin.amazonaws.cn/saml': 'https://signin.aws.amazon.com/saml',
+       'SAML:aud': RegionInfo.get(samlProvider.stack.region).samlSignOnUrl ?? 'https://signin.aws.amazon.com/saml',
```

```ts
export const PARTITION_SAML_SIGN_ON_URL: Record<Partition, string> = {
  [Partition.Default]: 'https://signin.aws.amazon.com/saml',
  [Partition.Cn]: 'https://signin.amazonaws.cn/saml',
  [Partition.UsGov]: 'https://signin.amazonaws-us-gov.com/saml',
  [Partition.UsIso]: 'https://signin.c2shome.ic.gov/saml',
  [Partition.UsIsoB]: 'https://signin.sc2shome.sgov.gov/saml',
};
```



Closes #25723.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-iam Related to AWS Identity and Access Management bug This issue is a bug. effort/small Small work item – less than a day of effort good first issue Related to contributions. See CONTRIBUTING.md p2
Projects
None yet
3 participants