Skip to content

Conversation

@sshver
Copy link
Owner

@sshver sshver commented Oct 29, 2020


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

}

/**
* Default Configuration for Virtual Nodes
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be more descriptive here.

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.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added descriptive comment.

Comment on lines 123 to 144
readonly enforce?: boolean

/**
* TLS enforced on these ports. If not specified it is enforced on all ports.
*
* @default - none
*/
readonly ports?: number[]

/**
* Certificate discovery method, ACM-PCA or Local file hosting.
*
* @default - none
*/
readonly certificateType: string;

/**
* Certificate File path or Certificate ARN.
*
* @default - none
*/
readonly certificate: string[];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should not be top level properties. These are specific to the client configuration with regard to TLS. There may be other types of backend defaults we could apply in the future.

You could model this more like

interface BackendDefaults {
  readonly tlsClientPolicy: TLSClientPolicy;
}

interface TLSClientPolicy {
  /**
   * @default - True
   */
  readonly enforce?: boolean;

  ...

  readonly validation: TLSClientValidation;
}

TLSClientValidation could be modeled as a bind class to enforce the trust is one of file, acmpca, or sds (in the future). We may want to accept the Certificate Authority construct from ACMPCA, which is not yet built. Adam can help with that, we'll just need to coordinate with him

We also want to be aware of the changes that are going to be made with aws/aws-app-mesh-roadmap#34 and be able to accommodate them easily

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the model.

/**
* TLS enforced if True.
*
* @default - none
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default in our API is true, let's mirror that here

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set enforce to true by default.

*/
export interface BackendDefaults {
/**
* Client policy for TLS
Copy link

@dfezzie dfezzie Nov 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the Props name is reserved for class constructors. (Found this out in a PR I have out now)

Let's have this named TLSClientPolicyOptions

Copy link

@dfezzie dfezzie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! This will set up an easy win for adding the ClientPolicy to backends!

/**
* Client policy for TLS
*/
readonly tlsClientPolicy: TLSClientPolicyProps;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can reword this to be more descriptive

TLS Connections with downstream server will always be enforced if True

Something to that effect.


/**
* TLS enforced on these ports. If not specified it is enforced on all ports.
*
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we haven't introduced SDS yet, let's remove the reference here

We can also reword this to

Policy used to determine if the TLS certificate the server presents is accepted

*/
readonly ports?: number[]
readonly ports?: number[];

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to be optional

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't it be required ? I found this reference doc where in it says this field in required


/**
* Defines the TLS validation context trust.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could shorten this to fileTrust(...)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also potentially accept just the path to the certificate chain instead of having a props interface. Makes it simpler to use for customers, but has the drawback of not being as extensible in the future, but there are plenty of ways around that.

export abstract class TLSClientValidation {
/**
* Certificate File path or Certificate ARN.
*
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to specify this is acm-pca somehow, but it doesn't flow great :P You have any ideas?


/**
* Returns Trust context based on trust type.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should specify ACM PCA here

Amazon Resource Names (ARN) of trusted ACM Private Certificate Authorities

file: {
certificateChain: this.certificateChain,
},
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not need to be exported. Same for above


/**
* TLS validation context trust for AWS Certicate Manager (ACM) certificate.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bind should return a Config object here

certificateChain: certificate[0],
},
},
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be simplified to just backendDefaults.tlsClientPolicy.ports since it accepts undefined.

} : {
file: {
certificateChain: certificate[0],
},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think enforce: backendDefaults.tlsClientPolicy.enforce ?? true would work here?

Copy link

@dfezzie dfezzie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just a few comments.

Any reason not to implement this for Virtual Gateways?

*/
export abstract class TLSClientValidation {
/**
* TLS validation context trust for a local file
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: TLS validation provided from the local file system

This struct tells the envoy where to fetch the validation context from

same comment below

readonly accessLog?: AccessLog;

/**
* Default Configuration Virtual Node uses to communicate with Vritual Service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: Vritual => Virtual

*/
public readonly mesh: IMesh;

private readonly backendDefaults = new Array<CfnVirtualNode.BackendDefaultsProperty>();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use an Array here? This could just be CfnVirtualNode.BackendDefaultsProperty

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the backendDefaults is of type CfnVirtualNode.BackendDefaultsProperty and a private member of VirtualNode, I would have to initialize it say, with an empty object because it cannot be undefined. There are no options to omit the empty object and all the resources would have backendDefaults: {}, if not provided by the client. Whereas if we use Array we could set omitEmptyArray true.

Copy link
Owner Author

@sshver sshver Nov 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or something like this would work as well.

    if (props.backendDefaults) {
      this.backendDefaults = this.addBackendDefaults(props.backendDefaults);
    } else {
      this.backendDefaults = {};
    }

 const node = new CfnVirtualNode(this, 'Resource', {
     backendDefaults: Object.keys(this.backendDefaults).length != 0 ? this.backendDefaults : undefined,
. . .
 });

/**
* Adds Default Backend Configuration for virtual node to communicate with Virtual Services.
*/
public addBackendDefaults(clientPolicy: ClientPolicy) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would we need this method?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that the backendDefault can be added to virtual node after it has been created. Hence a public method.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed offline, I have made this method private.

this.backendDefaults.push({
clientPolicy: {
tls: {
enforce: clientPolicy.tlsClientPolicy.enforce ?? true,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically we could just do clientPolicy.tlsClientPolicy.enforce and accept the undefined since the API defaults to true. Not sure what the right thing to do here for CDK is

/**
* Defines the TLS validation context trust.
*/
export abstract class TLSClientValidation {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backend Client Policies won't be the only shapes that support validation contexts. Listeners could support validation contexts in the future (ex. mTLS).

Unless there is a limitation that forces us to have 2 different shapes for client validation and server validation, I'd recommend changing the name here to a more general TLSValidationContext. And creating a separate file for client policy shapes.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. I have updated the PR.

@sshver
Copy link
Owner Author

sshver commented Nov 18, 2020

Looks good to me. Just a few comments.

Any reason not to implement this for Virtual Gateways?

Added backend defaults for Virtual Gateways in the latest commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants