Skip to content

Commit c1f2abb

Browse files
fix(iam): SamlConsolePrincipal returns incorrect url in GovCloud and 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*
1 parent bdf4285 commit c1f2abb

File tree

6 files changed

+35
-4
lines changed

6 files changed

+35
-4
lines changed

packages/aws-cdk-lib/aws-iam/lib/principals.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ export class SamlConsolePrincipal extends SamlPrincipal {
760760
super(samlProvider, {
761761
...conditions,
762762
StringEquals: {
763-
'SAML:aud': cdk.Aws.PARTITION==='aws-cn'? 'https://signin.amazonaws.cn/saml': 'https://signin.aws.amazon.com/saml',
763+
'SAML:aud': RegionInfo.get(samlProvider.stack.region).samlSignOnUrl ?? 'https://signin.aws.amazon.com/saml',
764764
},
765765
});
766766
}

packages/aws-cdk-lib/aws-iam/test/principals.test.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,16 @@ test('use OpenID Connect principal from provider', () => {
144144
expect(stack.resolve(principal.federated)).toStrictEqual({ Ref: 'MyProvider730BA1C8' });
145145
});
146146

147-
test('SAML principal', () => {
147+
test.each([
148+
{ name: 'SAML principal', region: 'us-east-1', expectedAud: 'https://signin.aws.amazon.com/saml' },
149+
{ name: 'SAML principal CN', region: 'cn-northwest-1', expectedAud: 'https://signin.amazonaws.cn/saml' },
150+
{ name: 'SAML principal UsGov', region: 'us-gov-east-1', expectedAud: 'https://signin.amazonaws-us-gov.com/saml' },
151+
{ name: 'SAML principal UsIso', region: 'us-iso-east-1', expectedAud: 'https://signin.c2shome.ic.gov/saml' },
152+
{ name: 'SAML principal UsIsoB', region: 'us-isob-east-1', expectedAud: 'https://signin.sc2shome.sgov.gov/saml' },
153+
])('$name', ({ region, expectedAud }) => {
148154
// GIVEN
149-
const stack = new Stack();
155+
const app = new App();
156+
const stack = new Stack(app, 'TestStack', { env: { region } });
150157
const provider = new iam.SamlProvider(stack, 'MyProvider', {
151158
metadataDocument: iam.SamlMetadataDocument.fromXml('document'),
152159
});
@@ -166,7 +173,7 @@ test('SAML principal', () => {
166173
Action: 'sts:AssumeRoleWithSAML',
167174
Condition: {
168175
StringEquals: {
169-
'SAML:aud': 'https://signin.aws.amazon.com/saml',
176+
'SAML:aud': expectedAud,
170177
},
171178
},
172179
Effect: 'Allow',

packages/aws-cdk-lib/region-info/build-tools/fact-tables.ts

+8
Original file line numberDiff line numberDiff line change
@@ -3361,3 +3361,11 @@ export const ADOT_LAMBDA_LAYER_ARNS: { [key: string]: any } = {
33613361
PYTHON_SDK: ADOT_LAMBDA_LAYER_PYTHON_SDK_ARNS,
33623362
GENERIC: ADOT_LAMBDA_LAYER_GENERIC_ARNS,
33633363
};
3364+
3365+
export const PARTITION_SAML_SIGN_ON_URL: Record<Partition, string> = {
3366+
[Partition.Default]: 'https://signin.aws.amazon.com/saml',
3367+
[Partition.Cn]: 'https://signin.amazonaws.cn/saml',
3368+
[Partition.UsGov]: 'https://signin.amazonaws-us-gov.com/saml',
3369+
[Partition.UsIso]: 'https://signin.c2shome.ic.gov/saml',
3370+
[Partition.UsIsoB]: 'https://signin.sc2shome.sgov.gov/saml',
3371+
};

packages/aws-cdk-lib/region-info/build-tools/generate-static-data.ts

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ADOT_LAMBDA_LAYER_ARNS,
1313
PARAMS_AND_SECRETS_LAMBDA_LAYER_ARNS,
1414
APPCONFIG_LAMBDA_LAYER_ARNS,
15+
PARTITION_SAML_SIGN_ON_URL,
1516
} from './fact-tables';
1617
import { AWS_CDK_METADATA } from './metadata';
1718
import {
@@ -84,6 +85,8 @@ export async function main(): Promise<void> {
8485

8586
registerFact(region, 'APPMESH_ECR_ACCOUNT', APPMESH_ECR_ACCOUNTS[region]);
8687

88+
registerFact(region, 'SAML_SIGN_ON_URL', PARTITION_SAML_SIGN_ON_URL[partition]);
89+
8790
const firehoseCidrBlock = FIREHOSE_CIDR_BLOCKS[region];
8891
if (firehoseCidrBlock) {
8992
registerFact(region, 'FIREHOSE_CIDR_BLOCK', `${FIREHOSE_CIDR_BLOCKS[region]}/27`);

packages/aws-cdk-lib/region-info/lib/fact.ts

+5
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ export class FactName {
190190
*/
191191
public static readonly FIREHOSE_CIDR_BLOCK = 'firehoseCidrBlock';
192192

193+
/**
194+
* The SAML Sign On URL for partition used by IAM SAML Principal
195+
*/
196+
public static readonly SAML_SIGN_ON_URL = 'samlSignOnUrl';
197+
193198
/**
194199
* The ARN of CloudWatch Lambda Insights for a version (e.g. 1.0.98.0)
195200
*/

packages/aws-cdk-lib/region-info/lib/region-info.ts

+8
Original file line numberDiff line numberDiff line change
@@ -197,4 +197,12 @@ export class RegionInfo {
197197
public paramsAndSecretsLambdaLayerArn(version: string, architecture: string): string | undefined {
198198
return Fact.find(this.name, FactName.paramsAndSecretsLambdaLayer(version, architecture));
199199
}
200+
201+
/**
202+
* SAML Sign On URL used by IAM SAML Principals.
203+
*/
204+
public get samlSignOnUrl(): string | undefined {
205+
return Fact.find(this.name, FactName.SAML_SIGN_ON_URL);
206+
}
207+
200208
}

0 commit comments

Comments
 (0)