Skip to content

Commit 7294118

Browse files
authored
feat(ec2): session timeout and login banner for client vpn endpoint (#18590)
Add support for session timeout and client login banner for Client VPN endpoints. Modeled the session timeout as an `enum` and not a `Duration` because it only accepts a sets of values (comparable to `RetentionDays` in `aws-logs`). ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent e10391b commit 7294118

File tree

3 files changed

+76
-1
lines changed

3 files changed

+76
-1
lines changed

packages/@aws-cdk/aws-ec2/lib/client-vpn-endpoint.ts

+44
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,37 @@ export interface ClientVpnEndpointOptions {
150150
* @default true
151151
*/
152152
readonly authorizeAllUsersToVpcCidr?: boolean;
153+
154+
/**
155+
* The maximum VPN session duration time.
156+
*
157+
* @default ClientVpnSessionTimeout.TWENTY_FOUR_HOURS
158+
*/
159+
readonly sessionTimeout?: ClientVpnSessionTimeout;
160+
161+
/**
162+
* Customizable text that will be displayed in a banner on AWS provided clients
163+
* when a VPN session is established.
164+
*
165+
* UTF-8 encoded characters only. Maximum of 1400 characters.
166+
*
167+
* @default - no banner is presented to the client
168+
*/
169+
readonly clientLoginBanner?: string;
170+
}
171+
172+
/**
173+
* Maximum VPN session duration time
174+
*/
175+
export enum ClientVpnSessionTimeout {
176+
/** 8 hours */
177+
EIGHT_HOURS = 8,
178+
/** 10 hours */
179+
TEN_HOURS = 10,
180+
/** 12 hours */
181+
TWELVE_HOURS = 12,
182+
/** 24 hours */
183+
TWENTY_FOUR_HOURS = 24,
153184
}
154185

155186
/**
@@ -284,6 +315,12 @@ export class ClientVpnEndpoint extends Resource implements IClientVpnEndpoint {
284315
throw new Error('The name of the Lambda function must begin with the `AWSClientVPN-` prefix');
285316
}
286317

318+
if (props.clientLoginBanner
319+
&& !Token.isUnresolved(props.clientLoginBanner)
320+
&& props.clientLoginBanner.length > 1400) {
321+
throw new Error(`The maximum length for the client login banner is 1400, got ${props.clientLoginBanner.length}`);
322+
}
323+
287324
const logging = props.logging ?? true;
288325
const logGroup = logging
289326
? props.logGroup ?? new logs.LogGroup(this, 'LogGroup')
@@ -317,6 +354,13 @@ export class ClientVpnEndpoint extends Resource implements IClientVpnEndpoint {
317354
transportProtocol: props.transportProtocol,
318355
vpcId: props.vpc.vpcId,
319356
vpnPort: props.port,
357+
sessionTimeoutHours: props.sessionTimeout,
358+
clientLoginBannerOptions: props.clientLoginBanner
359+
? {
360+
enabled: true,
361+
bannerText: props.clientLoginBanner,
362+
}
363+
: undefined,
320364
});
321365

322366
this.endpointId = endpoint.ref;

packages/@aws-cdk/aws-ec2/package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,9 @@
693693
"props-physical-name:@aws-cdk/aws-ec2.VpnGatewayProps",
694694
"props-physical-name:@aws-cdk/aws-ec2.ClientVpnEndpointProps",
695695
"props-physical-name:@aws-cdk/aws-ec2.ClientVpnAuthorizationRuleProps",
696-
"props-physical-name:@aws-cdk/aws-ec2.ClientVpnRouteProps"
696+
"props-physical-name:@aws-cdk/aws-ec2.ClientVpnRouteProps",
697+
"duration-prop-type:@aws-cdk/aws-ec2.ClientVpnEndpointOptions.sessionTimeout",
698+
"duration-prop-type:@aws-cdk/aws-ec2.ClientVpnEndpointProps.sessionTimeout"
697699
]
698700
},
699701
"stability": "stable",

packages/@aws-cdk/aws-ec2/test/client-vpn-endpoint.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,35 @@ test('client vpn endpoint with custom route', () => {
242242
});
243243
});
244244

245+
test('client vpn endpoint with custom session timeout', () => {
246+
vpc.addClientVpnEndpoint('Endpoint', {
247+
cidr: '10.100.0.0/16',
248+
serverCertificateArn: 'server-certificate-arn',
249+
clientCertificateArn: 'client-certificate-arn',
250+
sessionTimeout: ec2.ClientVpnSessionTimeout.TEN_HOURS,
251+
});
252+
253+
Template.fromStack(stack).hasResourceProperties('AWS::EC2::ClientVpnEndpoint', {
254+
SessionTimeoutHours: 10,
255+
});
256+
});
257+
258+
test('client vpn endpoint with client login banner', () => {
259+
vpc.addClientVpnEndpoint('Endpoint', {
260+
cidr: '10.100.0.0/16',
261+
serverCertificateArn: 'server-certificate-arn',
262+
clientCertificateArn: 'client-certificate-arn',
263+
clientLoginBanner: 'Welcome!',
264+
});
265+
266+
Template.fromStack(stack).hasResourceProperties('AWS::EC2::ClientVpnEndpoint', {
267+
ClientLoginBannerOptions: {
268+
Enabled: true,
269+
BannerText: 'Welcome!',
270+
},
271+
});
272+
});
273+
245274
test('throws with more than 2 dns servers', () => {
246275
expect(() => vpc.addClientVpnEndpoint('Endpoint', {
247276
cidr: '10.100.0.0/16',

0 commit comments

Comments
 (0)