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

Cognito: Cannot create cfn user pool with only email MFA enabled #32615

Open
1 task
dpetzev opened this issue Dec 20, 2024 · 6 comments
Open
1 task

Cognito: Cannot create cfn user pool with only email MFA enabled #32615

dpetzev opened this issue Dec 20, 2024 · 6 comments
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug. effort/small Small work item – less than a day of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2

Comments

@dpetzev
Copy link

dpetzev commented Dec 20, 2024

Describe the bug

Trying to create a Cognito user pool using the L1 construct and ONLY email MFA enabled leads to an error in CloudFormation.

This DOES work if I create the same user pool without any MFA enabled and then go to the AWS console and update it manually to have email only MFA.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Version

No response

Expected Behavior

CloudFormation is able to create the requested resource without issues.

Current Behavior

Error in CloudFormation with this message:

Resource handler returned message: "SMS configuration and Auto verification for phone_number are required when MFA is required/optional (Service: CognitoIdentityProvider, Status Code: 400, Request ID: ..., HandlerErrorCode: InvalidRequest)

Reproduction Steps

Here is an example of a stack that yields the error in CloudFormation

import * as cognito from 'aws-cdk-lib/aws-cognito';
import { App, Stack, StackProps } from 'aws-cdk-lib/core';

export class AuthStack extends Stack {
  constructor(scope: App, id: string, props: StackProps) {
    super(scope, id, props);

    const userPool = new cognito.CfnUserPool(this, 'UserPool', {
      userPoolName: 'UserPool123',
      adminCreateUserConfig: {
        allowAdminCreateUserOnly: true,
        unusedAccountValidityDays: 1,
      },
      usernameAttributes: ['email'],
      usernameConfiguration: {
        caseSensitive: false,
      },
      enabledMfas: ['EMAIL_OTP'],
      mfaConfiguration: 'OPTIONAL',
    });
  }
}

Possible Solution

No response

Additional Information/Context

Very similar bug, but with OTP only MFA enabled #11478

CDK CLI Version

2.173.2

Framework Version

No response

Node.js Version

v18.19.1

OS

Mac OS

Language

TypeScript

Language Version

No response

Other information

No response

@dpetzev dpetzev added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Dec 20, 2024
@github-actions github-actions bot added the @aws-cdk/aws-cognito Related to Amazon Cognito label Dec 20, 2024
@khushail khushail added needs-reproduction This issue needs reproduction. p2 and removed needs-triage This issue or PR still needs to be triaged. labels Dec 20, 2024
@khushail khushail self-assigned this Dec 20, 2024
@khushail khushail added investigating This issue is being investigated and/or work is in progress to resolve the issue. and removed needs-reproduction This issue needs reproduction. labels Dec 23, 2024
@khushail
Copy link
Contributor

Hi @dpetzev , thanks for reporting this. I am able to repro the issue with the given code -

Screenshot 2024-12-26 at 1 16 48 PM

@khushail
Copy link
Contributor

@dpetzev , I see that its mentioned in Cloudformation docs to provide EmailConfiguration as well. could you please try with including the config changes as mentioned and see if that works for you -

EnabledMfas

    Set enabled MFA options on a specified user pool. To disable all MFAs after it has been enabled, set MfaConfiguration to OFF and remove EnabledMfas. MFAs can only be all disabled if MfaConfiguration is OFF. After you enable SMS_MFA, you can only disable it by setting MfaConfiguration to OFF. Can be one of the following values:

        SMS_MFA - Enables MFA with SMS for the user pool. To select this option, you must also provide values for SmsConfiguration.

        SOFTWARE_TOKEN_MFA - Enables software token MFA for the user pool.

        EMAIL_OTP - Enables MFA with email for the user pool. To select this option, you must provide values for EmailConfiguration and within those, set EmailSendingAccount to DEVELOPER.

    Allowed values: SMS_MFA | SOFTWARE_TOKEN_MFA | EMAIL_OTP

    Required: No

    Type: Array of String

@khushail khushail added response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels Dec 26, 2024
@dpetzev
Copy link
Author

dpetzev commented Dec 27, 2024

Hey @khushail, thanks for looking into it. Yes, I had the EmailConfiguration defined as well in the user pool I just omitted it for brevity. Still the same error. It looks similar to:

 emailConfiguration: {
         emailSendingAccount: 'DEVELOPER',
         sourceArn: 'arn:aws:ses:eu-central-1:...',
       },

It seems to me like it's a bug on the CloudFormation part, since the same configuration (user pool with email sending account + only email MFA enabled) is possible through the AWS console, just not with using CloudFormation.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Dec 27, 2024
@khushail
Copy link
Contributor

khushail commented Dec 27, 2024

@dpetzev , thanks for confirming that. Since its a L1 construct that is causing error , this is definitely a cloudformation issue. I will be creating an issue with the coudformation team and you could follow the same for updates. Hope that would be helpful!

@khushail khushail added the needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. label Dec 27, 2024
@khushail khushail removed their assignment Dec 27, 2024
@khushail khushail added the effort/small Small work item – less than a day of effort label Dec 27, 2024
@khushail
Copy link
Contributor

khushail commented Dec 27, 2024

@dpetzev , Issue created with Cloudformation team - aws-cloudformation/cloudformation-coverage-roadmap#2221.

@dpetzev
Copy link
Author

dpetzev commented Dec 27, 2024

@khushail Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-cognito Related to Amazon Cognito bug This issue is a bug. effort/small Small work item – less than a day of effort needs-cfn This issue is waiting on changes to CloudFormation before it can be addressed. p2
Projects
None yet
Development

No branches or pull requests

2 participants