fix(cognito): stop defaulting unset password requirements to enabled (#4250)

* fix(cognito): stop defaulting unset password requirements to enabled

CreateUserPool filled in RequireUppercase, RequireLowercase, RequireNumbers
and RequireSymbols as true whenever a PasswordPolicy left them out. The four
members are unboxed booleans in the Cognito model, so a client that wants one
off cannot say so on the wire: aws-sdk-go-v2 emits each under
`if v.RequireLowercase != false`. A request built for require_* = false
carries only MinimumLength, and Floci answered it with all four enabled.

That made every Terraform plan after a create report drift on all four flags,
converging only because UpdateUserPool does not normalize, and it over-enforced
the policy on SignUp and AdminSetUserPassword: a pool created with
PasswordPolicy { MinimumLength: 6 } rejected passwords real Cognito accepts.

The API reference documents no default for any of the four. It documents one
for TemporaryPasswordValidityDays ("Defaults to 7"), which is kept, along with
MinimumLength 8. The all-enabled policy is the console's "Cognito defaults"
mode, not an API default; terraform-provider-aws asserts require_numbers and
require_uppercase read back as false immediately after a create that set them
to false, against the live service.

Absence now means "not required", which validatePasswordAgainstPolicy already
resolved that way through policyBoolean, so enforcement follows with no change.

Pools created with no PasswordPolicy at all are untouched, as before.

* test(cognito): pin the unset password requirement contract at the wire

Adds the JSON 1.1 half of the CreateUserPool password policy fix: a request
carrying only MinimumLength must come back without the four Require* members,
and a request that sets them to false explicitly must come back with false.

Verified non-vacuously - with the RequireUppercase default restored, the first
test fails on "RequireUppercase must not be defaulted on".
This commit is contained in:
Abhigya authored and GitHub committed 2026-09-23 14:03:27 -04:00
1 parent f8f1b56ce9
commit 4e42f47740
4 files changed
+181 -19

No files matched your search

@@ -331,11 +331,22 @@ public class CognitoService implements ResourceProvider {
/**
* Fills in AWS's per-field password policy defaults for a pool created with a
* {@code PasswordPolicy} that has some fields unset: MinimumLength 8 (AWS's documented
* complex-password recommendation; the field itself only documents a minimum of 6), the four
* character-class requirements enabled, and TemporaryPasswordValidityDays 7 (the one default
* the API reference states explicitly). "If you don't provide a value for an attribute,
* Amazon Cognito sets it to its default value" (CreateUserPool).
* {@code PasswordPolicy} that has some fields unset: TemporaryPasswordValidityDays 7 (the one
* default the API reference states explicitly) and MinimumLength 8 (AWS's documented
* complex-password recommendation; the field itself only documents a minimum of 6).
* "If you don't provide a value for an attribute, Amazon Cognito sets it to its default
* value" (CreateUserPool).
*
* <p>RequireUppercase, RequireLowercase, RequireNumbers and RequireSymbols are deliberately
* left alone. The API reference documents no default for any of them, and they are unboxed
* booleans in the Cognito model, so a client that wants one off cannot say so on the wire:
* aws-sdk-go-v2 emits each under {@code if v.RequireLowercase != false}. Absence therefore
* means "not required", which is what the live service reports back - the Terraform provider
* asserts require_numbers and require_uppercase read as false immediately after a create
* that set them to false. Defaulting them to enabled made every Terraform plan after a
* create show spurious drift, and over-enforced the policy on SignUp and
* AdminSetUserPassword. The all-enabled policy is the console's "Cognito defaults" mode,
* not an API default.
*
* <p>Deliberately does not fabricate a {@code PasswordPolicy} for a pool that supplies none
* at all — every other test and fixture in this codebase creates pools that way, relying on
@@ -355,10 +366,6 @@ public class CognitoService implements ResourceProvider {
Map<String, Object> normalized = new HashMap<>(policies);
Map<String, Object> passwordPolicy = new HashMap<>((Map<String, Object>) raw);
passwordPolicy.putIfAbsent("MinimumLength", 8);
passwordPolicy.putIfAbsent("RequireUppercase", true);
passwordPolicy.putIfAbsent("RequireLowercase", true);
passwordPolicy.putIfAbsent("RequireNumbers", true);
passwordPolicy.putIfAbsent("RequireSymbols", true);
passwordPolicy.putIfAbsent("TemporaryPasswordValidityDays", 7);
normalized.put("PasswordPolicy", passwordPolicy);
pool.setPolicies(normalized);