-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
(aws-certificatemanager): DNS Validation fails when alternates are in different hosted zones #15217
Comments
Thanks for the bug report, and the initial investigation! I am unassigning and marking this issue as We use +1s to help prioritize our work, and are happy to revaluate this issue based on community feedback. You can reach out to the cdk.dev community on Slack to solicit support for reprioritization. |
We also came up with the same problem, so here is my +1 I think this could be a low effort task, as it would be enough to replace this and this with a map of SANs and corresponding hosted zone ids and loop over it here. In the meantime, are there any known workarounds? We really need to update the stack containing our certificate, as we upgraded the cdk version. |
@flavioleggio I tried to figure out a CDK workaround and was unable to do so; workaround coding started to get way too big. It felt like the cons out weighed the pros. In my case, I know when I'm using multiple host zones vs alternates that exist under one zone. In the multiple host zone case I create the cert via the console and drop its I happen to have other code that fetches DNS records and assembles (groups) the alternate names into hosted zones so that I can create DNS records at the apex, if those records do not exist. The code is a bit involved. At first, I toyed with the idea of fixing this bug myself, but decided I just didn't understand the CDK well enough to propose a proper fix. I'm happy to share that DNS analysis code with you or anyone else either for a possible patch or for your own workaround. Here are the data and function signatures. If anyone is interested in the actual code, post here or PM me. export interface HostedZoneSchedule {
exists: { [key: string]: any }, // hosted zone exists in Route53
create: { [key: string]: any }, // create these (apex) hosted zones
domains: { [key: string]: { // Requires an A or CNAME record
hostedZone: string, // Hosted Zone for the record
} },
};
// Given an unordered domain list, construct an organized mapping of domains
// to existing (in Route 53) hosted zones and new hosted zones to be created.
// New hosted zones will always be apex domains (apex.tld.) whereas existing
// hosted domains could be apex or subdomains.
export async function synthesizeHostedZoneSchedule(domains: string[]): Promise<HostedZoneSchedule> {
...
} Note, because new DNS entries have to be created, if you want true CDK rollback behavior, the challenge here is to remember that you created the DNS records so they can be rolled back for CDK errors and deletes. I'm sure CDK developers are used to doing this all of the time. In my stack code, if I see a pre-existing DNS entry, it takes a different code path ( |
We are manually creating certificates and using their ARNs. It sucks but I've not seen any better way really. |
@codeedog
Note that in my example The only problem with this solution is that it does not work if you also need to create the certificate in a region which is different from the one in which the stack is deployed; in fact, the Certificate construct does not allow to specify a region, while the DNSValidatedCertificate does. Note that there are use cases where you need to specify a region, for example for services like CloudFront and Amazon ApiGateway, where the certificate must be located in |
+1 |
In case my original filing was murky, the entire point of the bug is that certificate creation for multiple apex hosted zones (e.g. |
+1 |
yes, AFAIK |
You can create the Certificate in |
Now that the official CloudFormation resource `AWS::CertificateManager::Certificate` (CDK's `Certificate` construct) supports DNS validation we do not want to recommend using the `DnsValidatedCertificate` construct. The `DnsValidatedCertificate` construct uses CloudFormation custom resources to perform the certificate creation and this creates a lot of maintenance burden on our team (see the list of linked issues). Currently the primary use case for using `DnsValidatedCertificate` over `Certificate` is for cross region use cases. For this use case I have updated the README to have our suggested solution. The example in the README is tested in this [integration test](https://github.com/aws/aws-cdk/blob/main/packages/@aws-cdk/aws-cloudfront/test/integ.cloudfront-cross-region-cert.ts) fixes #8934, #2914, #20698, #17349, #15217, #14519 ---- ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
Although SSL Certificates may contain alternate subject domains with different hosted zones and it is possible to create such certificates via Web Console, aws command line and, in fact, CDK (using the
Certificate
class), it is not possible to do this withDnsValidatedCertificate
. The certificate is, in fact, actually created. However, the CDK management code triggers an error causing a rollback of the Stack creation or update process despite the successful creation of the certificate.Reproduction Steps
I coded a stack that triggers the bug. It contains two options:
github repo
What did you expect to happen?
I expected that a Certificate containing the two different domains each existing in two separate hosted zones would have resulted in a Certificate created in the region 'us-east-1'. Note, the current region for this was not 'us-east-1'. Then, I would have expected the Stack creation process to have continued successfully to completion.
What actually happened?
A Certificate was created in the 'us-east-1' region. Then, upon an attempt to create A Records, the record for
www.example.net
was attempted to be created within the hosted zone forexample.com
. This caused a failure (example.com
cannot hold a record forexample.net
) which triggered a rollback of the stack creation. So, the Certificate was created successfully, but the A record entries were not.Environment
Other
Note: it is possible to create a Certificate with different hosted zones using the AWS tools and UI. The Web console, the command line tool and CDK's acm.Certificate() method all allow it. Note, in the case of the latter, it looks like the code (if I have the correct file: lambda handler) uses the
sdk
callacm.requestCertificate
(line 92), which according to the documentation allows SubjectAlternativeNames in different hosted zones (www.example.net
). Given this and the fact that I can see the certificate continues to exist in the 'us-east-1' region even after rollback, I'm fairly certain that the call torequestCertificate
succeeds. Therefore, the problem is almost certainly further down in the code.Looking lower, Line 146 initiates a change batch call into Route 53 to create the A Records passing the hosted zone ID at Line 163. It uses an array of records collected at Line 130. I believe it is this batch change call that's failing as that's indicated by the error I'm seeing. I don't have a copy of the command line error as the stack creation process erases it, but it mentions something about not allowed to create
example.net
inexample.com
hosted zone. This would fit with a fixed hosted zone (Line 163) and varied hosted zones required for the A records.I think this batch change needs to be broken up into separate hosted zones depending upon the zone matching the domain(s).
This is 🐛 Bug Report
The text was updated successfully, but these errors were encountered: