Skip to content

Commit a733bd1

Browse files
khobergVoid-Conceptnija-atmergify[bot]
authored andcommitted
feat(apigateway): DomainName supports SecurityPolicy (#6374)
* Pass securityPolicy from API Gateway DomainName to cfnDomainName * Update ApiGateway README with example securityPolicy * DomainName: Add documentation for SecurityPolicy TSL versions, add test for absent securityPolicy * fix tsdoc @default Co-authored-by: Void-Concept <49216983+Void-Concept@users.noreply.github.com> Co-authored-by: Niranjan Jayakar <16217941+nija-at@users.noreply.github.com> Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 5276067 commit a733bd1

File tree

3 files changed

+69
-3
lines changed

3 files changed

+69
-3
lines changed

packages/@aws-cdk/aws-apigateway/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,8 @@ You can also define a `DomainName` resource directly in order to customize the d
540540
new apigw.DomainName(this, 'custom-domain', {
541541
domainName: 'example.com',
542542
certificate: acmCertificateForExampleCom,
543-
endpointType: apigw.EndpointType.EDGE // default is REGIONAL
543+
endpointType: apigw.EndpointType.EDGE, // default is REGIONAL
544+
securityPolicy: apigw.SecurityPolicy.TLS_1_2
544545
});
545546
```
546547

packages/@aws-cdk/aws-apigateway/lib/domain-name.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,17 @@ import * as acm from '@aws-cdk/aws-certificatemanager';
22
import { Construct, IResource, Resource } from '@aws-cdk/core';
33
import { CfnDomainName } from './apigateway.generated';
44
import { BasePathMapping, BasePathMappingOptions } from './base-path-mapping';
5-
import { EndpointType, IRestApi} from './restapi';
5+
import { EndpointType, IRestApi } from './restapi';
6+
7+
/**
8+
* The minimum version of the SSL protocol that you want API Gateway to use for HTTPS connections.
9+
*/
10+
export enum SecurityPolicy {
11+
/** Cipher suite TLS 1.0 */
12+
TLS_1_0 = 'TLS_1_0',
13+
/** Cipher suite TLS 1.2 */
14+
TLS_1_2 = 'TLS_1_2'
15+
}
616

717
export interface DomainNameOptions {
818
/**
@@ -22,6 +32,13 @@ export interface DomainNameOptions {
2232
* @default REGIONAL
2333
*/
2434
readonly endpointType?: EndpointType;
35+
36+
/**
37+
* The Transport Layer Security (TLS) version + cipher suite for this domain name.
38+
* @see https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-domainname.html
39+
* @default SecurityPolicy.TLS_1_0
40+
*/
41+
readonly securityPolicy?: SecurityPolicy
2542
}
2643

2744
export interface DomainNameProps extends DomainNameOptions {
@@ -90,6 +107,7 @@ export class DomainName extends Resource implements IDomainName {
90107
certificateArn: edge ? props.certificate.certificateArn : undefined,
91108
regionalCertificateArn: edge ? undefined : props.certificate.certificateArn,
92109
endpointConfiguration: { types: [endpointType] },
110+
securityPolicy: props.securityPolicy
93111
});
94112

95113
this.domainName = resource.ref;

packages/@aws-cdk/aws-apigateway/test/test.domains.ts

+48-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// tslint:disable:object-literal-key-quotes
2-
import { expect, haveResource } from '@aws-cdk/assert';
2+
import { ABSENT, expect, haveResource } from '@aws-cdk/assert';
33
import * as acm from '@aws-cdk/aws-certificatemanager';
44
import { Stack } from '@aws-cdk/core';
55
import { Test } from 'nodeunit';
@@ -65,6 +65,53 @@ export = {
6565
test.done();
6666
},
6767

68+
'accepts different security policies'(test: Test) {
69+
// GIVEN
70+
const stack = new Stack();
71+
const cert = new acm.Certificate(stack, 'Cert', { domainName: 'example.com' });
72+
73+
// WHEN
74+
new apigw.DomainName(stack, 'my-domain', {
75+
domainName: 'old.example.com',
76+
certificate: cert,
77+
securityPolicy: apigw.SecurityPolicy.TLS_1_0
78+
});
79+
80+
new apigw.DomainName(stack, 'your-domain', {
81+
domainName: 'new.example.com',
82+
certificate: cert,
83+
securityPolicy: apigw.SecurityPolicy.TLS_1_2
84+
});
85+
86+
new apigw.DomainName(stack, 'default-domain', {
87+
domainName: 'default.example.com',
88+
certificate: cert
89+
});
90+
91+
// THEN
92+
expect(stack).to(haveResource('AWS::ApiGateway::DomainName', {
93+
"DomainName": "old.example.com",
94+
"EndpointConfiguration": { "Types": [ "REGIONAL" ] },
95+
"RegionalCertificateArn": { "Ref": "Cert5C9FAEC1" },
96+
"SecurityPolicy": "TLS_1_0"
97+
}));
98+
99+
expect(stack).to(haveResource('AWS::ApiGateway::DomainName', {
100+
"DomainName": "new.example.com",
101+
"EndpointConfiguration": { "Types": [ "REGIONAL" ] },
102+
"RegionalCertificateArn": { "Ref": "Cert5C9FAEC1" },
103+
"SecurityPolicy": "TLS_1_2"
104+
}));
105+
106+
expect(stack).to(haveResource('AWS::ApiGateway::DomainName', {
107+
"DomainName": "default.example.com",
108+
"EndpointConfiguration": { "Types": [ "REGIONAL" ] },
109+
"RegionalCertificateArn": { "Ref": "Cert5C9FAEC1" },
110+
"SecurityPolicy": ABSENT
111+
}));
112+
test.done();
113+
},
114+
68115
'"mapping" can be used to automatically map this domain to the deployment stage of an API'(test: Test) {
69116
// GIVEN
70117
const stack = new Stack();

0 commit comments

Comments
 (0)