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

fix(cognito/userpool)!: MFA not always working #1533

Merged
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
6 changes: 6 additions & 0 deletions apis/cognitoidentityprovider/generator-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ ignore:
- CreateIdentityProviderInput.UserPoolId
- CreateIdentityProviderInput.ProviderDetails
- CreateIdentityProviderOutput.IdentityProvider.ProviderDetails
- CreateUserPoolInput.AdminCreateUserConfig.UnusedAccountValidityDays
resources:
UserPool:
fields:
SoftwareTokenMfaConfiguration:
from:
operation: SetUserPoolMfaConfig
path: SoftwareTokenMfaConfiguration
exceptions:
errors:
# In the API this is a 400 error, but we have to define a 404 error here,
Expand Down
10 changes: 5 additions & 5 deletions apis/cognitoidentityprovider/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions apis/cognitoidentityprovider/v1alpha1/zz_types.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions apis/cognitoidentityprovider/v1alpha1/zz_user_pool.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions examples/cognito/userpool.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,34 @@ spec:
forProvider:
region: us-east-1
poolName: examplePool
# "After you create a user pool, you can't change or remove sign-in options.":
# concerns aliasAttributes, usernameAttributes, UsernameConfiguration
# "Only one of the aliasAttributes or usernameAttributes can be set in a User pool."
# if aliasAttributes used, seems to add these additionally to username as sign-in options.
# In contrast using usernameAttributes seems to replace username as sign-in option!
aliasAttributes:
- email
- phone_number
- preferred_username
usernameConfiguration: # default is true
caseSensitive: false
adminCreateUserConfig:
allowAdminCreateUserOnly: true
inviteMessageTemplate:
emailMessage: |
Your username is:
<br>{username}<br>
<br>and your temporary password is:
<br>{####}<br>
# ensure that for email subject line a single-line string is provided
emailSubject: "Your temporary password"
mfaConfiguration: 'ON'
# to make MFA usable, either softwareTokenMFAConfiguration
# and/or smsConfiguration (with externalID) needs to be provided
softwareTokenMFAConfiguration:
enabled: true
userPoolTags:
pool: big
users: best
providerConfigRef:
name: example
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ spec:
sMSMessage:
type: string
type: object
unusedAccountValidityDays:
format: int64
type: integer
type: object
aliasAttributes:
description: 'Attributes supported as an alias for this user pool.
Expand Down Expand Up @@ -287,6 +284,12 @@ spec:
smsVerificationMessage:
description: A string representing the SMS verification message.
type: string
softwareTokenMFAConfiguration:
description: The software token MFA configuration.
properties:
enabled:
type: boolean
type: object
userPoolAddOns:
description: Enables advanced security risk detection. Set the
key AdvancedSecurityMode to the value "AUDIT".
Expand Down
70 changes: 70 additions & 0 deletions pkg/clients/cognitoidentityprovider/fake/fake.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
Copyright 2021 The Crossplane Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package fake

import (
"context"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider/cognitoidentityprovideriface"
)

// MockCognitoIdentityProviderClient for testing
type MockCognitoIdentityProviderClient struct {
cognitoidentityprovideriface.CognitoIdentityProviderAPI

MockGetUserPoolMfaConfig func(*cognitoidentityprovider.GetUserPoolMfaConfigInput) (*cognitoidentityprovider.GetUserPoolMfaConfigOutput, error)
MockSetUserPoolMfaConfigWithContext func(context.Context, *cognitoidentityprovider.SetUserPoolMfaConfigInput, []request.Option) (*cognitoidentityprovider.SetUserPoolMfaConfigOutput, error)

Called MockCognitoIdentityProviderClientCall
}

// CallGetUserPoolMfaConfig to log call
type CallGetUserPoolMfaConfig struct {
Ctx aws.Context
I *cognitoidentityprovider.GetUserPoolMfaConfigInput
Opts []request.Option
}

// GetUserPoolMfaConfig calls MockGetUserPoolMfaConfig
func (m *MockCognitoIdentityProviderClient) GetUserPoolMfaConfig(i *cognitoidentityprovider.GetUserPoolMfaConfigInput) (*cognitoidentityprovider.GetUserPoolMfaConfigOutput, error) {
m.Called.GetUserPoolMfaConfig = append(m.Called.GetUserPoolMfaConfig, &CallGetUserPoolMfaConfig{I: i})

return m.MockGetUserPoolMfaConfig(i)
}

// CallSetUserPoolMfaConfigWithContext to log call
type CallSetUserPoolMfaConfigWithContext struct {
Ctx aws.Context
I *cognitoidentityprovider.SetUserPoolMfaConfigInput
Opts []request.Option
}

// SetUserPoolMfaConfigWithContext calls MockSetUserPoolMfaConfigWithContext
func (m *MockCognitoIdentityProviderClient) SetUserPoolMfaConfigWithContext(ctx context.Context, i *cognitoidentityprovider.SetUserPoolMfaConfigInput, opts ...request.Option) (*cognitoidentityprovider.SetUserPoolMfaConfigOutput, error) {
m.Called.SetUserPoolMfaConfigWithContext = append(m.Called.SetUserPoolMfaConfigWithContext, &CallSetUserPoolMfaConfigWithContext{Ctx: ctx, I: i, Opts: opts})

return m.MockSetUserPoolMfaConfigWithContext(ctx, i, opts)
}

// MockCognitoIdentityProviderClientCall to log calls
type MockCognitoIdentityProviderClientCall struct {
GetUserPoolMfaConfig []*CallGetUserPoolMfaConfig
SetUserPoolMfaConfigWithContext []*CallSetUserPoolMfaConfigWithContext
}
Loading