-
Notifications
You must be signed in to change notification settings - Fork 6
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: mount a volume and enforce readonlyRootFilesystem in ecs-task #2544
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@guardian/cdk": major | ||
--- | ||
|
||
Enforce readonlyRootFilesystem in ecs-task. Support mounting a volume in ecs-task. | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,6 +120,13 @@ export interface GuEcsTaskProps extends AppIdentity { | |
securityGroups?: ISecurityGroup[]; | ||
customTaskPolicies?: PolicyStatement[]; | ||
environmentOverrides?: TaskEnvironmentVariable[]; | ||
/** | ||
* If your container needs to write to disk whilst running, you will need to mount a non-root volume to use. Setting | ||
* volumeMountPath will ensure a volume is mounted at that location, making use of Faragate ephemeral storage (set by | ||
* 'storage' param) | ||
* | ||
*/ | ||
volumeMountPath?: string; | ||
Comment on lines
+123
to
+129
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. An alternative might be to expose the created export class GuEcsTask extends Construct {
public readonly task: TaskDefinition;
public readonly container: ContainerDefinition;
constructor() {
super();
const taskDefinition = new TaskDefinition(...);
const containerDefinition = new ContainerDefinition(...);
this.task = taskDefinition;
this.container = containerDefinition;
}
} This approach avoids adding a new optional prop1 and increases flexibility as we can now freely call any function available on const { task, container } = new GuEcsTask(...);
task.addVolume({
name: 'asd'
});
task.someOtherUsefulFunction(...); Footnotes
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh that's a much better approach! |
||
storage?: number; | ||
/** | ||
* Whether to give the task IAM role access to the account's dist bucket. | ||
|
@@ -128,11 +135,6 @@ export interface GuEcsTaskProps extends AppIdentity { | |
* shoud set this value to `false`. | ||
*/ | ||
enableDistributablePolicy?: boolean; | ||
/** | ||
* When this parameter is true, the container is given read-only access to its root file system. | ||
* @default false | ||
*/ | ||
readonlyRootFilesystem?: boolean; | ||
/** | ||
* If `true`, CloudWatch Container Insights will be enabled for the cluster | ||
* @default false | ||
|
@@ -185,8 +187,8 @@ export class GuEcsTask extends Construct { | |
monitoringConfiguration, | ||
securityGroups = [], | ||
environmentOverrides, | ||
volumeMountPath, | ||
enableDistributablePolicy = true, | ||
readonlyRootFilesystem = false, | ||
containerInsights = false, | ||
} = props; | ||
|
||
|
@@ -227,9 +229,21 @@ export class GuEcsTask extends Construct { | |
streamPrefix: app, | ||
logRetention: 14, | ||
}), | ||
readonlyRootFilesystem, | ||
readonlyRootFilesystem: true, | ||
}); | ||
|
||
if (volumeMountPath) { | ||
taskDefinition.addVolume({ | ||
name: `${app}-volume`, | ||
}); | ||
|
||
containerDefinition.addMountPoints({ | ||
sourceVolume: `${app}-volume`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this work only because the string matches import type { Volume } from 'aws-cdk-lib/aws-ecs';
const volume: Volume = {
name: `${app}-volume`,
};
taskDefinition.addVolume(volume);
containerDefinition.addMountPoints({
sourceVolume: volume.name,
containerPath: volumeMountPath,
readOnly: false
}); |
||
containerPath: volumeMountPath, | ||
readOnly: false, | ||
}); | ||
} | ||
|
||
if (enableDistributablePolicy) { | ||
const distPolicy = new GuGetDistributablePolicyStatement(scope, { app }); | ||
taskDefinition.addToTaskRolePolicy(distPolicy); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we more descriptive here and offer an example implementation?