Skip to content

Commit d0d42ca

Browse files
authored
fix(lambda): handle gracefully for same alias default domain (#2607)
<!-- Provide summary of changes --> fixes #2602. Currently Copilot fails if users set the `alias` to be the same as the default domain name we assign them. Though this is not a very common behavior, we should handle this edge case gracefully. <!-- Issue number, if available. E.g. "Fixes #31", "Addresses #42, 77" --> By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent e239ce3 commit d0d42ca

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

cf-custom-resources/lib/dns-cert-validator.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,12 @@ const requestCertificate = async function (
108108
) {
109109
const crypto = require("crypto");
110110
const [acm, envRoute53, appRoute53] = clients(region, rootDnsRole);
111-
// For backward compatiblity.
112-
const sansToUse = [`*.${certDomain}`];
111+
// For backward compatiblity, and make sure the SANs we use are unique.
112+
const uniqueSansToUse = new Set([certDomain, `*.${certDomain}`]);
113113
for (const alias of aliases) {
114-
sansToUse.push(alias);
114+
uniqueSansToUse.add(alias);
115115
}
116+
const sansToUse = [...uniqueSansToUse];
116117
const reqCertResponse = await acm
117118
.requestCertificate({
118119
DomainName: certDomain,
@@ -138,8 +139,7 @@ const requestCertificate = async function (
138139

139140
let options;
140141
let attempt;
141-
// We need to count the domain name itself.
142-
const expectedValidationOptionsNum = sansToUse.length + 1;
142+
const expectedValidationOptionsNum = sansToUse.length;
143143
for (attempt = 0; attempt < maxAttempts; attempt++) {
144144
const { Certificate } = await acm
145145
.describeCertificate({

cf-custom-resources/test/dns-cert-validator-test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ describe("DNS Validated Certificate Handler", () => {
2222
const testRootDNSRole = "mockRole";
2323
const testAliases = `{
2424
"frontend": ["v1.${testAppName}.${testDomainName}", "foobar.com"],
25-
"backend": ["v2.${testDomainName}"]
25+
"backend": ["v2.${testDomainName}", "${testEnvName}.${testAppName}.${testDomainName}"]
2626
}`;
2727
const testUpdatedAliases = `{
2828
"frontend": ["v1.${testAppName}.${testDomainName}"],
29-
"backend": ["v2.${testDomainName}"]
29+
"backend": ["v2.${testDomainName}", "${testEnvName}.${testAppName}.${testDomainName}"]
3030
}`;
3131
const testSANs = [
32+
"test.myapp.example.com",
3233
"*.test.myapp.example.com",
3334
"v1.myapp.example.com",
3435
"v2.example.com",
@@ -518,6 +519,7 @@ describe("DNS Validated Certificate Handler", () => {
518519
sinon.match({
519520
DomainName: `${testEnvName}.${testAppName}.${testDomainName}`,
520521
SubjectAlternativeNames: [
522+
`${testEnvName}.${testAppName}.${testDomainName}`,
521523
`*.${testEnvName}.${testAppName}.${testDomainName}`,
522524
],
523525
ValidationMethod: "DNS",

templates/environment/cf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# SPDX-License-Identifier: MIT-0
33
Description: CloudFormation environment template for infrastructure shared among Copilot workloads.
44
Metadata:
5-
Version: 'v1.5.0'
5+
Version: 'v1.5.1'
66
Parameters:
77
AppName:
88
Type: String

0 commit comments

Comments
 (0)