Repository navigation
fix(ecs-service): make /tmp writable for non-root apps, add grace period and ECS Exec - #184
Merged
Merged
Conversation
…iod and ECS Exec Fargate creates the empty "tmp" task volume root-owned with mode 0755, so an app running as the default uid 1000 cannot write to /tmp (javazoneweb's nginx fails with mkdir() "/tmp/proxy_temp" ... Permission denied). A non-essential init container (busybox pinned by digest, root, read-only rootfs) now runs chmod 1777 /tmp, and the app container depends on it with condition SUCCESS. ECS.20 is suppressed for team task definitions; root app users are rejected in the generator and the module. Also: - compute.health_check_grace_period (default 120s) on services with a target group - compute.exec turns on ECS Exec and grants the task role ssmmessages channels; team permission sets may ecs:ExecuteCommand on the shared cluster, tasks stay limited to the team's own tag Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Terraform Plan🚧 Changes detected — Plan: 1 to add, 1 to change, 0 to destroy. Plan outputLLM ReviewRisk: 🟢 LOW Plan updates the team provisioner Lambda code in place (source hash change only) and creates a Security Hub automation rule that suppresses a known, accepted ECS.20 finding for platform /tmp init containers in specific task definitions.
|
This was referenced Oct 31, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
1000withreadonlyRootFilesystem = true. The only writable path is the empty task volumetmpat/tmp. Fargate creates that volume owned by root with mode 0755, so a non-root user cannot write to it. Live log fromjavazoneweb-javazone-2027(nginx-unprivileged):nginx: [emerg] mkdir() "/tmp/proxy_temp" failed (13: Permission denied). Changingcompute.userwould not help, because the volume belongs to root whatever the user is.health_check_grace_period_seconds. A task therefore had about 20-30 s to become healthy, which is too short for JVM apps.Change
modules/ecs-serviceplatform_tmp_init. It is non-essential, runs as root with a read-only root filesystem, runschmod 1777 /tmpon the shared volume and exits. The image is busybox 1.37 frompublic.ecr.aws, pinned by digest (tmp_init_image).dependsOnthe init container with conditionSUCCESS.NAME_RE), so the names can never clash.container_usernow has a validation that rejects0androot(also as0:x/root:x).health_check_grace_period_seconds(default 120). It is set only when there is a target group, because AWS rejects it without a load balancer.enable_execute_command(default false).compute.health_check_grace_period(whole seconds, 0-3600, default 120).compute.exec(bool). It setsenable_execute_commandand adds anecs-exectask-role policy with the fourssmmessages:*Channelactions.compute.execrequiresreadonly_root_filesystem: false, because AWS does not support ECS Exec with a read-only root filesystem.compute.useris validated: name, uid,user:grouporuid:gid. Root is rejected. The default stays"1000"andcompute.useroverrides it, as before; this is now documented.javabin-team-{team}inline policy getsAllowExecOnPlatformCluster, which allowsecs:ExecuteCommandon the sharedjavabin-platformcluster. The cluster is taggedteam=shared, so the existing tag-scoped allow did not cover it.AllowTeamResources(the task's propagatedteamtag).DenyXTeam) still deny other teams' tasks, so a member can exec only into their own team's tasks.terraform/org, boundary) is needed.task-definition/{team}-*for registered teams (one rule per 20 teams, the per-criterion limit).app-yaml-reference.md(compute.user, /tmp, grace period, exec),reusable-modules.md,platform-modules.md,lambda-functions.md.Checks behind the design
javabin-vpchas a NAT gateway (nat-0e9cc9e27cc6598db). Its only VPC endpoint is GuardDuty, and there are no ECR interface endpoints (that is documented as intentional). Tasks therefore reachpublic.ecr.awsthrough NAT. Public ECR pulls are anonymous, so the per-team execution role needs no new permissions.testteam-platform-test-app,cupcake-cupcake-backend,cupcake-cupcake,jzwatch-jz-watch,javazoneweb-javazone-2027) have one container withuser "1000",readonlyRootFilesystem true, thetmphost volume at/tmp,enableExecuteCommand falseand grace period 0. This change matches that shape and adds the init container.Verification
python3 -m unittest discover -s scripts/tests: 142 tests OK. NewComputeTestcovers:python3 -m unittest discover -s terraform/lambda-src/tests: 219 tests OK. The team permission set test now checks the exec statement and the tag-scoped allow.terraform fmt -check -recursiveandterraform validatepass forterraform/platformandmodules/ecs-service.terraform plan(read-only) on a scratch root that callsecs-service:0,chmod 1777 /tmp, same mount) and the app container withdependsOn SUCCESScontainer_user = "root:0"fails validationpublic.ecr.aws/v2/docker/library/busybox/manifests/1.37(multi-arch index).Follow-ups
javabin execwrapper aroundaws ecs execute-commandis not in this PR.app.yamland CLAUDE.md comments could mentionhealth_check_grace_periodandexec.🤖 Generated with Claude Code