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): choice-based authentication (passwordless sign-in / passkey sign-in) #32369

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

Tietew
Copy link
Contributor

@Tietew Tietew commented Dec 3, 2024

Issue # (if applicable)

Closes #32265.

Reason for this change

User Pool has introduced choice-based authentication, including passwordless sign-in and passkey (WebAuthn) sign-in.
For details, see Manage authentication methods in AWS SDKs.

Related PRs:

Description of changes

Added following properties:

  • allowedFirstAuthFactors - allowed first authenticate factors
  • passkeyRelyingPartyId - the authentication domain used as passkey relying party ID
  • passkeyUserVerification - configure user verification to be preferred or required

Description of how you validated changes

Added unit test and an integ test.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added admired-contributor [Pilot] contributed between 13-24 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2 labels Dec 3, 2024
@aws-cdk-automation aws-cdk-automation requested a review from a team December 3, 2024 06:47
@Tietew
Copy link
Contributor Author

Tietew commented Dec 3, 2024

This PR is draft until #32367 is merged. Ready now.


// TODO: validate whether the feature plan is not Lite

const allowedFirstAuthFactors = ['PASSWORD'];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When 'PASSWORD' is missing, CloudFormations fails with following error:

Resource handler returned message: "Invalid request provided: PASSWORD should be configured as one of the allowed first auth factors."

Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 80.79%. Comparing base (ccc9f5e) to head (3c1778b).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #32369   +/-   ##
=======================================
  Coverage   80.79%   80.79%           
=======================================
  Files         232      232           
  Lines       14106    14106           
  Branches     2452     2452           
=======================================
  Hits        11397    11397           
  Misses       2429     2429           
  Partials      280      280           
Flag Coverage Δ
suite.unit 80.79% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
packages/aws-cdk 79.53% <ø> (ø)
packages/aws-cdk-lib/core 82.17% <ø> (ø)

@Tietew Tietew force-pushed the cognito-userpool-passwordless branch from 0d5449e to 53ffbfb Compare December 6, 2024 04:07
@Tietew Tietew changed the title feat(cognito): passwordless sign-in feat(cognito): choice-based authentication (passwordless sign-in / passkey sign-in) Dec 6, 2024
GavinZZ pushed a commit that referenced this pull request Dec 6, 2024
### Issue # (if applicable)

N/A

### Reason for this change

Amazon Cognito introduces the feature plans which replaces the Advanced
Security Mode.
See:
https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-sign-in-feature-plans.html

Related to #32369 - passwordless sign-in requires Essentials or higher
feature plan.

### Description of changes

- Add new `featurePlan` property and `FeaturePlan` enum to specify user
pool feature plan.
- Deprecate `advancedSecurityMode` property and `AdvancedSecurityMode`
enum.

Note that the previous AWS document about Advanced Security Mode is now
redirected to [Advanced security with threat
protection](https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pool-settings-threat-protection.html).

### Description of how you validated changes

Added new unit tests and an integ test.

### Checklist
- [x] My code adheres to the [CONTRIBUTING
GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and
[DESIGN
GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md)

----

*By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache-2.0 license*

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@Tietew Tietew marked this pull request as ready for review December 7, 2024 03:17
@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Dec 7, 2024
Copy link
Contributor

@lpizzinidev lpizzinidev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Sorry for the super-late review

@@ -5,7 +5,7 @@ import { Role, ServicePrincipal } from '../../aws-iam';
import * as kms from '../../aws-kms';
import * as lambda from '../../aws-lambda';
import { CfnParameter, Duration, Stack, Tags } from '../../core';
import { AccountRecovery, Mfa, NumberAttribute, StringAttribute, UserPool, UserPoolIdentityProvider, UserPoolOperation, VerificationEmailStyle, UserPoolEmail, AdvancedSecurityMode, LambdaVersion, FeaturePlan } from '../lib';
import { AccountRecovery, Mfa, NumberAttribute, StringAttribute, UserPool, UserPoolIdentityProvider, UserPoolOperation, VerificationEmailStyle, UserPoolEmail, AdvancedSecurityMode, LambdaVersion, FeaturePlan, PasskeyUserVerification } from '../lib';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this line correctly formatted? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's ok because eslint passes.

@@ -1322,6 +1388,28 @@ export class UserPool extends UserPoolBase {
});
}

private configureSignInPolicy(props: UserPoolProps): CfnUserPool.SignInPolicyProperty | undefined {
if (!props.allowedFirstAuthFactors) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should we handle allowedFirstAuthFactors: {}?
With the current implementation AllowedFirstAuthFactors: ['PASSWORD'] will be set explicitly by the CDK.
Maybe it's better to return undefined and let CFN handle the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated to return undefined explicitly.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jan 28, 2025
@Tietew
Copy link
Contributor Author

Tietew commented Jan 30, 2025

@lpizzinidev Thank you for your comments! I've pushed some modifications.

Comment on lines 1432 to 1434
if (allowedFirstAuthFactors.length === 1) {
return undefined;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could introduce subtle bugs in case the number of required auth methods changes for some reason.
Let's check !Object.keys(allowedFirstAuthFactors).length at L1417 instead.

Copy link
Contributor Author

@Tietew Tietew Feb 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your suggestion.

But I'll revert this because:

  1. Create a stack with a user pool including SignInPolicy: { AllowedFirstAuthFactors: ['PASSWORD','WEB_AUTHN'] }
  2. Remove the SignInPolicy then update the stack
  3. Management console shows the user pool still enables choice-based sign-in with Password and Passkey
  4. Set SignInPolicy: { AllowedFirstAuthFactors: ['PASSWORD'] } then update the stack again
  5. Management console shows the user pool disables choice-based sign-in.

Therefore, we should provide the way to disable choice-based sign-in explicitly by specifying allowedFirstAuthFactors: {}.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar issue: #30796

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 69e8b8b
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@Tietew
Copy link
Contributor Author

Tietew commented Feb 3, 2025

@lpizzinidev
I've pushed the revert and an additional test for explicit allowedFirstAuthFactors: {}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
admired-contributor [Pilot] contributed between 13-24 PRs to the CDK effort/medium Medium work item – several days of effort feature-request A feature should be added or improved. p2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cognito: Passwordless authentication support
3 participants