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

update ecs template with unprivileged mode and correct user/group #49

Merged
merged 2 commits into from
Jun 26, 2024
Merged
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
62 changes: 34 additions & 28 deletions modules/aws_ecs/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ resource "aws_cloudwatch_log_group" "this" {
}

resource "aws_db_subnet_group" "this" {
name = "${var.deployment_name}-retool"
name = "${var.deployment_name}-retool"
subnet_ids = var.private_subnet_ids
}

Expand Down Expand Up @@ -69,7 +69,7 @@ resource "aws_ecs_service" "retool" {
for_each = var.launch_type == "FARGATE" ? toset([1]) : toset([])


content {
content {
subnets = var.private_subnet_ids
security_groups = [
aws_security_group.containers.id
Expand Down Expand Up @@ -97,7 +97,7 @@ resource "aws_ecs_service" "jobs_runner" {

for_each = var.launch_type == "FARGATE" ? toset([1]) : toset([])

content {
content {
subnets = var.private_subnet_ids
security_groups = [
aws_security_group.containers.id
Expand Down Expand Up @@ -129,7 +129,7 @@ resource "aws_ecs_service" "workflows_backend" {

for_each = var.launch_type == "FARGATE" ? toset([1]) : toset([])

content {
content {
subnets = var.private_subnet_ids
security_groups = [
aws_security_group.containers.id
Expand Down Expand Up @@ -157,7 +157,7 @@ resource "aws_ecs_service" "workflows_worker" {

for_each = var.launch_type == "FARGATE" ? toset([1]) : toset([])

content {
content {
subnets = var.private_subnet_ids
security_groups = [
aws_security_group.containers.id
Expand Down Expand Up @@ -419,14 +419,14 @@ resource "aws_ecs_task_definition" "retool_workflows_worker" {
}

resource "aws_ecs_task_definition" "retool_code_executor" {
count = var.code_executor_enabled ? 1 : 0
family = "retool-code-executor"
task_role_arn = aws_iam_role.task_role.arn
execution_role_arn = var.launch_type == "FARGATE" ? aws_iam_role.execution_role[0].arn : null
requires_compatibilities = var.launch_type == "FARGATE" ? ["FARGATE"] : null
network_mode = var.launch_type == "FARGATE" ? "awsvpc" : "bridge"
cpu = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["code_executor"]["cpu"] : null
memory = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["code_executor"]["memory"] : null
count = var.code_executor_enabled ? 1 : 0
family = "retool-code-executor"
task_role_arn = aws_iam_role.task_role.arn
execution_role_arn = var.launch_type == "FARGATE" ? aws_iam_role.execution_role[0].arn : null
requires_compatibilities = var.launch_type == "FARGATE" ? ["FARGATE"] : null
network_mode = var.launch_type == "FARGATE" ? "awsvpc" : "bridge"
cpu = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["code_executor"]["cpu"] : null
memory = var.launch_type == "FARGATE" ? var.ecs_task_resource_map["code_executor"]["memory"] : null
container_definitions = jsonencode(
[
{
Expand All @@ -435,6 +435,7 @@ resource "aws_ecs_task_definition" "retool_code_executor" {
image = local.ecs_code_executor_image
cpu = var.launch_type == "EC2" ? var.ecs_task_resource_map["code_executor"]["cpu"] : null
memory = var.launch_type == "EC2" ? var.ecs_task_resource_map["code_executor"]["memory"] : null
user = var.launch_type == "FARGATE" ? "1001:1001" : null
command = [
"./start.sh"
]
Expand All @@ -460,9 +461,14 @@ resource "aws_ecs_task_definition" "retool_code_executor" {
}
]

environment = concat(
environment = compact(concat(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

local.base_environment_variables,
)
# https://docs.retool.com/reference/environment-variables/code-executor#container_unprivileged_mode
var.launch_type == "FARGATE" ? {
name = "CONTAINER_UNPRIVILEGED_MODE"
value = "true"
Comment on lines +468 to +469
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ECS Fargate cannot use privileged containers atm, turn off sandboxing.

} : null,
))
}
]
)
Expand Down Expand Up @@ -516,18 +522,18 @@ resource "aws_service_discovery_service" "retool_code_executor_service" {
}

module "temporal" {
count = var.workflows_enabled && !var.use_exising_temporal_cluster ? 1 : 0
source = "./temporal"
deployment_name = "${var.deployment_name}-temporal"
vpc_id = var.vpc_id
subnet_ids = var.private_subnet_ids
private_dns_namespace_id = aws_service_discovery_private_dns_namespace.retoolsvc[0].id
aws_cloudwatch_log_group_id = aws_cloudwatch_log_group.this.id
count = var.workflows_enabled && !var.use_exising_temporal_cluster ? 1 : 0
source = "./temporal"
deployment_name = "${var.deployment_name}-temporal"
vpc_id = var.vpc_id
subnet_ids = var.private_subnet_ids
private_dns_namespace_id = aws_service_discovery_private_dns_namespace.retoolsvc[0].id
aws_cloudwatch_log_group_id = aws_cloudwatch_log_group.this.id
temporal_aurora_performance_insights_enabled = var.temporal_aurora_performance_insights_enabled
aws_region = var.aws_region
aws_ecs_cluster_id = aws_ecs_cluster.this.id
launch_type = var.launch_type
container_sg_id = aws_security_group.containers.id
aws_ecs_capacity_provider_name = var.launch_type == "EC2" ? aws_ecs_capacity_provider.this[0].name : null
task_propagate_tags = var.task_propagate_tags
aws_region = var.aws_region
aws_ecs_cluster_id = aws_ecs_cluster.this.id
launch_type = var.launch_type
container_sg_id = aws_security_group.containers.id
aws_ecs_capacity_provider_name = var.launch_type == "EC2" ? aws_ecs_capacity_provider.this[0].name : null
task_propagate_tags = var.task_propagate_tags
}