-
Notifications
You must be signed in to change notification settings - Fork 4k
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): better control sms role creation #9513
Conversation
- Introduce a property `enableSmsRole` that can be used to override CDK logic and explicitly enable or disable automatic creation of an IAM role for SMS. - Instead of creating the SMS role by default, all of the time, be smart about determining when the role is actually needed. Create the role only if (a) SMS is configured as MFA second factor, (b) sign in via phone number is enabled, or (c) phone verification is required. BREAKING CHANGE: CDK may now remove a previously created IAM role for SMS. The role will be removed only because it's not actually required by the user pool based on its configuration, so this should have no impact. This behaviour can be explicitly overridden by setting `enableSmsRole` property. closes #6943
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.
@nija-at Are you comfortable with the integ tests now not covering the SMS role creation? Or is there another one that does? I'm just a little concerned we lost coverage here.
To your discretion, just wanted to mention it. Adding the do-not-merge
label for now but feel free to remove and merge.
const mfaEnabled = props.mfa && props.mfa !== Mfa.OFF; | ||
const mfaSms = !props.mfaSecondFactor || props.mfaSecondFactor.sms; // mfaSecondFactor.sms is true, by default if MFA is 'on' |
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.
Seems like you can reuse the mfaConfiguration
method here:
aws-cdk/packages/@aws-cdk/aws-cognito/lib/user-pool.ts
Lines 875 to 892 in e878f9c
private mfaConfiguration(props: UserPoolProps): string[] | undefined { | |
if (props.mfa === undefined || props.mfa === Mfa.OFF) { | |
// since default is OFF, treat undefined and OFF the same way | |
return undefined; | |
} else if (props.mfaSecondFactor === undefined && | |
(props.mfa === Mfa.OPTIONAL || props.mfa === Mfa.REQUIRED)) { | |
return [ 'SMS_MFA' ]; | |
} else { | |
const enabledMfas = []; | |
if (props.mfaSecondFactor!.sms) { | |
enabledMfas.push('SMS_MFA'); | |
} | |
if (props.mfaSecondFactor!.otp) { | |
enabledMfas.push('SOFTWARE_TOKEN_MFA'); | |
} | |
return enabledMfas; | |
} | |
} |
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.
Good catch. Changed.
These are tested in |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Introduce a property
enableSmsRole
that can be used to override CDKlogic and explicitly enable or disable automatic creation of an IAM role
for SMS.
Instead of creating the SMS role by default, all of the time, be smart
about determining when the role is actually needed. Create the role only
if (a) SMS is configured as MFA second factor, (b) sign in via phone
number is enabled, or (c) phone verification is required.
closes #6943
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license