mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(cognito): refuse user pool custom domains in GovCloud and EUSC (#5614)
* fix(cognito): refuse user pool custom domains in GovCloud The AWS GovCloud (US) User Guide lists "Custom domains for user pools are not available" among the Cognito differences (https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-cog.html), but CreateUserPoolDomain and UpdateUserPoolDomain treated a CustomDomainConfig the same in every partition. In a GovCloud region the request only failed later, on the us-east-1 certificate check, with a message about the certificate rather than about the feature. Both operations now refuse a CustomDomainConfig when the request region is in aws-us-gov, before the certificate is looked at, with an InvalidParameterException, which the cognito-idp model declares for both. No source shows AWS's message, so the wording is Floci's own, as for the API Gateway EDGE gate. Prefix domains keep working in GovCloud. EUSC is left as it is because no source covers it, and China and the ISO partitions have no user pools. Signed-off-by: Hector Ventura <hectorvent@gmail.com> * fix(cognito): refuse user pool custom domains in EUSC too The European Sovereign Cloud guide lists user pool custom domains as not available, in the same words as the GovCloud guide, so a CustomDomainConfig in eusc-de-east-1 is now refused with InvalidParameterException instead of falling through to the us-east-1 certificate check. The issued-certificate ACM stub the user pool domain unit tests each carried a copy of moves to one helper, CognitoCertificateStubs. Signed-off-by: Hector Ventura <hectorvent@gmail.com> --------- Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
372d3d11d5
commit
9df4ffbfa1
8 files changed
+234
-18
No files matched your search
@@ -9,6 +9,8 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.config.TlsCertificateManager;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartition;
|
||||
import io.github.hectorvent.floci.core.common.AwsPartitions;
|
||||
import io.github.hectorvent.floci.core.common.AwsRegions;
|
||||
import io.github.hectorvent.floci.core.common.Base64Url;
|
||||
import io.github.hectorvent.floci.core.common.Digests;
|
||||
@@ -1683,6 +1685,8 @@ public class CognitoService implements ResourceProvider {
|
||||
private static final String CERTIFICATE_REGION = "us-east-1"; // partition-literal: CloudFront certificates live in us-east-1 by AWS's rule
|
||||
private static final String CERTIFICATE_NOT_USABLE = "The specified SSL certificate doesn't exist, "
|
||||
+ "isn't in us-east-1 region, isn't valid, or doesn't include a valid certificate chain."; // partition-literal: AWS's message text
|
||||
/** The partitions where AWS documents user pool custom domains as not available. */
|
||||
private static final Set<String> CUSTOM_DOMAIN_UNAVAILABLE_PARTITIONS = Set.of("aws-us-gov", "aws-eusc");
|
||||
|
||||
/**
|
||||
* Creates either an Amazon Cognito prefix domain ({@code customDomainConfig == null})
|
||||
@@ -1710,6 +1714,7 @@ public class CognitoService implements ResourceProvider {
|
||||
userPoolDomain.setS3Bucket("aws-cognito-prod-" + regionResolver.getRegion() + "-assets");
|
||||
|
||||
if (customDomainConfig != null) {
|
||||
requireCustomDomainsAvailable(regionResolver.getRegion());
|
||||
String certificateArn = (String) customDomainConfig.get("CertificateArn");
|
||||
if (certificateArn == null || certificateArn.isBlank()) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
@@ -1835,6 +1840,7 @@ public class CognitoService implements ResourceProvider {
|
||||
String previousCertificateArn = userPoolDomain.getCertificateArn();
|
||||
String certificateArn = previousCertificateArn;
|
||||
if (customDomainConfig != null) {
|
||||
requireCustomDomainsAvailable(regionResolver.getRegion());
|
||||
if (!userPoolDomain.isCustomDomain()) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"CustomDomainConfig cannot be set on an Amazon Cognito prefix domain", 400);
|
||||
@@ -1900,6 +1906,21 @@ public class CognitoService implements ResourceProvider {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* User pool custom domains are not available in AWS GovCloud (US) or in the AWS European
|
||||
* Sovereign Cloud: both guides say "Custom domains for user pools are not available"
|
||||
* (https://docs.aws.amazon.com/govcloud-us/latest/UserGuide/govcloud-cog.html,
|
||||
* https://docs.aws.eu/esc/latest/userguide/cognito.html). Prefix domains are. No source shows
|
||||
* AWS's message for the refusal, so the wording is Floci's own.
|
||||
*/
|
||||
private static void requireCustomDomainsAvailable(String region) {
|
||||
AwsPartition partition = AwsPartitions.forRegionOrCommercial(region);
|
||||
if (CUSTOM_DOMAIN_UNAVAILABLE_PARTITIONS.contains(partition.id())) {
|
||||
throw new AwsException("InvalidParameterException",
|
||||
"Custom domains for user pools are not available in partition " + partition.id() + ".", 400);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* AWS accepts only an issued ACM certificate from us-east-1 behind a custom domain, and answers
|
||||
* anything else with this one message.
|
||||
|
||||
Reference in new issue
Block a user