Skip to content

Commit d4e3744

Browse files
Harden ECS task definition for Security Hub compliance (#43)
## Summary - **ECS.5 (HIGH)**: Add `readonlyRootFilesystem = true` to container definition + ephemeral `/tmp` volume mount so apps can still write temp files - **ECS.20 (MEDIUM)**: Add `user = "1000"` default (non-root) — apps can override via `compute.user` in app.yaml - Wire `container_user` through the module registry for expander support Triggered by Security Hub alerts on `platform-test-app:6` and `:7`. ## Test plan - [ ] Merge to main - [ ] Push trigger commit to platform-test-app — expand will regenerate service.tf with hardened defaults - [ ] Verify new task definition revision has `readonlyRootFilesystem: true`, `/tmp` mount, and `user: "1000"` - [ ] Verify Security Hub finding resolves within ~24h
1 parent 9623810 commit d4e3744

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎scripts/registry.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
"security_group_ids": "list:ref:platform.ecs_tasks_security_group_id",
167167
"target_group_arn": "ref:routing.target_group_arn",
168168
"region": "env:AWS_REGION",
169+
"container_user": "yaml:compute.user|default:1000",
169170
"environment": "collect:env_vars",
170171
"secrets": "collect:secret_vars",
171172
},

‎terraform/modules/ecs-service/main.tf‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,26 @@ resource "aws_ecs_task_definition" "this" {
2020
execution_role_arn = var.execution_role_arn
2121
task_role_arn = var.task_role_arn
2222

23+
volume {
24+
name = "tmp"
25+
}
26+
2327
container_definitions = jsonencode([
2428
{
2529
name = var.name
2630
image = var.image
2731
essential = true
32+
user = tostring(var.container_user)
33+
34+
readonlyRootFilesystem = true
35+
36+
mountPoints = [
37+
{
38+
sourceVolume = "tmp"
39+
containerPath = "/tmp"
40+
readOnly = false
41+
}
42+
]
2843

2944
portMappings = [
3045
{

‎terraform/modules/ecs-service/variables.tf‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,9 @@ variable "region" {
8484
description = "AWS region for CloudWatch logs"
8585
type = string
8686
}
87+
88+
variable "container_user" {
89+
description = "User to run the container as (non-root for ECS.20 compliance)"
90+
type = string
91+
default = "1000"
92+
}

0 commit comments

Comments
 (0)