Skip to content

Commit 6dff0cf

Browse files
author
Eugene Dementiev
committed
Add variables to enable readonly root filesystem and run as user
1 parent 8bf03b2 commit 6dff0cf

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

main.tf

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ resource "aws_ecs_task_definition" "task" {
88
essential = var.essential
99
memory = var.memory
1010
memoryReservation = var.memory_reservation
11-
mountPoints = []
11+
mountPoints = var.readonlyRootFilesystem ? [{ sourceVolume = "tmp", containerPath = "/tmp" }] : []
1212
volumesFrom = []
1313
linuxParameters = {
1414
initProcessEnabled = var.init_process_enabled
1515
}
16+
readonlyRootFilesystem = var.readonlyRootFilesystem
17+
user = var.user
1618
}
1719
], var.additional_container_definitions) : merge(s, {
1820
environment = [for k in sort(keys(var.environment)) : { "name" : k, "value" : var.environment[k] }]
@@ -28,6 +30,17 @@ resource "aws_ecs_task_definition" "task" {
2830

2931
task_role_arn = var.task_role_arn
3032

33+
# the /tmp volume is needed if the root fs is readonly
34+
# tmpfs takes precious memory, so it's easier to create a volume
35+
dynamic "volume" {
36+
for_each = var.readonlyRootFilesystem ? [{}] : []
37+
content {
38+
name = "tmp"
39+
docker_volume_configuration {
40+
scope = "task"
41+
}
42+
}
43+
}
3144
}
3245

3346

variables.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ variable "log_configuration" {
8282
default = { logDriver = "", options = {} }
8383
}
8484

85+
variable "readonlyRootFilesystem" {
86+
type = bool
87+
description = "Enforce read-only access to the file system inside of the Docker container"
88+
default = false
89+
}
90+
8591
variable "deployment_minimum_healthy_percent" {
8692
description = "Minimum number of healty contianers during deployments"
8793
default = 50
@@ -93,14 +99,22 @@ variable "deployment_maximum_percent" {
9399
}
94100

95101
variable "desired_count" {
102+
type = number
96103
default = 1
97104
}
98105

99106
variable "init_process_enabled" {
107+
type = bool
100108
description = "Use embdedded to Docker tini init process that correctly reaps zombie processes"
101109
default = true
102110
}
103111

112+
variable "user" {
113+
type = string
114+
description = "Run container as the specified user. Formats are: user, user:group, uid, uid:gid, user:gid, uid:group"
115+
default = ""
116+
}
117+
104118

105119
locals {
106120
balanced = var.container_port > 0

0 commit comments

Comments
 (0)