Skip to content
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

Support tls version #240

Merged
merged 3 commits into from Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions DomainInfo.ts
Expand Up @@ -5,6 +5,7 @@ class DomainInfo {

public domainName: string;
public hostedZoneId: string;
public securityPolicy: string;

/**
* Sometimes, the getDomainName call doesn't return either a distributionHostedZoneId or a regionalHostedZoneId.
Expand All @@ -14,12 +15,14 @@ class DomainInfo {
* PR: https://github.com/amplify-education/serverless-domain-manager/pull/171
*/
private defaultHostedZoneId: string = "Z2FDTNDATAQYW2";
private defaultSecurityPolicy: string = "TLS_1_2";

constructor(data: any) {
this.domainName = data.distributionDomainName || data.regionalDomainName;
this.hostedZoneId = data.distributionHostedZoneId ||
data.regionalHostedZoneId ||
this.defaultHostedZoneId;
this.securityPolicy = data.securityPolicy || this.defaultSecurityPolicy;
}
}

Expand Down
2 changes: 2 additions & 0 deletions README.md
Expand Up @@ -69,6 +69,7 @@ custom:
certificateName: '*.foo.com'
createRoute53Record: true
endpointType: 'regional'
securityPolicy: tls_1_2
```

| Parameter Name | Default Value | Description |
Expand All @@ -83,6 +84,7 @@ custom:
| hostedZoneId | | If hostedZoneId is set the route53 record set will be created in the matching zone, otherwise the hosted zone will be figured out from the domainName (hosted zone with matching domain). |
| hostedZonePrivate | | If hostedZonePrivate is set to `true` then only private hosted zones will be used for route 53 records. If it is set to `false` then only public hosted zones will be used for route53 records. Setting this parameter is specially useful if you have multiple hosted zones with the same domain name (e.g. a public and a private one) |
| enabled | true | Sometimes there are stages for which is not desired to have custom domain names. This flag allows the developer to disable the plugin for such cases. Accepts either `boolean` or `string` values and defaults to `true` for backwards compatibility. |
securityPolicy | tls_1_2 | The security policy to apply to the custom domain name. Accepts `tls_1_0` or `tls_1_2`|

## Running

Expand Down
15 changes: 15 additions & 0 deletions index.ts
Expand Up @@ -9,6 +9,11 @@ const endpointTypes = {
regional: "REGIONAL",
};

const tlsVersions = {
tls_1_0: "TLS_1_0",
tls_1_2: "TLS_1_2",
};

const certStatuses = ["PENDING_VALIDATION", "ISSUED", "INACTIVE"];

class ServerlessCustomDomain {
Expand All @@ -33,6 +38,7 @@ class ServerlessCustomDomain {
public basePath: string;
private endpointType: string;
private stage: string;
private securityPolicy: string;

constructor(serverless: ServerlessInstance, options: ServerlessOptions) {
this.serverless = serverless;
Expand Down Expand Up @@ -197,6 +203,14 @@ class ServerlessCustomDomain {
}
this.endpointType = endpointTypeToUse;

const securityPolicyDefault = this.serverless.service.custom.customDomain.securityPolicy ||
tlsVersions.tls_1_2;
const tlsVersionToUse = tlsVersions[securityPolicyDefault.toLowerCase()];
if (!tlsVersionToUse) {
throw new Error(`${securityPolicyDefault} is not a supported securityPolicy, use tls_1_0 or tls_1_2.`);
}
this.securityPolicy = tlsVersionToUse;

this.acmRegion = this.endpointType === endpointTypes.regional ?
this.serverless.providers.aws.getRegion() : "us-east-1";
const acmCredentials = Object.assign({}, credentials, { region: this.acmRegion });
Expand Down Expand Up @@ -317,6 +331,7 @@ class ServerlessCustomDomain {
types: [this.endpointType],
},
regionalCertificateArn: certificateArn,
securityPolicy: this.securityPolicy,
};
if (this.endpointType === endpointTypes.edge) {
params.regionalCertificateArn = undefined;
Expand Down
181 changes: 149 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "serverless-domain-manager",
"version": "3.2.7",
"version": "3.3.0",
"engines": {
"node": ">=4.0"
},
Expand Down Expand Up @@ -66,7 +66,7 @@
"wrappy": "^1.0.2"
},
"dependencies": {
"aws-sdk": "^2.177.0",
"aws-sdk": "^2.490.0",
"chalk": "^2.4.1"
}
}