Skip to content
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
3 changes: 3 additions & 0 deletions terraform/apps.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module "python_backend_prod" {
env = "prod"
vpc_id = data.aws_vpc.use2.id
logs_group = aws_cloudwatch_log_group.ecslogs.name
logs_group_arn = aws_cloudwatch_log_group.ecslogs.arn
ecs_cluster_id = module.ecs.cluster_id
task_execution_role = data.aws_iam_role.ecs_task_execution_role.arn
image_tag = "prod"
Expand Down Expand Up @@ -52,6 +53,7 @@ module "python_backend_staging" {
env = "staging"
vpc_id = data.aws_vpc.use2.id
logs_group = aws_cloudwatch_log_group.ecslogs.name
logs_group_arn = aws_cloudwatch_log_group.ecslogs.arn
ecs_cluster_id = module.ecs.cluster_id
task_execution_role = data.aws_iam_role.ecs_task_execution_role.arn
image_tag = "staging"
Expand Down Expand Up @@ -195,6 +197,7 @@ module "pybot_prod" {
env = "prod"
vpc_id = data.aws_vpc.use2.id
logs_group = aws_cloudwatch_log_group.ecslogs.name
logs_group_arn = aws_cloudwatch_log_group.ecslogs.arn
ecs_cluster_id = module.ecs.cluster_id
task_execution_role = data.aws_iam_role.ecs_task_execution_role.arn
image_tag = "latest"
Expand Down
10 changes: 10 additions & 0 deletions terraform/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ module "ecs" {

cluster_name = local.name

# ECS Exec session logs go to the shared ECS log group
cluster_configuration = {
execute_command_configuration = {
logging = "OVERRIDE"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

low security, confidence low, pass security

Exec session logs stored unencrypted in shared 7-day log group

Exec sessions on production containers (which hold injected secrets from Secrets Manager) are logged into the shared ecslogs group, with no KMS encryption configured for the exec channel or the log group. Session output could include secrets and is readable by anyone with access to that log group. Impact is limited because access requires existing ecs:ExecuteCommand or log-read permissions.

Model output from untrusted input. Check it before you act on it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Not changing this in this PR:

  • CloudWatch Logs encrypts all log groups at rest by default (AWS-owned key), and the exec channel itself is TLS. A customer KMS key would add only key-policy-based access control.
  • The people who can read ecslogs are the infrastructure group and the admins. They can already read the same secrets from Secrets Manager and open exec sessions themselves, so a separate key does not narrow access.
  • Container stdout in this group can already include the same data.

If we later want exec audit logs with their own retention or a narrower reader set, a dedicated /ecs/exec-sessions group is a small follow-up.

🤖 Generated with Claude Code

log_configuration = {
cloud_watch_log_group_name = aws_cloudwatch_log_group.ecslogs.name
}
}
}

# disable container insights to save a bit of money
cluster_settings = {
name = "containerInsights"
Expand Down
3 changes: 3 additions & 0 deletions terraform/pybot/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ locals {
resource "aws_ecs_task_definition" "pybot" {
family = "pybot_${var.env}"
execution_role_arn = var.task_execution_role
task_role_arn = aws_iam_role.task.arn
network_mode = "bridge"
cpu = local.cpu
memory = local.memory
Expand Down Expand Up @@ -74,6 +75,8 @@ resource "aws_ecs_service" "pybot" {

desired_count = local.count

enable_execute_command = true

deployment_maximum_percent = 100
deployment_minimum_healthy_percent = 0

Expand Down
40 changes: 40 additions & 0 deletions terraform/pybot/task_role.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Task role for ECS Exec (SSM messages channel) and exec session logging.
resource "aws_iam_role" "task" {
name = "pybot_${var.env}"

assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Action = "sts:AssumeRole"
Principal = { Service = "ecs-tasks.amazonaws.com" }
}]
})
}

resource "aws_iam_role_policy" "ecs_exec" {
name = "ecs-exec"
role = aws_iam_role.task.id

policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel",
"logs:DescribeLogGroups", # no resource-level support
]
Resource = "*"
},
{
Effect = "Allow"
Action = ["logs:CreateLogStream", "logs:PutLogEvents"]
Resource = "${var.logs_group_arn}:*"
},
]
})
}
5 changes: 5 additions & 0 deletions terraform/pybot/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ variable "image_tag" {
description = "The tag of the image to deploy"
default = "latest"
}

variable "logs_group_arn" {
type = string
description = "The ARN of the log group (ECS Exec session logs)"
}
3 changes: 3 additions & 0 deletions terraform/python_backend/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ locals {
resource "aws_ecs_task_definition" "python_backend" {
family = "python_backend_${var.env}"
execution_role_arn = var.task_execution_role
task_role_arn = aws_iam_role.task.arn
network_mode = "bridge"
cpu = local.cpu
memory = local.memory
Expand Down Expand Up @@ -118,6 +119,8 @@ resource "aws_ecs_service" "python_backend" {

desired_count = local.count

enable_execute_command = true

deployment_maximum_percent = 100
deployment_minimum_healthy_percent = 0

Expand Down
40 changes: 40 additions & 0 deletions terraform/python_backend/task_role.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Task role for ECS Exec (SSM messages channel) and exec session logging.
resource "aws_iam_role" "task" {
name = "python_backend_${var.env}"

assume_role_policy = jsonencode({
Version = "2012-10-17"
Statement = [{
Effect = "Allow"
Action = "sts:AssumeRole"
Principal = { Service = "ecs-tasks.amazonaws.com" }
}]
})
}

resource "aws_iam_role_policy" "ecs_exec" {
name = "ecs-exec"
role = aws_iam_role.task.id

policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Allow"
Action = [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel",
"logs:DescribeLogGroups", # no resource-level support
]
Resource = "*"
},
{
Effect = "Allow"
Action = ["logs:CreateLogStream", "logs:PutLogEvents"]
Resource = "${var.logs_group_arn}:*"
},
]
})
}
5 changes: 5 additions & 0 deletions terraform/python_backend/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ variable "image_tag" {
description = "The tag of the image to deploy"
default = "latest"
}

variable "logs_group_arn" {
type = string
description = "The ARN of the log group (ECS Exec session logs)"
}
Loading