forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
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 ClientPolicy to VirtualNode, VirtualGateway and Vi…
…rtualService (aws#11563) Adds backend defaults to Virtual Node and Virtual Gateways. Adds validation context for the backend defined on the Virtual Node. Before merging (TODO): - [ ] Update README ---- *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
14 changed files
with
427 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import { Construct } from 'constructs'; | ||
|
||
/** | ||
* Interface which all CertificateAuthority based class must implement | ||
*/ | ||
export interface ICertificateAuthority extends cdk.IResource { | ||
/** | ||
* The Amazon Resource Name of the Certificate | ||
* | ||
* @attribute | ||
*/ | ||
readonly certificateAuthorityArn: string; | ||
} | ||
|
||
/** | ||
* Defines a Certificate for ACMPCA | ||
* | ||
* @resource AWS::ACMPCA::CertificateAuthority | ||
*/ | ||
export class CertificateAuthority { | ||
/** | ||
* Import an existing Certificate given an ARN | ||
*/ | ||
public static fromCertificateAuthorityArn(scope: Construct, id: string, certificateAuthorityArn: string): ICertificateAuthority { | ||
return new class extends cdk.Resource implements ICertificateAuthority { | ||
readonly certificateAuthorityArn = certificateAuthorityArn; | ||
}(scope, id); | ||
} | ||
|
||
private constructor() { | ||
} | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
// AWS::ACMPCA CloudFormation Resources: | ||
export * from './acmpca.generated'; | ||
export * from './certificate-authority'; |
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,110 @@ | ||
import * as acmpca from '@aws-cdk/aws-acmpca'; | ||
import * as cdk from '@aws-cdk/core'; | ||
import { CfnVirtualNode } from './appmesh.generated'; | ||
|
||
enum CertificateType { | ||
ACMPCA = 'acm', | ||
FILE = 'file', | ||
} | ||
|
||
/** | ||
* Properties of TLS Client Policy | ||
*/ | ||
export interface ClientPolicyConfig { | ||
/** | ||
* Represents single Client Policy property | ||
*/ | ||
readonly clientPolicy: CfnVirtualNode.ClientPolicyProperty; | ||
} | ||
|
||
/** | ||
* Represents the property needed to define a Client Policy | ||
*/ | ||
export interface ClientPolicyOptions { | ||
/** | ||
* TLS is enforced on the ports specified here. | ||
* If no ports are specified, TLS will be enforced on all the ports. | ||
* | ||
* @default - none | ||
*/ | ||
readonly ports?: number[]; | ||
} | ||
|
||
/** | ||
* ACM Trust Properties | ||
*/ | ||
export interface AcmTrustOptions extends ClientPolicyOptions { | ||
/** | ||
* Contains information for your private certificate authority | ||
*/ | ||
readonly certificateAuthorities: acmpca.ICertificateAuthority[]; | ||
} | ||
|
||
/** | ||
* File Trust Properties | ||
*/ | ||
export interface FileTrustOptions extends ClientPolicyOptions { | ||
/** | ||
* Path to the Certificate Chain file on the file system where the Envoy is deployed. | ||
*/ | ||
readonly certificateChain: string; | ||
} | ||
|
||
/** | ||
* Defines the TLS validation context trust. | ||
*/ | ||
export abstract class ClientPolicy { | ||
/** | ||
* Tells envoy where to fetch the validation context from | ||
*/ | ||
public static fileTrust(props: FileTrustOptions): ClientPolicy { | ||
return new ClientPolicyImpl(props.ports, CertificateType.FILE, props.certificateChain, undefined); | ||
} | ||
|
||
/** | ||
* TLS validation context trust for ACM Private Certificate Authority (CA). | ||
*/ | ||
public static acmTrust(props: AcmTrustOptions): ClientPolicy { | ||
return new ClientPolicyImpl(props.ports, CertificateType.ACMPCA, undefined, props.certificateAuthorities); | ||
} | ||
|
||
/** | ||
* Returns Trust context based on trust type. | ||
*/ | ||
public abstract bind(scope: cdk.Construct): ClientPolicyConfig; | ||
|
||
} | ||
|
||
class ClientPolicyImpl extends ClientPolicy { | ||
constructor (private readonly ports: number[] | undefined, | ||
private readonly certificateType: CertificateType, | ||
private readonly certificateChain: string | undefined, | ||
private readonly certificateAuthorityArns: acmpca.ICertificateAuthority[] | undefined) { super(); } | ||
|
||
public bind(_scope: cdk.Construct): ClientPolicyConfig { | ||
if (this.certificateType === CertificateType.ACMPCA && this.certificateAuthorityArns?.map(certificateArn => | ||
certificateArn.certificateAuthorityArn).length === 0) { | ||
throw new Error('You must provide at least one Certificate Authority when creating an ACM Trust ClientPolicy'); | ||
} else { | ||
return { | ||
clientPolicy: { | ||
tls: { | ||
ports: this.ports, | ||
validation: { | ||
trust: { | ||
[this.certificateType]: this.certificateType === CertificateType.FILE | ||
? { | ||
certificateChain: this.certificateChain, | ||
} | ||
: { | ||
certificateAuthorityArns: this.certificateAuthorityArns?.map(certificateArn => | ||
certificateArn.certificateAuthorityArn), | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} | ||
} | ||
} |
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 |
---|---|---|
|
@@ -138,4 +138,5 @@ class FileAccessLog extends AccessLog { | |
}, | ||
}; | ||
} | ||
} | ||
} | ||
|
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
Oops, something went wrong.