Skip to content

Commit f216f96

Browse files
McDoitElad Ben-Israel
authored andcommitted
fix(acm): enabled validation of certificates on the zone name (#2133)
As it is now, only certificates with subdomains are correctly validated Got help from @njlaw to find and correct the issue
1 parent d22a154 commit f216f96

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/@aws-cdk/aws-certificatemanager/lib/dns-validated-certificate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export class DnsValidatedCertificate extends cdk.Construct implements ICertifica
8383
protected validate(): string[] {
8484
const errors: string[] = [];
8585
// Ensure the zone name is a parent zone of the certificate domain name
86-
if (!this.domainName.endsWith('.' + this.normalizedZoneName)) {
86+
if (this.domainName !== this.normalizedZoneName && !this.domainName.endsWith('.' + this.normalizedZoneName)) {
8787
errors.push(`DNS zone ${this.normalizedZoneName} is not authoritative for certificate domain name ${this.domainName}`);
8888
}
8989
return errors;

packages/@aws-cdk/aws-certificatemanager/test/test.dns-validated-certificate.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,31 @@ export = {
112112
test.throws(() => expect(stack), /DNS zone hello.com is not authoritative for certificate domain name example.com/);
113113
test.done();
114114
},
115+
116+
'test root certificate'(test: Test) {
117+
const stack = new Stack();
118+
119+
const exampleDotComZone = new PublicHostedZone(stack, 'ExampleDotCom', {
120+
zoneName: 'example.com'
121+
});
122+
123+
new DnsValidatedCertificate(stack, 'Cert', {
124+
domainName: 'example.com',
125+
hostedZone: exampleDotComZone,
126+
});
127+
128+
expect(stack).to(haveResource('AWS::CloudFormation::CustomResource', {
129+
ServiceToken: {
130+
'Fn::GetAtt': [
131+
'CertCertificateRequestorFunction98FDF273',
132+
'Arn'
133+
]
134+
},
135+
DomainName: 'example.com',
136+
HostedZoneId: {
137+
Ref: 'ExampleDotCom4D1B83AA'
138+
}
139+
}));
140+
test.done();
141+
},
115142
};

0 commit comments

Comments
 (0)