diff --git a/packages/@aws-cdk/aws-iam/README.md b/packages/@aws-cdk/aws-iam/README.md index f2b86ccff2f59..8cf5978aaa7c6 100644 --- a/packages/@aws-cdk/aws-iam/README.md +++ b/packages/@aws-cdk/aws-iam/README.md @@ -364,6 +364,47 @@ const provider = new iam.OpenIdConnectProvider(this, 'MyProvider', { const principal = new iam.OpenIdConnectPrincipal(provider); ``` +## SAML provider + +An IAM SAML 2.0 identity provider is an entity in IAM that describes an external +identity provider (IdP) service that supports the SAML 2.0 (Security Assertion +Markup Language 2.0) standard. You use an IAM identity provider when you want +to establish trust between a SAML-compatible IdP such as Shibboleth or Active +Directory Federation Services and AWS, so that users in your organization can +access AWS resources. IAM SAML identity providers are used as principals in an +IAM trust policy. + +```ts +new iam.SamlProvider(this, 'Provider', { + metadataDocument: iam.SamlMetadataDocument.fromFile('/path/to/saml-metadata-document.xml'), +}); +``` + +The `SamlPrincipal` class can be used as a principal with a `SamlProvider`: + +```ts +const provider = new iam.SamlProvider(this, 'Provider', { + metadataDocument: iam.SamlMetadataDocument.fromFile('/path/to/saml-metadata-document.xml'), +}); +const principal = new iam.SamlPrincipal(provider, { + StringEquals: { + 'SAML:iss': 'issuer', + }, +}); +``` + +When creating a role for programmatic and AWS Management Console access, use the `SamlConsolePrincipal` +class: + +```ts +const provider = new iam.SamlProvider(this, 'Provider', { + metadataDocument: iam.SamlMetadataDocument.fromFile('/path/to/saml-metadata-document.xml'), +}); +new iam.Role(this, 'Role', { + assumedBy: new iam.SamlConsolePrincipal(provider), +}); +``` + ## Users IAM manages users for your AWS account. To create a new user: diff --git a/packages/@aws-cdk/aws-iam/lib/index.ts b/packages/@aws-cdk/aws-iam/lib/index.ts index 19b8a156ba598..06c2a9bb6cdcd 100644 --- a/packages/@aws-cdk/aws-iam/lib/index.ts +++ b/packages/@aws-cdk/aws-iam/lib/index.ts @@ -12,6 +12,7 @@ export * from './grant'; export * from './unknown-principal'; export * from './oidc-provider'; export * from './permissions-boundary'; +export * from './saml-provider'; // AWS::IAM CloudFormation Resources: export * from './iam.generated'; diff --git a/packages/@aws-cdk/aws-iam/lib/principals.ts b/packages/@aws-cdk/aws-iam/lib/principals.ts index ee4cdf0c43e27..6295b8fa966e9 100644 --- a/packages/@aws-cdk/aws-iam/lib/principals.ts +++ b/packages/@aws-cdk/aws-iam/lib/principals.ts @@ -2,6 +2,7 @@ import * as cdk from '@aws-cdk/core'; import { Default, RegionInfo } from '@aws-cdk/region-info'; import { IOpenIdConnectProvider } from './oidc-provider'; import { Condition, Conditions, PolicyStatement } from './policy-statement'; +import { ISamlProvider } from './saml-provider'; import { mergePrincipal } from './util'; /** @@ -493,6 +494,38 @@ export class OpenIdConnectPrincipal extends WebIdentityPrincipal { } } +/** + * Principal entity that represents a SAML federated identity provider + */ +export class SamlPrincipal extends FederatedPrincipal { + constructor(samlProvider: ISamlProvider, conditions: Conditions) { + super(samlProvider.samlProviderArn, conditions, 'sts:AssumeRoleWithSAML'); + } + + public toString() { + return `SamlPrincipal(${this.federated})`; + } +} + +/** + * Principal entity that represents a SAML federated identity provider for + * programmatic and AWS Management Console access. + */ +export class SamlConsolePrincipal extends SamlPrincipal { + constructor(samlProvider: ISamlProvider, conditions: Conditions = {}) { + super(samlProvider, { + ...conditions, + StringEquals: { + 'SAML:aud': 'https://signin.aws.amazon.com/saml', + }, + }); + } + + public toString() { + return `SamlConsolePrincipal(${this.federated})`; + } +} + /** * Use the AWS account into which a stack is deployed as the principal entity in a policy */ diff --git a/packages/@aws-cdk/aws-iam/lib/saml-provider.ts b/packages/@aws-cdk/aws-iam/lib/saml-provider.ts new file mode 100644 index 0000000000000..33712adb60ed2 --- /dev/null +++ b/packages/@aws-cdk/aws-iam/lib/saml-provider.ts @@ -0,0 +1,100 @@ +import * as fs from 'fs'; +import { IResource, Resource, Token } from '@aws-cdk/core'; +import { Construct } from 'constructs'; +import { CfnSAMLProvider } from './iam.generated'; + +/** + * A SAML provider + */ +export interface ISamlProvider extends IResource { + /** + * The Amazon Resource Name (ARN) of the provider + * + * @attribute + */ + readonly samlProviderArn: string; +} + +/** + * Properties for a SAML provider + */ +export interface SamlProviderProps { + /** + * The name of the provider to create. + * + * This parameter allows a string of characters consisting of upper and + * lowercase alphanumeric characters with no spaces. You can also include + * any of the following characters: _+=,.@- + * + * Length must be between 1 and 128 characters. + * + * @default - a CloudFormation generated name + */ + readonly name?: string; + + /** + * An XML document generated by an identity provider (IdP) that supports + * SAML 2.0. The document includes the issuer's name, expiration information, + * and keys that can be used to validate the SAML authentication response + * (assertions) that are received from the IdP. You must generate the metadata + * document using the identity management software that is used as your + * organization's IdP. + */ + readonly metadataDocument: SamlMetadataDocument; +} + +/** + * A SAML metadata document + */ +export abstract class SamlMetadataDocument { + /** + * Create a SAML metadata document from a XML string + */ + public static fromXml(xml: string): SamlMetadataDocument { + return { xml }; + } + + /** + * Create a SAML metadata document from a XML file + */ + public static fromFile(path: string): SamlMetadataDocument { + return { xml: fs.readFileSync(path, 'utf-8') }; + } + + /** + * The XML content of the metadata document + */ + public abstract readonly xml: string; +} + +/** + * A SAML provider + */ +export class SamlProvider extends Resource implements ISamlProvider { + /** + * Import an existing provider + */ + public static fromSamlProviderArn(scope: Construct, id: string, samlProviderArn: string): ISamlProvider { + class Import extends Resource implements ISamlProvider { + public readonly samlProviderArn = samlProviderArn; + } + return new Import(scope, id); + } + + public readonly samlProviderArn: string; + + constructor(scope: Construct, id: string, props: SamlProviderProps) { + super(scope, id); + + if (props.name && !Token.isUnresolved(props.name) && !/^[\w+=,.@-]{1,128}$/.test(props.name)) { + throw new Error('Invalid SAML provider name. The name must be a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-. Length must be between 1 and 128 characters.'); + } + + const samlProvider = new CfnSAMLProvider(this, 'Resource', { + name: this.physicalName, + samlMetadataDocument: props.metadataDocument.xml, + }); + + this.samlProviderArn = samlProvider.ref; + } +} diff --git a/packages/@aws-cdk/aws-iam/package.json b/packages/@aws-cdk/aws-iam/package.json index 6455688b5c006..76cd09b7b2d9a 100644 --- a/packages/@aws-cdk/aws-iam/package.json +++ b/packages/@aws-cdk/aws-iam/package.json @@ -105,6 +105,7 @@ "from-signature:@aws-cdk/aws-iam.Role.fromRoleArn", "construct-interface-extends-iconstruct:@aws-cdk/aws-iam.IManagedPolicy", "props-physical-name:@aws-cdk/aws-iam.OpenIdConnectProviderProps", + "props-physical-name:@aws-cdk/aws-iam.SamlProviderProps", "resource-interface-extends-resource:@aws-cdk/aws-iam.IManagedPolicy", "docs-public-apis:@aws-cdk/aws-iam.IUser" ] diff --git a/packages/@aws-cdk/aws-iam/test/integ.saml-provider.expected.json b/packages/@aws-cdk/aws-iam/test/integ.saml-provider.expected.json new file mode 100644 index 0000000000000..6a5263ebc9675 --- /dev/null +++ b/packages/@aws-cdk/aws-iam/test/integ.saml-provider.expected.json @@ -0,0 +1,34 @@ +{ + "Resources": { + "Provider2281708E": { + "Type": "AWS::IAM::SAMLProvider", + "Properties": { + "SamlMetadataDocument": "\n\n \n \n \n \n \n \n \n \n \n \n xF+xF7hmYedlu04o41mAyvIFBnXuvGE368C9oNLICCA=\n \n \n cGs8ZgnhtOluTKeRZHWjLrtvP9mUxHvSpKWSM5L4MFwojXZ39HIxCAAB22VseLVn8nMH0JxEAze/SzxraCewvJmYrUYKVgECl8kaQ1AKfbWHmrqyCRm9+WX6Fsj9SEGRNOPRfVpceVZYFrw3rimgjYZq/hyjvuEsp/6Eu+2RrO/mCNT7J0y5luOXLeHwJfeNalcl1mHA0JMCusnwfQOvRjkgOKL8pvDyXti+cvicDKqExeDGTaUoUyyynNWXLBLHHUhq29ej80D6lPVZWFqAgsZPm/O3spLhWl974PzDnX0qMds3aieZbHmuots+Cdy0LXQVHLjhRbDU8F6+BU+lRQ==\n \n \n MIIDBTCCAe2gAwIBAgIQN33ROaIJ6bJBWDCxtmJEbjANBgkqhkiG9w0BAQsFADAtMSswKQYDVQQDEyJhY2NvdW50cy5hY2Nlc3Njb250cm9sLndpbmRvd3Mubm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UEAxMiYWNjb3VudHMuYWNjZXNzY29udHJvbC53aW5kb3dzLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALH7FzF1rjvnZ4i2iBC2tz8qs/WP61n3/wFawgJxUnTx2vP/z5pG7f8qvumd7taOII0aSlp648SIfMw59WdUUtup5CnDYOcX1sUdivAj20m2PIDK6f+KWZ+7YKxJqCzJMH4GGlQvuDIhRKNT9oHfZgnYCCAmjXmJBtWyD052qqrkzOSn0/e9TKbjlTnTNcrIno3XDQ7xG+79vOD2GZMNopsKogWNxUdLFRu44ClKLRb4Xe00eVrANtBkv+mSJFFJS1Gxv611hpdGI2S0v1H+KvB26O7vuzGhZ/AevRemGhXQ5V5vwNEqXnVRVkBRszLKeN/+rxM436xQyVQGJMG+sVECAwEAAaMhMB8wHQYDVR0OBBYEFLlRBSxxgmNPObCFrl+hSsbcvRkcMA0GCSqGSIb3DQEBCwUAA4IBAQB+UQFTNs6BUY3AIGkS2ZRuZgJsNEr/ZEM4aCs2domd2Oqj7+5iWsnPh5CugFnI4nd+ZLgKVHSD6acQ27we+eNY6gxfpQCY1fiN/uKOOsA0If8IbPdBEhtPerRgPJFXLHaYVqD8UYDo5KNCcoB4Kh8nvCWRGPUUHPRqp7AnAcVrcbiXA/bmMCnFWuNNahcaAKiJTxYlKDaDIiPN35yECYbDj0PBWJUxobrvj5I275jbikkp8QSLYnSU/v7dMDUbxSLfZ7zsTuaF2Qx+L62PsYTwLzIFX3M8EMSQ6h68TupFTi5n0M2yIXQgoRoNEDWNJZ/aZMY/gqT02GQGBWrh+/vJ\n \n \n \n \n \n Name\n The mutable display name of the user.\n \n \n Subject\n An immutable, globally unique, non-reusable identifier of the user that is unique to the application for which a token is issued.\n \n \n Given Name\n First name of the user.\n \n \n Surname\n Last name of the user.\n \n \n Display Name\n Display name of the user.\n \n \n Nick Name\n Nick name of the user.\n \n \n Authentication Instant\n The time (UTC) when the user is authenticated to Windows Azure Active Directory.\n \n \n Authentication Method\n The method that Windows Azure Active Directory uses to authenticate users.\n \n \n ObjectIdentifier\n Primary identifier for the user in the directory. Immutable, globally unique, non-reusable.\n \n \n TenantId\n Identifier for the user's tenant.\n \n \n IdentityProvider\n Identity provider for the user.\n \n \n Email\n Email address of the user.\n \n \n Groups\n Groups of the user.\n \n \n External Access Token\n Access token issued by external identity provider.\n \n \n External Access Token Expiration\n UTC expiration time of access token issued by external identity provider.\n \n \n External OpenID 2.0 Identifier\n OpenID 2.0 identifier issued by external identity provider.\n \n \n GroupsOverageClaim\n Issued when number of user's group claims exceeds return limit.\n \n \n Role Claim\n Roles that the user or Service Principal is attached to\n \n \n RoleTemplate Id Claim\n Role template id of the Built-in Directory Roles that the user is a member of\n \n \n \n \n https://login.microsoftonline.com/9ecb31cb-702e-4ce0-ae22-bcee28d49d49/wsfed\n \n \n \n \n https://login.microsoftonline.com/9ecb31cb-702e-4ce0-ae22-bcee28d49d49/wsfed\n \n \n \n \n \n \n \n MIIDBTCCAe2gAwIBAgIQN33ROaIJ6bJBWDCxtmJEbjANBgkqhkiG9w0BAQsFADAtMSswKQYDVQQDEyJhY2NvdW50cy5hY2Nlc3Njb250cm9sLndpbmRvd3MubmV0MB4XDTIwMTIyMTIwNTAxN1oXDTI1MTIyMDIwNTAxN1owLTErMCkGA1UEAxMiYWNjb3VudHMuYWNjZXNzY29udHJvbC53aW5kb3dzLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKGiy0/YZHEo9rRn2bI27u189Sq7NKhInFz5hLCSjgUB2rmf5ETNR3RJIDiW1M51LKROsTrjkl45cxK6gcVwLuEgr3L1TgmBtr/Rt/riKyxeXbLQ9LGBwaNVaJrSscxfdFbJa5J+qzUIFBiFoL7kE8ZtbkZJWBTxHEyEcNC52JJ8ydOhgvZYykete8AAVa2TZAbg4ECo9+6nMsaGsSBncRHJlRWVycq8Q4HV4faMEZmZ+iyCZRo2fZufXpn7sJwZ7CEBuw4qycHvUl6y153sUUFqsswnZGGjqp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xM436xQyVQGJMG+sVECAwEAAaMhMB8wHQYDVR0OBBYEFLlRBSxxgmNPObCFrl+hSsbcvRkcMA0GCSqGSIb3DQEBCwUAA4IBAQB+UQFTNs6BUY3AIGkS2ZRuZgJsNEr/ZEM4aCs2domd2Oqj7+5iWsnPh5CugFnI4nd+ZLgKVHSD6acQ27we+eNY6gxfpQCY1fiN/uKOOsA0If8IbPdBEhtPerRgPJFXLHaYVqD8UYDo5KNCcoB4Kh8nvCWRGPUUHPRqp7AnAcVrcbiXA/bmMCnFWuNNahcaAKiJTxYlKDaDIiPN35yECYbDj0PBWJUxobrvj5I275jbikkp8QSLYnSU/v7dMDUbxSLfZ7zsTuaF2Qx+L62PsYTwLzIFX3M8EMSQ6h68TupFTi5n0M2yIXQgoRoNEDWNJZ/aZMY/gqT02GQGBWrh+/vJ\n \n \n \n \n \n https://sts.windows.net/9ecb31cb-702e-4ce0-ae22-bcee28d49d49/\n \n \n \n \n https://login.microsoftonline.com/9ecb31cb-702e-4ce0-ae22-bcee28d49d49/wsfed\n \n \n \n \n https://login.microsoftonline.com/9ecb31cb-702e-4ce0-ae22-bcee28d49d49/wsfed\n \n \n \n \n \n \n \n MIIDBTCCAe2gAwIBAgIQN33ROaIJ6bJBWDCxtmJEbjANBgkqhkiG9w0BAQsFADAtMSswKQYDVQQDEyJhY2NvdW50cy5hY2Nlc3Njb250cm9sLndpbmRvd3MubmV0MB4XDTIwMTIyMTIwNTAxN1oXDTI1MTIyMDIwNTAxN1owLTErMCkGA1UEAxMiYWNjb3VudHMuYWNjZXNzY29udHJvbC53aW5kb3dzLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKGiy0/YZHEo9rRn2bI27u189Sq7NKhInFz5hLCSjgUB2rmf5ETNR3RJIDiW1M51LKROsTrjkl45cxK6gcVwLuEgr3L1TgmBtr/Rt/riKyxeXbLQ9LGBwaNVaJrSscxfdFbJa5J+qzUIFBiFoL7kE8ZtbkZJWBTxHEyEcNC52J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OD2GZMNopsKogWNxUdLFRu44ClKLRb4Xe00eVrANtBkv+mSJFFJS1Gxv611hpdGI2S0v1H+KvB26O7vuzGhZ/AevRemGhXQ5V5vwNEqXnVRVkBRszLKeN/+rxM436xQyVQGJMG+sVECAwEAAaMhMB8wHQYDVR0OBBYEFLlRBSxxgmNPObCFrl+hSsbcvRkcMA0GCSqGSIb3DQEBCwUAA4IBAQB+UQFTNs6BUY3AIGkS2ZRuZgJsNEr/ZEM4aCs2domd2Oqj7+5iWsnPh5CugFnI4nd+ZLgKVHSD6acQ27we+eNY6gxfpQCY1fiN/uKOOsA0If8IbPdBEhtPerRgPJFXLHaYVqD8UYDo5KNCcoB4Kh8nvCWRGPUUHPRqp7AnAcVrcbiXA/bmMCnFWuNNahcaAKiJTxYlKDaDIiPN35yECYbDj0PBWJUxobrvj5I275jbikkp8QSLYnSU/v7dMDUbxSLfZ7zsTuaF2Qx+L62PsYTwLzIFX3M8EMSQ6h68TupFTi5n0M2yIXQgoRoNEDWNJZ/aZMY/gqT02GQGBWrh+/vJ\n \n \n \n \n \n \n \n\n" + } + }, + "Role1ABCC5F0": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRoleWithSAML", + "Condition": { + "StringEquals": { + "SAML:aud": "https://signin.aws.amazon.com/saml" + } + }, + "Effect": "Allow", + "Principal": { + "Federated": { + "Ref": "Provider2281708E" + } + } + } + ], + "Version": "2012-10-17" + } + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-iam/test/integ.saml-provider.ts b/packages/@aws-cdk/aws-iam/test/integ.saml-provider.ts new file mode 100644 index 0000000000000..e421b8c4d2b01 --- /dev/null +++ b/packages/@aws-cdk/aws-iam/test/integ.saml-provider.ts @@ -0,0 +1,22 @@ +import * as path from 'path'; +import { App, Stack, StackProps } from '@aws-cdk/core'; +import { Construct } from 'constructs'; +import * as iam from '../lib'; + +class TestStack extends Stack { + constructor(scope: Construct, id: string, props?: StackProps) { + super(scope, id, props); + + const provider = new iam.SamlProvider(this, 'Provider', { + metadataDocument: iam.SamlMetadataDocument.fromFile(path.join(__dirname, 'saml-metadata-document.xml')), + }); + + new iam.Role(this, 'Role', { + assumedBy: new iam.SamlConsolePrincipal(provider), + }); + } +} + +const app = new App(); +new TestStack(app, 'cdk-saml-provider'); +app.synth(); diff --git a/packages/@aws-cdk/aws-iam/test/principals.test.ts b/packages/@aws-cdk/aws-iam/test/principals.test.ts index 115430ed58552..43ed8433c47f6 100644 --- a/packages/@aws-cdk/aws-iam/test/principals.test.ts +++ b/packages/@aws-cdk/aws-iam/test/principals.test.ts @@ -127,4 +127,42 @@ test('use OpenID Connect principal from provider', () => { // THEN expect(stack.resolve(principal.federated)).toStrictEqual({ Ref: 'MyProvider730BA1C8' }); -}); \ No newline at end of file +}); + +test('SAML principal', () => { + // GIVEN + const stack = new Stack(); + const provider = new iam.SamlProvider(stack, 'MyProvider', { + metadataDocument: iam.SamlMetadataDocument.fromXml('document'), + }); + + // WHEN + const principal = new iam.SamlConsolePrincipal(provider); + new iam.Role(stack, 'Role', { + assumedBy: principal, + }); + + // THEN + expect(stack.resolve(principal.federated)).toStrictEqual({ Ref: 'MyProvider730BA1C8' }); + expect(stack).toHaveResource('AWS::IAM::Role', { + AssumeRolePolicyDocument: { + Statement: [ + { + Action: 'sts:AssumeRoleWithSAML', + Condition: { + StringEquals: { + 'SAML:aud': 'https://signin.aws.amazon.com/saml', + }, + }, + Effect: 'Allow', + Principal: { + Federated: { + Ref: 'MyProvider730BA1C8', + }, + }, + }, + ], + Version: '2012-10-17', + }, + }); +}); diff --git a/packages/@aws-cdk/aws-iam/test/saml-metadata-document.xml b/packages/@aws-cdk/aws-iam/test/saml-metadata-document.xml new file mode 100644 index 0000000000000..a53ae7763165d --- /dev/null +++ b/packages/@aws-cdk/aws-iam/test/saml-metadata-document.xml @@ -0,0 +1,177 @@ + + + + + + + + + + + + + xF+xF7hmYedlu04o41mAyvIFBnX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uKOOsA0If8IbPdBEhtPerRgPJFXLHaYVqD8UYDo5KNCcoB4Kh8nvCWRGPUUHPRqp7AnAcVrcbiXA/bmMCnFWuNNahcaAKiJTxYlKDaDIiPN35yECYbDj0PBWJUxobrvj5I275jbikkp8QSLYnSU/v7dMDUbxSLfZ7zsTuaF2Qx+L62PsYTwLzIFX3M8EMSQ6h68TupFTi5n0M2yIXQgoRoNEDWNJZ/aZMY/gqT02GQGBWrh+/vJ + + + + + + Name + The mutable display name of the user. + + + Subject + An immutable, globally unique, non-reusable identifier of the user that is unique to the application for which a token is issued. + + + Given Name + First name of the user. + + + Surname + Last name of the user. + + + Display Name + Display name of the user. + + + Nick Name + Nick name of the user. + + + Authentication Instant + The time (UTC) when the user is authenticated to Windows Azure Active Directory. + + + Authentication Method + The method that Windows Azure Active Directory uses to authenticate users. + + + ObjectIdentifier + Primary identifier for the user in the directory. Immutable, globally unique, non-reusable. + + + TenantId + Identifier for the user's tenant. + + + IdentityProvider + Identity provider for the user. + + + Email + Email address of the user. + + + Groups + Groups of the user. + + + External Access Token + Access token issued by external identity provider. + + + External Access Token Expiration + UTC expiration time of access token issued by external identity provider. + + + External OpenID 2.0 Identifier + OpenID 2.0 identifier issued by external identity provider. + + + GroupsOverageClaim + Issued when number of user's group claims exceeds return limit. + + + Role Claim + Roles that the user or Service Principal is attached to + + + RoleTemplate Id Claim + Role template id of the Built-in Directory Roles that the user is a member of + + + + + https://login.microsoftonline.com/9ecb31cb-702e-4ce0-ae22-bcee28d49d49/wsfed + + + + + https://login.microsoftonline.com/9ecb31cb-702e-4ce0-ae22-bcee28d49d49/wsfed + + + + + + + + MIIDBTCCAe2gAwIBAgIQN33ROaIJ6bJBWDCxtmJEbjANBgkqhkiG9w0BAQsFADAtMSswKQYDVQQDEyJhY2NvdW50cy5hY2Nlc3Njb250cm9sLndpbmRvd3MubmV0MB4XDTIwMTIyMTIwNTAxN1oXDTI1MTIyMDIwNTAxN1owLTErMCkGA1UEAxMiYWNjb3VudHM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IwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALH7FzF1rjvnZ4i2iBC2tz8qs/WP61n3/wFawgJxUnTx2vP/z5pG7f8qvumd7taOII0aSlp648SIfMw59WdUUtup5CnDYOcX1sUdivAj20m2PIDK6f+KWZ+7YKxJqCzJMH4GGlQvuDIhRKNT9oHfZgnYCCAmjXmJBtWyD052qqrkzOSn0/e9TKbjlTnTNcrIno3XDQ7xG+79vOD2GZMNopsKogWNxUdLFRu44ClKLRb4Xe00eVrANtBkv+mSJFFJS1Gxv611hpdGI2S0v1H+KvB26O7vuzGhZ/AevRemGhXQ5V5vwNEqXnVRVkBRszLKeN/+rxM436xQyVQGJMG+sVECAwEAAaMhMB8wHQYDVR0OBBYEFLlRBSxxgmNPObCFrl+hSsbcvRkcMA0GCSqGSIb3DQEBCwUAA4IBAQB+UQFTNs6BUY3AIGkS2ZRuZgJsNEr/ZEM4aCs2domd2Oqj7+5iWsnPh5CugFnI4nd+ZLgKVHSD6acQ27we+eNY6gxfpQCY1fiN/uKOOsA0If8IbPdBEhtPerRgPJFXLHaYVqD8UYDo5KNCcoB4Kh8nvCWRGPUUHPRqp7AnAcVrcbiXA/bmMCnFWuNNahcaAKiJTxYlKDaDIiPN35yECYbDj0PBWJUxobrvj5I275jbikkp8QSLYnSU/v7dMDUbxSLfZ7zsTuaF2Qx+L62PsYTwLzIFX3M8EMSQ6h68TupFTi5n0M2yIXQgoRoNEDWNJZ/aZMY/gqT02GQGBWrh+/vJ + + + + + + https://sts.windows.net/9ecb31cb-702e-4ce0-ae22-bcee28d49d49/ + + + + + https://login.microsoftonline.com/9ecb31cb-702e-4ce0-ae22-bcee28d49d49/wsfed + + + + + https://login.microsoftonline.com/9ecb31cb-702e-4ce0-ae22-bcee28d49d49/wsfed + + + + + + + + MIIDBTCCAe2gAwIBAgIQN33ROaIJ6bJBWDCxtmJEbjANBgkqhkiG9w0BAQsFADAtMSswKQYDVQQDEyJhY2NvdW50cy5hY2Nlc3Njb250cm9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OVoXDTI2MDIwNjE3MDAzOVowLTErMCkGA1UEAxMiYWNjb3VudHMuYWNjZXNzY29udHJvbC53aW5kb3dzLm5ldDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALH7FzF1rjvnZ4i2iBC2tz8qs/WP61n3/wFawgJxUnTx2vP/z5pG7f8qvumd7taOII0aSlp648SIfMw59WdUUtup5CnDYOcX1sUdivAj20m2PIDK6f+KWZ+7YKxJqCzJMH4GGlQvuDIhRKNT9oHfZgnYCCAmjXmJBtWyD052qqrkzOSn0/e9TKbjlTnTNcrIno3XDQ7xG+79vOD2GZMNopsKogWNxUdLFRu44ClKLRb4Xe00eVrANtBkv+mSJFFJS1Gxv611hpdGI2S0v1H+KvB26O7vuzGhZ/AevRemGhXQ5V5vwNEqXnVRVkBRszLKeN/+rxM436xQyVQGJMG+sVECAwEAAaMhMB8wHQYDVR0OBBYEFLlRBSxxgmNPObCFrl+hSsbcvRkcMA0GCSqGSIb3DQEBCwUAA4IBAQB+UQFTNs6BUY3AIGkS2ZRuZgJsNEr/ZEM4aCs2domd2Oqj7+5iWsnPh5CugFnI4nd+ZLgKVHSD6acQ27we+eNY6gxfpQCY1fiN/uKOOsA0If8IbPdBEhtPerRgPJFXLHaYVqD8UYDo5KNCcoB4Kh8nvCWRGPUUHPRqp7AnAcVrcbiXA/bmMCnFWuNNahcaAKiJTxYlKDaDIiPN35yECYbDj0PBWJUxobrvj5I275jbikkp8QSLYnSU/v7dMDUbxSLfZ7zsTuaF2Qx+L62PsYTwLzIFX3M8EMSQ6h68TupFTi5n0M2yIXQgoRoNEDWNJZ/aZMY/gqT02GQGBWrh+/vJ + + + + + + + + diff --git a/packages/@aws-cdk/aws-iam/test/saml-provider.test.ts b/packages/@aws-cdk/aws-iam/test/saml-provider.test.ts new file mode 100644 index 0000000000000..1878e65c51a14 --- /dev/null +++ b/packages/@aws-cdk/aws-iam/test/saml-provider.test.ts @@ -0,0 +1,25 @@ +import '@aws-cdk/assert/jest'; +import { Stack } from '@aws-cdk/core'; +import { SamlMetadataDocument, SamlProvider } from '../lib'; + +let stack: Stack; +beforeEach(() => { + stack = new Stack(); +}); + +test('SAML provider', () => { + new SamlProvider(stack, 'Provider', { + metadataDocument: SamlMetadataDocument.fromXml('document'), + }); + + expect(stack).toHaveResource('AWS::IAM::SAMLProvider', { + SamlMetadataDocument: 'document', + }); +}); + +test('throws with invalid name', () => { + expect(() => new SamlProvider(stack, 'Provider', { + name: 'invalid name', + metadataDocument: SamlMetadataDocument.fromXml('document'), + })).toThrow(/Invalid SAML provider name/); +});