Skip to content

feat(ec2): add support for vpn connections - #1899

Merged
eladb merged 14 commits into
aws:masterfrom
jogold:ec2-vpn
Mar 4, 2019
Merged

eladb merged 14 commits into
aws:masterfrom
jogold:ec2-vpn

Conversation

@jogold

@jogold jogold commented Feb 27, 2019 •

Copy link
Copy Markdown
Contributor

Add support for Site-to-Site VPN connections to VPC networks.

When VPN connections are specified, a VPN gateway is automatically
created and attached to the VPC. By default, routes are propagated on the
route tables associated with the private subnets. Propagation to routes
tables associated with public and/or isolated subnets is supported.

Update VPC context provider to also import vpnGatewayId.

References aws/jsii#231


Pull Request Checklist

  • Testing
    • Unit test added (prefer not to modify an existing test, otherwise, it's probably a breaking change)
    • CLI change?: coordinate update of integration tests with team
    • cdk-init template change?: coordinated update of integration tests with team
  • Docs
    • jsdocs: All public APIs documented
    • README: README and/or documentation topic updated
  • Title and Description
    • Change type: title prefixed with fix, feat will appear in changelog
    • Title: use lower-case and doesn't end with a period
    • Breaking?: last paragraph: "BREAKING CHANGE: <describe what changed + link for details>"
    • Issues: Indicate issues fixed via: "Fixes #xxx" or "Closes #xxx"
  • Sensitive Modules (requires 2 PR approvers)
    • IAM Policy Document (in @aws-cdk/aws-iam)
    • EC2 Security Groups and ACLs (in @aws-cdk/aws-ec2)
    • Grant APIs (only if not based on official documentation with a reference)

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

@jogold
jogold requested a review from a team as a code owner February 27, 2019 13:40

@eladb eladb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy: @PaulMaddox

Comment thread packages/@aws-cdk/aws-ec2/README.md Outdated

```ts
// Dynamic routing
vpc.newVpnConnection('Dynamic', {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

rename to addVpnConnection

Comment thread packages/@aws-cdk/aws-ec2/README.md Outdated

```ts
const vpc = new ec2.VpcNetwork(stack, 'MyVpc', {
vpnGateway: true

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

allow specifying vpnConnections in props as well via a map from ID to options:

new VpcNetwork(this, 'MyVpc', {
  vpnConnections: {
    dynamic: { ip: '1.2.3.4' }
  }
});


/**
* The id of the route table associated with this subnet.
* Not available for an imported subnet.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Will this throw for imported subnets?

@jogold jogold Feb 27, 2019 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No, it won't. We need routeTableId in order to propagate routes. The AWS::EC2::VPNGatewayRoutePropagation references it and is created inside the VpcNetwork construct. For imported networks/subnets we just don't need this routeTableId

Comment thread packages/@aws-cdk/aws-ec2/lib/vpc.ts Outdated

// Propagate routes on route tables associated with private subnets
const routePropagation = new CfnVPNGatewayRoutePropagation(this, 'RoutePropagation', {
routeTableIds: this.privateSubnets.map(subnet => subnet.routeTableId!),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No !s please (it indicates that either the model is wrong or that we need a check with a good error thrown). Seems like routeTableId cannot be undefined

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's indeed a mistake.

Comment thread packages/@aws-cdk/aws-ec2/lib/vpc.ts Outdated

this.subnetId = props.subnetId;
this.availabilityZone = props.availabilityZone;
this.routeTableId = '';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

that's fishy

Comment thread packages/@aws-cdk/aws-ec2/lib/vpn.ts Outdated
tunnelInsideCidr: string;
}

export interface BaseVpnConnectionProps {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please rename to VpnConnectionOptions (see #1740)

Comment thread packages/@aws-cdk/aws-ec2/lib/vpn.ts Outdated
/**
* The IPsec 1 VPN connection type.
*/
export const IPsec1 = 'ipsec.1';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this be an enum maybe?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Switching to an enum with only one member seems problematic for jsii? See build logs...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You are correct: aws/jsii#231

Can you add another member, even a dummy one?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And you can add this to the jsii issue and we'll fix once the jsii bug is fixed.

Comment thread packages/@aws-cdk/aws-ec2/lib/vpc.ts Outdated
/**
* Indicates whether a VPN gateway should be created and attached to this VPC.
*
* @default false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we make this default smarter, so if I define vpn connections on this VPC, it will default to "true", and otherwise to "false". I would expect this to Just Work (TM):

new VpcNetwork(this, 'VPC', {
  vpnConnections: {
    dynamic: { ip: '1.2.3.4' }
  }
});

@eladb

eladb commented Feb 27, 2019

Copy link
Copy Markdown
Contributor

Hey @jogold great work by the way!

@eladb eladb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good! I'd like @rix0rrr or @PaulMaddox 's feedback here as well

Comment thread packages/@aws-cdk/aws-ec2/README.md Outdated
});
```

To export a VPC that can accept VPN connections, set `vpnGateway` to `true`:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

"export"?

Comment thread packages/@aws-cdk/aws-ec2/lib/vpc.ts Outdated
routePropagation.node.addDependency(attachment);

const vpnConnections = props.vpnConnections || {};
Object.keys(vpnConnections).forEach(cId => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Style: I prefer:

for (const [ id, vpn ] of Object.entries(vpnConnections)) {
  // ...
}

Comment thread packages/@aws-cdk/aws-ec2/lib/vpn.ts Resolved
@eladb

eladb commented Feb 27, 2019

Copy link
Copy Markdown
Contributor

@leepa if you have some time to take a quick look, it will be much appreciated.

@eladb

eladb commented Feb 27, 2019

Copy link
Copy Markdown
Contributor

@jogold 👍

@jogold

jogold commented Feb 27, 2019 •

Copy link
Copy Markdown
Contributor Author

Do we need to support an option to propagate routes on isolated subnets? We could have something like:

export enum RoutesPropagationType {
  PrivateOnly,
  PrivateIsolated
}
export interface VpcNetworkProps {
  ...
  /**
   * Where to propagate VPN routes.
   *
   * @default on the route tables associated with the private subnets 
   */
  vpnRoutesPropagation?: RoutesPropagationType
  ...
}

@eladb

eladb commented Feb 27, 2019

Copy link
Copy Markdown
Contributor

@jogold sounds useful

@leepa leepa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Love this addition - it will make handling VPN connections nicer. There's the case of handing subnet groups rather than being opinionated about only allowing private subnets (so for example, some customers want to just SSH directly to hosts via the VPN connection).

Comment thread packages/@aws-cdk/aws-ec2/lib/vpc.ts Outdated

// Propagate routes on route tables associated with private subnets
const routePropagation = new CfnVPNGatewayRoutePropagation(this, 'RoutePropagation', {
routeTableIds: (this.privateSubnets as VpcPrivateSubnet[]).map(subnet => subnet.routeTableId),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should consider allowing an option to allow for subnetgroups to be chosen by the user of this to decide what to propogate - there are reasons you might want to route public (and isolated)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK, on it.

Comment thread packages/@aws-cdk/aws-ec2/lib/vpn.ts Outdated
* The range of inside IP addresses for the tunnel. Any specified CIDR blocks must be
* unique across all VPN connections that use the same virtual private gateway.
*/
tunnelInsideCidr: string;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will fix.

Comment thread packages/@aws-cdk/aws-ec2/lib/vpn.ts Outdated
/**
* Tunnel options for the VPN connection.
*/
vpnTunnelOptions?: VpnTunnelOption[];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Tests don't appear to cover this.

@eladb

eladb commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

@leepa are you happy with this? Can we merge?

@leepa

leepa commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

@eladb if the tests are passing, the changes look good!

@eladb

eladb commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

@jogold may I ask that you write up a nice PR description so we can use as a commit message?

@jogold

jogold commented Mar 4, 2019

Copy link
Copy Markdown
Contributor Author

@eladb updated description, is this ok?

@eladb
eladb merged commit e150648 into aws:master Mar 4, 2019
@eladb

eladb commented Mar 4, 2019

Copy link
Copy Markdown
Contributor

Perfect. Thanks!

@jogold
jogold deleted the ec2-vpn branch March 12, 2019 11:23
@jogold jogold mentioned this pull request Mar 28, 2019
3 of 4 tasks
ali-n4i pushed a commit to ali-n4i/aws-cdk that referenced this pull request Jul 29, 2026
Add support for Site-to-Site VPN connections to VPC networks.

When VPN connections are specified, a VPN gateway is automatically
created and attached to the VPC. By default, routes are propagated on the
route tables associated with the private subnets. Propagation to routes
tables associated with public and/or isolated subnets is supported.

Update VPC context provider to also import vpnGatewayId.

References aws/jsii#231
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.

3 participants