Skip to content

Commit 4fde59a

Browse files
authored
feat(ec2): client vpn endpoint (#12234)
Add support for client VPN endpoints with the following L2s: `ClientVpnEndpoint`, `ClientVpnAuthorizationRule` and `ClientVpnRoute`. Client VPN endpoints can be added to VPCs with the `addClientVpnEndpoint()` method. Both mutual and user-based authentication are supported. The `ClientVpnEndpoint` class implements `IConnectable`. Use a custom resource to import server and client certificates in ACM for the integration test. Close #4206 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent b940710 commit 4fde59a

19 files changed

+1964
-2
lines changed

packages/@aws-cdk/aws-ec2/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,71 @@ Note: The domain name must be owned (registered through Route53) by the account
678678
The VpcEndpointServiceDomainName will handle the AWS side of domain verification, the process for which can be found
679679
[here](https://docs.aws.amazon.com/vpc/latest/userguide/endpoint-services-dns-validation.html)
680680

681+
### Client VPN endpoint
682+
683+
AWS Client VPN is a managed client-based VPN service that enables you to securely access your AWS
684+
resources and resources in your on-premises network. With Client VPN, you can access your resources
685+
from any location using an OpenVPN-based VPN client.
686+
687+
Use the `addClientVpnEndpoint()` method to add a client VPN endpoint to a VPC:
688+
689+
```ts fixture=client-vpn
690+
vpc.addClientVpnEndpoint('Endpoint', {
691+
cidr: '10.100.0.0/16',
692+
serverCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/server-certificate-id',
693+
// Mutual authentication
694+
clientCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/client-certificate-id',
695+
// User-based authentication
696+
userBasedAuthentication: ec2.ClientVpnUserBasedAuthentication.federated(samlProvider),
697+
});
698+
```
699+
700+
The endpoint must use at least one [authentication method](https://docs.aws.amazon.com/vpn/latest/clientvpn-admin/client-authentication.html):
701+
702+
* Mutual authentication with a client certificate
703+
* User-based authentication (directory or federated)
704+
705+
If user-based authentication is used, the [self-service portal URL](https://docs.aws.amazon.com/vpn/latest/clientvpn-user/self-service-portal.html)
706+
is made available via a CloudFormation output.
707+
708+
By default, a new security group is created and logging is enabled. Moreover, a rule to
709+
authorize all users to the VPC CIDR is created.
710+
711+
To customize authorization rules, set the `authorizeAllUsersToVpcCidr` prop to `false`
712+
and use `addaddAuthorizationRule()`:
713+
714+
```ts fixture=client-vpn
715+
const endpoint = vpc.addClientVpnEndpoint('Endpoint', {
716+
cidr: '10.100.0.0/16',
717+
serverCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/server-certificate-id',
718+
userBasedAuthentication: ec2.ClientVpnUserBasedAuthentication.federated(samlProvider),
719+
authorizeAllUsersToVpcCidr: false,
720+
});
721+
722+
endpoint.addAuthorizationRule('Rule', {
723+
cidr: '10.0.10.0/32',
724+
groupId: 'group-id',
725+
});
726+
```
727+
728+
Use `addRoute()` to configure network routes:
729+
730+
```ts fixture=client-vpn
731+
const endpoint = vpc.addClientVpnEndpoint('Endpoint', {
732+
cidr: '10.100.0.0/16',
733+
serverCertificateArn: 'arn:aws:acm:us-east-1:123456789012:certificate/server-certificate-id',
734+
userBasedAuthentication: ec2.ClientVpnUserBasedAuthentication.federated(samlProvider),
735+
});
736+
737+
// Client-to-client access
738+
endpoint.addRoute('Route', {
739+
cidr: '10.100.0.0/16',
740+
target: ec2.ClientVpnRouteTarget.local(),
741+
});
742+
```
743+
744+
Use the `connections` object of the endpoint to allow traffic to other security groups.
745+
681746
## Instances
682747

683748
You can use the `Instance` class to start up a single EC2 instance. For production setups, we recommend
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { Resource } from '@aws-cdk/core';
2+
import { Construct } from 'constructs';
3+
import { IClientVpnEndpoint } from './client-vpn-endpoint-types';
4+
import { CfnClientVpnAuthorizationRule } from './ec2.generated';
5+
6+
/**
7+
* Options for a ClientVpnAuthorizationRule
8+
*/
9+
export interface ClientVpnAuthorizationRuleOptions {
10+
/**
11+
* The IPv4 address range, in CIDR notation, of the network for which access
12+
* is being authorized.
13+
*/
14+
readonly cidr: string;
15+
16+
/**
17+
* The ID of the group to grant access to, for example, the Active Directory
18+
* group or identity provider (IdP) group.
19+
*
20+
* @default - authorize all groups
21+
*/
22+
readonly groupId?: string;
23+
24+
/**
25+
* A brief description of the authorization rule.
26+
*
27+
* @default - no description
28+
*/
29+
readonly description?: string;
30+
}
31+
32+
/**
33+
* Properties for a ClientVpnAuthorizationRule
34+
*/
35+
export interface ClientVpnAuthorizationRuleProps extends ClientVpnAuthorizationRuleOptions {
36+
/**
37+
* The client VPN endpoint to which to add the rule.
38+
*/
39+
readonly clientVpnEndoint: IClientVpnEndpoint;
40+
}
41+
42+
/**
43+
* A client VPN authorization rule
44+
*/
45+
export class ClientVpnAuthorizationRule extends Resource {
46+
constructor(scope: Construct, id: string, props: ClientVpnAuthorizationRuleProps) {
47+
super(scope, id);
48+
49+
new CfnClientVpnAuthorizationRule(this, 'Resource', {
50+
clientVpnEndpointId: props.clientVpnEndoint.endpointId,
51+
targetNetworkCidr: props.cidr,
52+
accessGroupId: props.groupId,
53+
authorizeAllGroups: !props.groupId,
54+
description: props.description,
55+
});
56+
}
57+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { IDependable, IResource } from '@aws-cdk/core';
2+
import { IConnectable } from './connections';
3+
4+
/**
5+
* A client VPN endpoint
6+
*/
7+
export interface IClientVpnEndpoint extends IResource, IConnectable {
8+
/**
9+
* The endpoint ID
10+
*/
11+
readonly endpointId: string;
12+
13+
/**
14+
* Dependable that can be depended upon to force target networks associations
15+
*/
16+
readonly targetNetworksAssociated: IDependable;
17+
}
18+
19+
/**
20+
* A connection handler for client VPN endpoints
21+
*/
22+
export interface IClientVpnConnectionHandler {
23+
/**
24+
* The name of the function
25+
*/
26+
readonly functionName: string;
27+
28+
/**
29+
* The ARN of the function.
30+
*/
31+
readonly functionArn: string;
32+
}
33+
34+
/**
35+
* Transport protocol for client VPN
36+
*/
37+
export enum TransportProtocol {
38+
/** Transmission Control Protocol (TCP) */
39+
TCP = 'tcp',
40+
/** User Datagram Protocol (UDP) */
41+
UDP = 'udp',
42+
}
43+
44+
/**
45+
* Port for client VPN
46+
*/
47+
export enum VpnPort {
48+
/** HTTPS */
49+
HTTPS = 443,
50+
/** OpenVPN */
51+
OPENVPN = 1194,
52+
}

0 commit comments

Comments
 (0)