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

feat(cognito): add new AdvancedSecurityMode property #23261

Merged
merged 2 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/@aws-cdk/aws-cognito/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,16 @@ new cognito.UserPool(this, 'UserPool', {
The default for account recovery is by phone if available and by email otherwise.
A user will not be allowed to reset their password via phone if they are also using it for MFA.

#### Advanced Security Mode

User pools can be configured to use Advanced security. You can turn the user pool advanced security features on, and customize the actions that are taken in response to different risks. Or you can use audit mode to gather metrics on detected risks without taking action. In audit mode, the advanced security features publish metrics to Amazon CloudWatch. See the [documentation on Advanced security](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-settings-advanced-security.html) to learn more.

```ts
new cognito.UserPool(this, 'myuserpool', {
// ...
advancedSecurityMode: cognito.AdvancedSecurityMode.ENFORCED,
});
```

### Emails

Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-cognito/lib/user-pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,19 @@ export interface DeviceTracking {
readonly deviceOnlyRememberedOnUserPrompt: boolean;
}

/**
* The different ways in which a user pool's Advanced Security Mode can be configured.
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-cognito-userpool-userpooladdons.html#cfn-cognito-userpool-userpooladdons-advancedsecuritymode
*/
export enum AdvancedSecurityMode {
/** Enable advanced security mode */
ENFORCED = 'ENFORCED',
/** gather metrics on detected risks without taking action. Metrics are published to Amazon CloudWatch */
AUDIT = 'AUDIT',
/** Advanced security mode is disabled */
OFF = 'OFF'
}

/**
* Props for the UserPool construct
*/
Expand Down Expand Up @@ -692,6 +705,12 @@ export interface UserPoolProps {
* @default - no key ID configured
*/
readonly customSenderKmsKey?: IKey;

/**
* The user pool's Advanced Security Mode
* @default - no value
*/
readonly advancedSecurityMode?: AdvancedSecurityMode;
}

/**
Expand Down Expand Up @@ -934,6 +953,9 @@ export class UserPool extends UserPoolBase {
emailVerificationSubject,
smsVerificationMessage,
verificationMessageTemplate,
userPoolAddOns: undefinedIfNoKeys({
advancedSecurityMode: props.advancedSecurityMode,
}),
schema: this.schemaConfiguration(props),
mfaConfiguration: props.mfa,
enabledMfas: this.mfaConfiguration(props),
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"version":"21.0.0"}
{"version":"22.0.0"}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"version": "21.0.0",
"version": "22.0.0",
"files": {
"7df3ca05ace569184cc645d485b05885dc2e13f745606873a57afa9d264ecc08": {
"d52bd1bc71dfc61d4ad7024fe0716269f71e86ea085d0ccd71bcbe68e8df1c34": {
"source": {
"path": "integ-user-pool.template.json",
"packaging": "file"
},
"destinations": {
"current_account-current_region": {
"bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}",
"objectKey": "7df3ca05ace569184cc645d485b05885dc2e13f745606873a57afa9d264ecc08.json",
"objectKey": "d52bd1bc71dfc61d4ad7024fe0716269f71e86ea085d0ccd71bcbe68e8df1c34.json",
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}"
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,9 @@
"phone_number"
]
},
"UserPoolAddOns": {
"AdvancedSecurityMode": "ENFORCED"
},
"UserPoolName": "MyUserPool",
"VerificationMessageTemplate": {
"DefaultEmailOption": "CONFIRM_WITH_CODE",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "21.0.0",
"version": "22.0.0",
"testCases": {
"integ.user-pool-explicit-props": {
"stacks": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
{
"version": "21.0.0",
"version": "22.0.0",
"artifacts": {
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
},
"integ-user-pool.assets": {
"type": "cdk:asset-manifest",
"properties": {
Expand All @@ -23,7 +17,7 @@
"validateOnSynth": false,
"assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}",
"cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/7df3ca05ace569184cc645d485b05885dc2e13f745606873a57afa9d264ecc08.json",
"stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/d52bd1bc71dfc61d4ad7024fe0716269f71e86ea085d0ccd71bcbe68e8df1c34.json",
"requiresBootstrapStackVersion": 6,
"bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version",
"additionalDependencies": [
Expand Down Expand Up @@ -260,99 +254,15 @@
"type": "aws:cdk:logicalId",
"data": "CheckBootstrapVersion"
}
],
"createAuthChallengeCreateAuthChallengeCognito57E2297E": [
{
"type": "aws:cdk:logicalId",
"data": "createAuthChallengeCreateAuthChallengeCognito57E2297E",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
],
"customMessageCustomMessageCognitoB4F894A6": [
{
"type": "aws:cdk:logicalId",
"data": "customMessageCustomMessageCognitoB4F894A6",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
],
"defineAuthChallengeDefineAuthChallengeCognito4DBD8021": [
{
"type": "aws:cdk:logicalId",
"data": "defineAuthChallengeDefineAuthChallengeCognito4DBD8021",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
],
"postAuthenticationPostAuthenticationCognito8B923BC3": [
{
"type": "aws:cdk:logicalId",
"data": "postAuthenticationPostAuthenticationCognito8B923BC3",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
],
"postConfirmationPostConfirmationCognito9D010393": [
{
"type": "aws:cdk:logicalId",
"data": "postConfirmationPostConfirmationCognito9D010393",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
],
"preAuthenticationPreAuthenticationCognito67FACB54": [
{
"type": "aws:cdk:logicalId",
"data": "preAuthenticationPreAuthenticationCognito67FACB54",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
],
"preSignUpPreSignUpCognitoE986CC53": [
{
"type": "aws:cdk:logicalId",
"data": "preSignUpPreSignUpCognitoE986CC53",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
],
"preTokenGenerationPreTokenGenerationCognitoC1959918": [
{
"type": "aws:cdk:logicalId",
"data": "preTokenGenerationPreTokenGenerationCognitoC1959918",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
],
"userMigrationUserMigrationCognito29EEC4AD": [
{
"type": "aws:cdk:logicalId",
"data": "userMigrationUserMigrationCognito29EEC4AD",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
],
"verifyAuthChallengeResponseVerifyAuthChallengeResponseCognito9DC48AFC": [
{
"type": "aws:cdk:logicalId",
"data": "verifyAuthChallengeResponseVerifyAuthChallengeResponseCognito9DC48AFC",
"trace": [
"!!DESTRUCTIVE_CHANGES: WILL_DESTROY"
]
}
]
},
"displayName": "integ-user-pool"
},
"Tree": {
"type": "cdk:tree",
"properties": {
"file": "tree.json"
}
}
}
}
Loading