mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cloudformation): keep SMS_MFA on a user pool update until MFA is turned off (#7088)
* fix(cloudformation): keep SMS_MFA on a user pool update until MFA is turned off The AWS::Cognito::UserPool reference says that once SMS_MFA is enabled, only MfaConfiguration OFF turns it off. An update that stopped listing SMS_MFA in EnabledMfas cleared it. replaceUserPoolMfaConfig now keeps the pool's SMS setting when none is given and the mode is not OFF. Closes #7086 * fix(cognito): keep SMS MFA with the pool's current SMS settings Keeping SMS MFA replayed the settings it was enabled with, so an update that dropped SMS_MFA and changed SmsAuthenticationMessage or SmsConfiguration put the old values back over the ones updateUserPool had just applied. The kept SMS MFA now takes the pool's current message and SMS configuration.
This commit is contained in:
1 parent
3acebc90fe
commit
f0a1b11385
5 files changed
+61
-2
No files matched your search
@@ -203,7 +203,7 @@ cross-resource references.
|
||||
| CodePipeline | `Pipeline`, `CustomActionType`, `Webhook` |
|
||||
| CodeBuild | `Project` |
|
||||
| Batch | `ComputeEnvironment`, `JobQueue`, `JobDefinition` |
|
||||
| Cognito | `UserPool` (`ProviderURL` is the local issuer of the tokens Floci mints, `<base-url>/<pool id>`; `EnabledMfas` is applied with `SetUserPoolMfaConfig`, as on AWS), `UserPoolClient`, `UserPoolDomain`, `UserPoolGroup`, `UserPoolResourceServer`, `UserPoolUser`, `UserPoolUserToGroupAttachment` |
|
||||
| Cognito | `UserPool` (`ProviderURL` is the local issuer of the tokens Floci mints, `<base-url>/<pool id>`; `EnabledMfas` is applied with `SetUserPoolMfaConfig`, as on AWS, and once `SMS_MFA` is on only `MfaConfiguration: OFF` turns it off), `UserPoolClient`, `UserPoolDomain`, `UserPoolGroup`, `UserPoolResourceServer`, `UserPoolUser`, `UserPoolUserToGroupAttachment` |
|
||||
| ACM | `Certificate` |
|
||||
| EventBridge | `Rule`, `EventBus`, `EventBusPolicy`, `ApiDestination`, `Archive` (`KmsKeyIdentifier` is ignored) |
|
||||
| EventBridge Scheduler | `Schedule`, `ScheduleGroup` |
|
||||
|
||||
@@ -850,6 +850,10 @@ public class CognitoService implements ResourceProvider {
|
||||
* how CloudFormation applies a user pool's EnabledMfas. The settings are built on a copy and
|
||||
* stored in one write, so a concurrent sign-in never reads the pool between its old and new
|
||||
* MFA settings, and under the pool lock, so a concurrent tag or update is kept.
|
||||
* SMS is the exception: once enabled, only MfaConfiguration OFF turns it off, as the
|
||||
* AWS::Cognito::UserPool reference documents, so an SMS setting that is not given is kept,
|
||||
* with the pool's current message and SMS configuration rather than the ones it was enabled
|
||||
* with, since an update may have just changed them.
|
||||
*/
|
||||
public UserPool replaceUserPoolMfaConfig(String id, String mfaConfiguration,
|
||||
Boolean softwareTokenMfaEnabled,
|
||||
@@ -857,6 +861,16 @@ public class CognitoService implements ResourceProvider {
|
||||
Map<String, Object> emailMfaConfiguration) {
|
||||
synchronized (poolLock(id)) {
|
||||
UserPool pool = MAPPER.convertValue(describeUserPool(id), UserPool.class);
|
||||
if (smsMfaConfiguration == null && mfaConfiguration != null && !"OFF".equals(mfaConfiguration)
|
||||
&& pool.getSmsMfaConfiguration() != null) {
|
||||
smsMfaConfiguration = new LinkedHashMap<>(pool.getSmsMfaConfiguration());
|
||||
if (pool.getSmsAuthenticationMessage() != null) {
|
||||
smsMfaConfiguration.put("SmsAuthenticationMessage", pool.getSmsAuthenticationMessage());
|
||||
}
|
||||
if (pool.getSmsConfiguration() != null) {
|
||||
smsMfaConfiguration.put("SmsConfiguration", pool.getSmsConfiguration());
|
||||
}
|
||||
}
|
||||
applyMfaConfig(pool, mfaConfiguration, softwareTokenMfaEnabled, smsMfaConfiguration,
|
||||
emailMfaConfiguration, null, true);
|
||||
poolStore.put(id, pool);
|
||||
|
||||
+34
@@ -528,6 +528,40 @@ class CognitoCfnIntegrationTest {
|
||||
CfnStackWaits.awaitStackDeleted(stack);
|
||||
}
|
||||
|
||||
/** Once SMS_MFA is enabled, only MfaConfiguration OFF turns it off, per the template reference. */
|
||||
@Test
|
||||
void anUpdateKeepsSmsMfaUntilMfaIsTurnedOff() throws Exception {
|
||||
String stack = "cognito-cfn-enabled-mfas-keep-sms-it";
|
||||
String smsConfiguration = "\"SmsConfiguration\": {\"SnsCallerArn\": \"arn:aws:iam::000000000000:role/sms\"}";
|
||||
cloudFormation(stack, "CreateStack", enabledMfasTemplate(
|
||||
"\"MfaConfiguration\": \"OPTIONAL\", \"EnabledMfas\": [\"SMS_MFA\", \"SOFTWARE_TOKEN_MFA\"], "
|
||||
+ smsConfiguration));
|
||||
String poolId = outputValue(describeStacks(stack, "CREATE_COMPLETE"), "PoolId");
|
||||
|
||||
cloudFormation(stack, "UpdateStack", enabledMfasTemplate(
|
||||
"\"MfaConfiguration\": \"OPTIONAL\", \"EnabledMfas\": [\"SOFTWARE_TOKEN_MFA\"], "
|
||||
+ "\"SmsAuthenticationMessage\": \"New code {####}\", "
|
||||
+ "\"SmsConfiguration\": {\"SnsCallerArn\": \"arn:aws:iam::000000000000:role/sms-v2\"}"));
|
||||
describeStacks(stack, "UPDATE_COMPLETE");
|
||||
cognitoAction("GetUserPoolMfaConfig", "{\"UserPoolId\": \"" + poolId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("MfaConfiguration", equalTo("OPTIONAL"))
|
||||
.body("SoftwareTokenMfaConfiguration.Enabled", equalTo(true))
|
||||
.body("SmsMfaConfiguration.SmsAuthenticationMessage", equalTo("New code {####}"))
|
||||
.body("SmsMfaConfiguration.SmsConfiguration.SnsCallerArn", equalTo("arn:aws:iam::000000000000:role/sms-v2"));
|
||||
cognitoAction("DescribeUserPool", "{\"UserPoolId\": \"" + poolId + "\"}")
|
||||
.then().statusCode(200)
|
||||
.body("UserPool.SmsAuthenticationMessage", equalTo("New code {####}"))
|
||||
.body("UserPool.SmsConfiguration.SnsCallerArn", equalTo("arn:aws:iam::000000000000:role/sms-v2"));
|
||||
|
||||
cloudFormation(stack, "UpdateStack", enabledMfasTemplate("\"MfaConfiguration\": \"OFF\""));
|
||||
describeStacks(stack, "UPDATE_COMPLETE");
|
||||
assertMfa(poolId, "OFF", false, false);
|
||||
|
||||
cloudFormation(stack, "DeleteStack", null);
|
||||
CfnStackWaits.awaitStackDeleted(stack);
|
||||
}
|
||||
|
||||
/** OFF with a listed factor is refused by SetUserPoolMfaConfig after the pool exists. */
|
||||
@Test
|
||||
void aRefusedEnabledMfasOnCreateRemovesThePool() throws Exception {
|
||||
|
||||
+11
@@ -53,6 +53,17 @@ class CognitoReplaceMfaConfigTest {
|
||||
assertNotNull(pool.getSmsMfaConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
void smsThatIsNotGivenStaysOnUntilMfaIsTurnedOff() {
|
||||
service.replaceUserPoolMfaConfig(poolId, "OPTIONAL", true, Map.of("SmsAuthenticationMessage", "{####}"), null);
|
||||
|
||||
service.replaceUserPoolMfaConfig(poolId, "OPTIONAL", true, null, null);
|
||||
assertEquals("{####}", service.describeUserPool(poolId).getSmsMfaConfiguration().get("SmsAuthenticationMessage"));
|
||||
|
||||
service.replaceUserPoolMfaConfig(poolId, "OFF", null, null, null);
|
||||
assertNull(service.describeUserPool(poolId).getSmsMfaConfiguration());
|
||||
}
|
||||
|
||||
@Test
|
||||
void thePoolAReaderAlreadyHoldsKeepsItsSettings() {
|
||||
UserPool before = service.describeUserPool(poolId);
|
||||
|
||||
@@ -211,7 +211,7 @@ notes:
|
||||
AWS::Route53::RecordSetGroup: 'written in one change batch, so a record set that cannot be written leaves the zone unchanged; every record set must be in the group''s hosted zone'
|
||||
Custom::DynamoDBReplica: applied natively against DynamoDB, not via a provider Lambda
|
||||
AWS::DynamoDB::Table: '`TimeToLiveSpecification` applied on create and update; to rename an enabled TTL attribute, disable TTL in one update and enable the new attribute in a later one'
|
||||
AWS::Cognito::UserPool: '`ProviderURL` is the local issuer of the tokens Floci mints, `<base-url>/<pool id>`; `EnabledMfas` is applied with `SetUserPoolMfaConfig`, as on AWS'
|
||||
AWS::Cognito::UserPool: '`ProviderURL` is the local issuer of the tokens Floci mints, `<base-url>/<pool id>`; `EnabledMfas` is applied with `SetUserPoolMfaConfig`, as on AWS, and once `SMS_MFA` is on only `MfaConfiguration: OFF` turns it off'
|
||||
AWS::SES::EmailIdentity: 'BYODKIM is not supported by this resource; Easy DKIM DNS attributes use the shared emulator signing zone `dkim.amazonses.com` rather than AWS''s region- and identity-specific zone assignment'
|
||||
AWS::SES::ReceiptRule: 'stored in an existing SES receipt rule set; Ref and RuleName return the rule name; management plane only, with no inbound mail delivery'
|
||||
AWS::Events::Archive: '`KmsKeyIdentifier` is ignored'
|
||||
|
||||
Reference in new issue
Block a user