Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Use recommended ELB security policy #2306

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/curvy-balloons-carry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@guardian/cdk": minor
---

Use the recommended ELB security policy `ELBSecurityPolicy-TLS13-1-2-2021-06` which includes TLS 1.3, and is backwards compatible with TLS 1.2.
8 changes: 7 additions & 1 deletion src/constructs/loadbalancing/alb/application-listener.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ApplicationListener, ApplicationProtocol, ListenerAction } from "aws-cdk-lib/aws-elasticloadbalancingv2";
import {
ApplicationListener,
ApplicationProtocol,
ListenerAction,
SslPolicy,
} from "aws-cdk-lib/aws-elasticloadbalancingv2";
import type { ApplicationListenerProps } from "aws-cdk-lib/aws-elasticloadbalancingv2";
import { GuAppAwareConstruct } from "../../../utils/mixin/app-aware-construct";
import type { GuCertificate } from "../../acm";
Expand Down Expand Up @@ -47,6 +52,7 @@ export class GuHttpsApplicationListener extends GuAppAwareConstruct(ApplicationL
const mergedProps: GuApplicationListenerProps = {
port: certificate ? 443 : 8080,
protocol: certificate ? ApplicationProtocol.HTTPS : ApplicationProtocol.HTTP,
sslPolicy: SslPolicy.RECOMMENDED_TLS,
...props,
certificates: certificate
? [
Expand Down
2 changes: 2 additions & 0 deletions src/patterns/ec2-app/__snapshots__/base.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ exports[`the GuEC2App pattern can produce a restricted EC2 app locked to specifi
},
"Port": 443,
"Protocol": "HTTPS",
"SslPolicy": "ELBSecurityPolicy-TLS13-1-2-2021-06",
},
"Type": "AWS::ElasticLoadBalancingV2::Listener",
},
Expand Down Expand Up @@ -1398,6 +1399,7 @@ exports[`the GuEC2App pattern should produce a functional EC2 app with minimal a
},
"Port": 443,
"Protocol": "HTTPS",
"SslPolicy": "ELBSecurityPolicy-TLS13-1-2-2021-06",
},
"Type": "AWS::ElasticLoadBalancingV2::Listener",
},
Expand Down
25 changes: 24 additions & 1 deletion src/patterns/ec2-app/base.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Match, Template } from "aws-cdk-lib/assertions";
import { BlockDeviceVolume, EbsDeviceVolumeType } from "aws-cdk-lib/aws-autoscaling";
import { InstanceClass, InstanceSize, InstanceType, Peer, Port, Vpc } from "aws-cdk-lib/aws-ec2";
import type { CfnLoadBalancer } from "aws-cdk-lib/aws-elasticloadbalancingv2";
import { type CfnLoadBalancer } from "aws-cdk-lib/aws-elasticloadbalancingv2";
import { AccessScope, MetadataKeys } from "../../constants";
import { GuPrivateConfigBucketParameter } from "../../constructs/core";
import { GuSecurityGroup } from "../../constructs/ec2";
Expand Down Expand Up @@ -1072,4 +1072,27 @@ describe("the GuEC2App pattern", function () {
LoadBalancerAttributes: Match.arrayWith([Match.objectLike({ Key: "access_logs.s3.prefix", Value: "test-2" })]),
});
});

it("uses the latest security policy", function () {
const stack = simpleGuStackForTesting();
new GuEc2App(stack, {
applicationPort: 3000,
app: "test-gu-ec2-app",
access: { scope: AccessScope.PUBLIC },
instanceType: InstanceType.of(InstanceClass.T4G, InstanceSize.MEDIUM),
monitoringConfiguration: { noMonitoring: true },
userData: "#!/bin/dev foobarbaz",
certificateProps: {
domainName: "domain-name-for-your-application.example",
},
scaling: {
minimumInstances: 1,
},
instanceMetadataHopLimit: 2,
});

Template.fromStack(stack).hasResourceProperties("AWS::ElasticLoadBalancingV2::Listener", {
SslPolicy: "ELBSecurityPolicy-TLS13-1-2-2021-06",
Copy link
Contributor Author

@marsavar marsavar May 9, 2024

Choose a reason for hiding this comment

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

I have specifically hardcoded the string here instead of using the enum variant SslPolicy.RECOMMENDED_TLS, as AWS might change the underlying string in a future version of cdk, so this test will help us catch unexpected changes.

});
});
});