-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(appmesh): add listener TLS certificates for VirtualNodes and Vir…
…tualGateways (#11863) This change allows customers to include an ACM certificiate or specify a file certificate for their listeners to use to terminate TLS. #10051 ```typescript const cert = new Certificate(stack, 'cert', { domainName: '', }); new appmesh.VirtualNode(stack, 'test-node', { mesh, dnsHostName: 'test', listeners: [appmesh.VirtualNodeListener.grpc({ port: 80, tlsCertificate: appmesh.TlsCertificate.acm({ acmCertificate: cert, tlsMode: TlsMode.STRICT, }), }, )], }); ``` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
Showing
10 changed files
with
601 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,173 @@ | ||
import * as acm from '@aws-cdk/aws-certificatemanager'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { CfnVirtualNode } from './appmesh.generated'; | ||
|
||
/** | ||
* Enum of supported TLS modes | ||
*/ | ||
export enum TlsMode { | ||
/** | ||
* Only accept encrypted traffic | ||
*/ | ||
STRICT = 'STRICT', | ||
|
||
/** | ||
* Accept encrypted and plaintext traffic. | ||
*/ | ||
PERMISSIVE = 'PERMISSIVE', | ||
|
||
/** | ||
* TLS is disabled, only accept plaintext traffic. | ||
*/ | ||
DISABLED = 'DISABLED', | ||
} | ||
|
||
/** | ||
* A wrapper for the tls config returned by {@link TlsCertificate.bind} | ||
*/ | ||
export interface TlsCertificateConfig { | ||
/** | ||
* The CFN shape for a listener TLS certificate | ||
*/ | ||
readonly tlsCertificate: CfnVirtualNode.ListenerTlsCertificateProperty, | ||
|
||
/** | ||
* The TLS mode. | ||
*/ | ||
readonly tlsMode: TlsMode; | ||
} | ||
|
||
/** | ||
* ACM Certificate Properties | ||
*/ | ||
export interface AcmCertificateOptions { | ||
/** | ||
* The TLS mode. | ||
*/ | ||
readonly tlsMode: TlsMode; | ||
|
||
/** | ||
* The ACM certificate | ||
*/ | ||
readonly certificate: acm.ICertificate; | ||
} | ||
|
||
/** | ||
* File Certificate Properties | ||
*/ | ||
export interface FileCertificateOptions { | ||
/** | ||
* The TLS mode. | ||
*/ | ||
readonly tlsMode: TlsMode; | ||
|
||
/** | ||
* The file path of the certificate chain file. | ||
*/ | ||
readonly certificateChainPath: string; | ||
|
||
/** | ||
* The file path of the private key file. | ||
*/ | ||
readonly privateKeyPath: string; | ||
} | ||
|
||
/** | ||
* Represents a TLS certificate | ||
*/ | ||
export abstract class TlsCertificate { | ||
/** | ||
* Returns an File TLS Certificate | ||
*/ | ||
public static file(props: FileCertificateOptions): TlsCertificate { | ||
return new FileTlsCertificate(props); | ||
} | ||
|
||
/** | ||
* Returns an ACM TLS Certificate | ||
*/ | ||
public static acm(props: AcmCertificateOptions): TlsCertificate { | ||
return new AcmTlsCertificate(props); | ||
} | ||
|
||
/** | ||
* Returns TLS certificate based provider. | ||
*/ | ||
public abstract bind(_scope: cdk.Construct): TlsCertificateConfig; | ||
|
||
} | ||
|
||
/** | ||
* Represents a ACM provided TLS certificate | ||
*/ | ||
class AcmTlsCertificate extends TlsCertificate { | ||
/** | ||
* The TLS mode. | ||
* | ||
* @default - TlsMode.DISABLED | ||
*/ | ||
readonly tlsMode: TlsMode; | ||
|
||
/** | ||
* The ARN of the ACM certificate | ||
*/ | ||
readonly acmCertificate: acm.ICertificate; | ||
|
||
constructor(props: AcmCertificateOptions) { | ||
super(); | ||
this.tlsMode = props.tlsMode; | ||
this.acmCertificate = props.certificate; | ||
} | ||
|
||
bind(_scope: cdk.Construct): TlsCertificateConfig { | ||
return { | ||
tlsCertificate: { | ||
acm: { | ||
certificateArn: this.acmCertificate.certificateArn, | ||
}, | ||
}, | ||
tlsMode: this.tlsMode, | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Represents a file provided TLS certificate | ||
*/ | ||
class FileTlsCertificate extends TlsCertificate { | ||
/** | ||
* The TLS mode. | ||
* | ||
* @default - TlsMode.DISABLED | ||
*/ | ||
readonly tlsMode: TlsMode; | ||
|
||
/** | ||
* The file path of the certificate chain file. | ||
*/ | ||
readonly certificateChain: string; | ||
|
||
/** | ||
* The file path of the private key file. | ||
*/ | ||
readonly privateKey: string; | ||
|
||
constructor(props: FileCertificateOptions) { | ||
super(); | ||
this.tlsMode = props.tlsMode; | ||
this.certificateChain = props.certificateChainPath; | ||
this.privateKey = props.privateKeyPath; | ||
} | ||
|
||
bind(_scope: cdk.Construct): TlsCertificateConfig { | ||
return { | ||
tlsCertificate: { | ||
file: { | ||
certificateChain: this.certificateChain, | ||
privateKey: this.privateKey, | ||
}, | ||
}, | ||
tlsMode: this.tlsMode, | ||
}; | ||
} | ||
} |
Oops, something went wrong.