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

CDK cross-span vuln fix (WIP) #1436

Merged
merged 2 commits into from
Jan 8, 2025
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
83 changes: 69 additions & 14 deletions cdk/lib/__snapshots__/manage-frontend.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Object {
"GuEc2App",
"GuCertificate",
"GuInstanceRole",
"GuSsmSshPolicy",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We think this replaces the old AmazonSSMManagedInstanceCore policy below to ssh into the ec2 instance.

TODO: test in code to make sure we can still ssh into the instance

"GuDescribeEC2Policy",
"GuLoggingStreamNameParameter",
"GuLogShippingPolicy",
Expand Down Expand Up @@ -134,6 +135,11 @@ Object {
},
},
"MaxSize": "6",
"MetricsCollection": Array [
Object {
"Granularity": "1Minute",
},
],
"MinSize": "3",
"Tags": Array [
Object {
Expand Down Expand Up @@ -1805,20 +1811,6 @@ Object {
],
"Version": "2012-10-17",
},
"ManagedPolicyArns": Array [
Object {
"Fn::Join": Array [
"",
Array [
"arn:",
Object {
"Ref": "AWS::Partition",
},
":iam::aws:policy/AmazonSSMManagedInstanceCore",
],
],
},
],
"Path": "/",
"Tags": Array [
Object {
Expand Down Expand Up @@ -1921,6 +1913,7 @@ Object {
},
"Port": 443,
"Protocol": "HTTPS",
"SslPolicy": "ELBSecurityPolicy-TLS13-1-2-2021-06",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As long as fastly user TLS v1.2 or later this should be fine (https://docs.aws.amazon.com/elasticloadbalancing/latest/application/describe-ssl-policies.html)

},
"Type": "AWS::ElasticLoadBalancingV2::Listener",
},
Expand All @@ -1931,6 +1924,14 @@ Object {
"Key": "deletion_protection.enabled",
"Value": "true",
},
Object {
"Key": "routing.http.x_amzn_tls_version_and_cipher_suite.enabled",
"Value": "true",
},
Object {
"Key": "routing.http.drop_invalid_header_fields.enabled",
"Value": "true",
},
Comment on lines +1931 to +1934
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We're not sure what constitutes an invalid header, but this sounds sensible.

],
"Scheme": "internet-facing",
"SecurityGroups": Array [
Expand Down Expand Up @@ -2231,6 +2232,42 @@ Object {
},
"Type": "AWS::IAM::Policy",
},
"SsmSshPolicy4CFC977E": Object {
"Properties": Object {
"PolicyDocument": Object {
"Statement": Array [
Object {
"Action": Array [
"ec2messages:AcknowledgeMessage",
"ec2messages:DeleteMessage",
"ec2messages:FailMessage",
"ec2messages:GetEndpoint",
"ec2messages:GetMessages",
"ec2messages:SendReply",
"ssm:UpdateInstanceInformation",
"ssm:ListInstanceAssociations",
"ssm:DescribeInstanceProperties",
"ssm:DescribeDocumentParameters",
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel",
Comment on lines +2241 to +2254
Copy link
Member

Choose a reason for hiding this comment

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

These match the current permissions needed according to https://github.com/guardian/ssm-scala?tab=readme-ov-file#in-aws

],
"Effect": "Allow",
"Resource": "*",
},
],
"Version": "2012-10-17",
},
"PolicyName": "ssm-ssh-policy",
"Roles": Array [
Object {
"Ref": "InstanceRoleManagefrontendC8EBF20D",
},
],
},
"Type": "AWS::IAM::Policy",
},
"TargetGroupManagefrontend7AE2B787": Object {
"Properties": Object {
"HealthCheckIntervalSeconds": 10,
Expand Down Expand Up @@ -2345,6 +2382,9 @@ Object {
"Type": "AWS::EC2::SecurityGroupIngress",
},
"supportPRODmanagefrontend8911518E": Object {
"DependsOn": Array [
"InstanceRoleManagefrontendC8EBF20D",
],
"Properties": Object {
"LaunchTemplateData": Object {
"IamInstanceProfile": Object {
Expand All @@ -2359,6 +2399,9 @@ Object {
"Ref": "AMIManagefrontend",
},
"InstanceType": "t4g.small",
"MetadataOptions": Object {
"InstanceMetadataTags": "enabled",
},
Comment on lines +2402 to +2404
Copy link
Member

Choose a reason for hiding this comment

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

this is to allow access to https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/work-with-tags-in-IMDS.html
This is probably useful for kibana logs or wazuh or something but shouldn't break anything.

"SecurityGroupIds": Array [
Object {
"Fn::GetAtt": Array [
Expand All @@ -2377,6 +2420,10 @@ Object {
Object {
"ResourceType": "instance",
"Tags": Array [
Object {
"Key": "App",
"Value": "manage-frontend",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
Expand All @@ -2402,6 +2449,10 @@ Object {
Object {
"ResourceType": "volume",
"Tags": Array [
Object {
"Key": "App",
"Value": "manage-frontend",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
Expand Down Expand Up @@ -2482,6 +2533,10 @@ systemctl start manage-frontend
Object {
"ResourceType": "launch-template",
"Tags": Array [
Object {
"Key": "App",
"Value": "manage-frontend",
},
Object {
"Key": "gu:cdk:version",
"Value": "TEST",
Expand Down
16 changes: 11 additions & 5 deletions cdk/lib/manage-frontend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@ import type { GuAsgCapacity } from '@guardian/cdk/lib/types';
import type { App } from 'aws-cdk-lib';
import { Duration } from 'aws-cdk-lib';
import { CfnDashboard } from 'aws-cdk-lib/aws-cloudwatch';
import { InstanceClass, InstanceSize, InstanceType } from 'aws-cdk-lib/aws-ec2';
import {
InstanceClass,
InstanceSize,
InstanceType,
UserData,
} from 'aws-cdk-lib/aws-ec2';
import { Protocol } from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
import { CfnRecordSet } from 'aws-cdk-lib/aws-route53';
Expand Down Expand Up @@ -45,9 +50,9 @@ export class ManageFrontend extends GuStack {
default: `/${this.stage}/${this.stack}/${app}/serverRavenDSN`,
});

// intentionally removed tabs from the following string for bash's sake!
const userData = `#!/bin/bash -ev
# get runnable tar from S3
const userData = UserData.forLinux({ shebang: '#!/bin/bash -ev' });
userData.addCommands(
`# get runnable tar from S3
aws --region ${this.region} s3 cp s3://membership-dist/${this.stack}/${this.stage}/${app}/manage-frontend.zip /tmp
mkdir /etc/gu
unzip /tmp/manage-frontend.zip -d /etc/gu/dist/
Expand Down Expand Up @@ -76,7 +81,8 @@ EOL
# RUN
systemctl enable manage-frontend
systemctl start manage-frontend
/opt/cloudwatch-logs/configure-logs application ${this.stack} ${this.stage} ${app} /var/log/manage-frontend.log`;
/opt/cloudwatch-logs/configure-logs application ${this.stack} ${this.stage} ${app} /var/log/manage-frontend.log`,
);

const logGroup = new LogGroup(this, 'ManageFrontendLogGroup', {
logGroupName: `support-manage-frontend-${this.stage}`,
Expand Down
10 changes: 5 additions & 5 deletions cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@
"deploy-code": "cdk deploy --path-metadata false --version-reporting false ManageFrontend-CODE"
},
"devDependencies": {
"@guardian/cdk": "50.10.6",
"@guardian/cdk": "61.1.0",
"@guardian/eslint-config-typescript": "1.0.7",
"@guardian/prettier": "1.0.0",
"@types/jest": "^27.5.0",
"@types/node": "18.7.14",
"aws-cdk": "2.87.0",
"aws-cdk-lib": "2.87.0",
"constructs": "10.2.69",
"aws-cdk": "2.172.0",
"aws-cdk-lib": "2.172.0",
"constructs": "10.4.2",
"eslint": "^8.23.0",
"jest": "^27.5.1",
"prettier": "^2.7.1",
"source-map-support": "^0.5.20",
"source-map-support": "0.5.21",
"ts-jest": "^27.1.4",
"ts-node": "^10.9.1",
"typescript": "~4.7.4"
Expand Down
Loading
Loading