-
Notifications
You must be signed in to change notification settings - Fork 0
Added BackendDefaults to Virtual Node #3
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
5326284
e476ae7
dbc5870
5b4c97b
b4b7f95
ce35692
4aea038
25208a4
5b260be
a55a305
7ca64da
01be91b
7e2ddbc
49824b1
0306a36
045d2a7
2cad882
20c0e96
d36fc42
4e07587
da25261
41d2c12
d18fdc4
4ec4b21
8b0b863
bd2d85e
8b707ce
de939c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,11 @@ export interface IVirtualNode extends cdk.IResource { | |
| * Utility method to add Node Listeners for new or existing VirtualNodes | ||
| */ | ||
| addListeners(...listeners: VirtualNodeListener[]): void; | ||
|
|
||
| /** | ||
| * Utility method to add Default Backend Configuration for new or existing VirtualNodes | ||
| */ | ||
| addBackendDefaults(backendDefaults: BackendDefaults): void; | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -98,6 +103,144 @@ export interface VirtualNodeBaseProps { | |
| * @default - No access logging | ||
| */ | ||
| readonly accessLog?: AccessLog; | ||
|
|
||
| /** | ||
| * Default Configuration Virtual Node uses to communicate with Vritual Service | ||
| * | ||
| * @default - No Config | ||
| */ | ||
| readonly backendDefaults?: BackendDefaults; | ||
| } | ||
|
|
||
| /** | ||
| * Default configuration that is applied to all backends for the virtual node. | ||
| * Any configuration defined will be overwritten by configurations specified for a particular backend. | ||
| */ | ||
| export interface BackendDefaults { | ||
| /** | ||
| * Client policy for TLS | ||
| */ | ||
| readonly tlsClientPolicy: TLSClientPolicyProps; | ||
| } | ||
|
|
||
| /** | ||
| * Properties with respect to TLS backend default. | ||
| */ | ||
| export interface TLSClientPolicyProps { | ||
|
||
| /** | ||
| * TLS enforced if True. | ||
|
||
| * | ||
| * @default - True | ||
| */ | ||
| readonly enforce?: boolean; | ||
|
|
||
| /** | ||
| * TLS enforced on these ports. If not specified it is enforced on all ports. | ||
| * | ||
| * @default - none | ||
| */ | ||
| readonly ports?: number[]; | ||
|
|
||
| /** | ||
| * To enforce the trust is one of file, acmpca, or sds. | ||
|
||
| * | ||
| * @default - none | ||
| */ | ||
| readonly validation: TLSClientValidation; | ||
|
||
| } | ||
|
|
||
| /** | ||
| * Defines the TLS validation context trust. | ||
| */ | ||
| export abstract class TLSClientValidation { | ||
| /** | ||
| * TLS validation context trust for a local file | ||
| */ | ||
| public static fileTrustValidation(props: FileTrustProps): TLSClientValidation { | ||
|
||
| return new FileTrust(props); | ||
| } | ||
|
|
||
| /** | ||
| * TLS validation context trust for AWS Certicate Manager (ACM) certificate. | ||
|
||
| */ | ||
| public static acmTrustValidation(props: ACMTrustProps): TLSClientValidation { | ||
| return new ACMTrust(props); | ||
| } | ||
|
|
||
| /** | ||
| * Returns Trust context based on trust type. | ||
| */ | ||
| public abstract bind(scope: cdk.Construct): CfnVirtualNode.TlsValidationContextProperty; | ||
|
||
| } | ||
|
|
||
| /** | ||
| * ACM Trust Properties | ||
| */ | ||
| export interface ACMTrustProps { | ||
| /** | ||
| * Amazon Resource Name of the Certificates | ||
|
||
| */ | ||
| readonly certificateAuthorityArns: string[]; | ||
|
||
| } | ||
|
|
||
| /** | ||
| * File Trust Properties | ||
| */ | ||
| export interface FileTrustProps { | ||
| /** | ||
| * Path to the Certificate Chain file on the file system where the Envoy is deployed. | ||
| */ | ||
| readonly certificateChain: string; | ||
| } | ||
|
|
||
| /** | ||
| * Represents a Transport Layer Security (TLS) validation context trust for a local file | ||
| */ | ||
| export class FileTrust extends TLSClientValidation { | ||
| /** | ||
| * Path to the Certificate Chain file on the file system where the Envoy is deployed. | ||
| */ | ||
| readonly certificateChain: string; | ||
|
|
||
| constructor(props: FileTrustProps) { | ||
| super(); | ||
| this.certificateChain = props.certificateChain; | ||
| } | ||
|
|
||
| public bind(_scope: cdk.Construct): CfnVirtualNode.TlsValidationContextProperty { | ||
| return { | ||
| trust: { | ||
| file: { | ||
| certificateChain: this.certificateChain, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Represents a TLS validation context trust for an AWS Certicate Manager (ACM) certificate. | ||
| */ | ||
| export class ACMTrust extends TLSClientValidation { | ||
|
||
| /** | ||
| * Amazon Resource Name of the Certificates | ||
| */ | ||
| readonly certificateAuthorityArns: string[]; | ||
|
|
||
| constructor(props: ACMTrustProps) { | ||
| super(); | ||
| this.certificateAuthorityArns = props.certificateAuthorityArns; | ||
| } | ||
|
|
||
| public bind(_scope: cdk.Construct): CfnVirtualNode.TlsValidationContextProperty { | ||
| return { | ||
| trust: { | ||
| acm: { | ||
| certificateAuthorityArns: this.certificateAuthorityArns, | ||
| }, | ||
| }, | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -123,6 +266,7 @@ abstract class VirtualNodeBase extends cdk.Resource implements IVirtualNode { | |
|
|
||
| protected readonly backends = new Array<CfnVirtualNode.BackendProperty>(); | ||
| protected readonly listeners = new Array<CfnVirtualNode.ListenerProperty>(); | ||
| protected readonly backendDefaults = new Array<CfnVirtualNode.BackendDefaultsProperty>(); | ||
|
|
||
| /** | ||
| * Add a Virtual Services that this node is expected to send outbound traffic to | ||
|
|
@@ -137,6 +281,23 @@ abstract class VirtualNodeBase extends cdk.Resource implements IVirtualNode { | |
| } | ||
| } | ||
|
|
||
| /** | ||
| * Adds Default Backend Configuration for virtual node to communicate with Virtual Services. | ||
| */ | ||
| public addBackendDefaults(backendDefaults: BackendDefaults) { | ||
| // eslint-disable-next-line no-console | ||
| console.log(backendDefaults.tlsClientPolicy.enforce); | ||
| this.backendDefaults.push({ | ||
| clientPolicy: { | ||
| tls: { | ||
| enforce: backendDefaults.tlsClientPolicy.enforce === undefined ? true : backendDefaults.tlsClientPolicy.enforce, | ||
|
||
| validation: backendDefaults.tlsClientPolicy.validation.bind(this), | ||
| ports: backendDefaults.tlsClientPolicy.ports ? backendDefaults.tlsClientPolicy.ports : undefined, | ||
|
||
| }, | ||
| }, | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Utility method to add an inbound listener for this virtual node | ||
| */ | ||
|
|
@@ -234,6 +395,9 @@ export class VirtualNode extends VirtualNodeBase { | |
|
|
||
| this.addBackends(...props.backends || []); | ||
| this.addListeners(...props.listener ? [props.listener] : []); | ||
| if (props.backendDefaults) { | ||
| this.addBackendDefaults(props.backendDefaults); | ||
| } | ||
| const accessLogging = props.accessLog?.bind(this); | ||
|
|
||
| const node = new CfnVirtualNode(this, 'Resource', { | ||
|
|
@@ -242,6 +406,7 @@ export class VirtualNode extends VirtualNodeBase { | |
| spec: { | ||
| backends: cdk.Lazy.anyValue({ produce: () => this.backends }, { omitEmptyArray: true }), | ||
| listeners: cdk.Lazy.anyValue({ produce: () => this.listeners }, { omitEmptyArray: true }), | ||
| backendDefaults: cdk.Lazy.anyValue({ produce: () => this.backendDefaults[0] }, { omitEmptyArray: true }), | ||
| serviceDiscovery: { | ||
| dns: props.dnsHostName !== undefined ? { hostname: props.dnsHostName } : undefined, | ||
| awsCloudMap: props.cloudMapService !== undefined ? { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo:
Vritual=>Virtual