-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
feat(iam): SAML identity provider #13393
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 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 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,75 @@ | ||
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: 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, | ||
}); | ||
|
||
this.samlProviderArn = samlProvider.ref; | ||
} | ||
} |
This file contains 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
34 changes: 34 additions & 0 deletions
34
packages/@aws-cdk/aws-iam/test/integ.saml-provider.expected.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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,23 @@ | ||
import * as fs from 'fs'; | ||
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: fs.readFileSync(path.join(__dirname, 'saml-metadata-document.xml'), 'utf-8'), | ||
}); | ||
|
||
new iam.Role(this, 'Role', { | ||
assumedBy: new iam.SamlConsolePrincipal(provider), | ||
}); | ||
} | ||
} | ||
|
||
const app = new App(); | ||
new TestStack(app, 'cdk-saml-provider'); | ||
app.synth(); |
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we abstract this away? I don't think anybody would want to inline the XML and read from a file would be the default. So what about providing only a file name to the L2?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In most cases you are right but it could be returned by a custom resource?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So what about a SamlMetadata class that has fromInline and fromFile?