Résumé
ONYEDIKACHI BERNARDCLOUD · DEVSECOPS · AI
RésuméGet in touch
CASE 11SECURE COMPUTE

ECS Container IAM Least Privilege

An ECS service ran with no task role of its own and kept a sensitive value in plain sight in its task definition. I created a scoped task role under a permissions boundary, registered a new revision with it, and rolled the service onto it.

Status: REMEDIATED · DEPLOYED

DOMAIN
Secure compute
PLATFORM
Amazon ECS on EC2, AWS IAM
SEVERITY
Medium
OUTCOME
Dedicated task identity

TOOLS

AWS CLIAmazon ECSAWS IAMjqECS task definitionsIAM permissions boundary
RESULT
BEFORENo task role
AFTERScoped role, revision 2 live
01

Objective

I set out to inspect a running ECS service, identify its IAM misconfiguration, see what sensitive information the task definition exposed, and fix it by giving the task its own scoped IAM role.

02

Scenario

The service ran task definition revision :1 on the EC2 launch type. Its taskRoleArn was null, so the container had no application-level IAM identity of its own, which blurs the line between the app and the host underneath. A sensitive value was also stored directly in the container definition as an environment variable.

03

What I found

room44-app:1NO TASK ROLE
TaskDefinition: room44-app:1
TaskRole:       null
ExecutionRole:  room44-lab-execution-role
NetworkMode:    bridge
FINDING 01MEDIUM

No dedicated task role

The service's task definition had no task role.

Without a task role, the application has no clearly separated AWS permissions. On ECS with EC2, weak identity separation raises the risk of privileges leaking between the application and the infrastructure.

FINDING 02MEDIUM

A sensitive value in the task definition

The container definition held a sensitive value in an environment variable (the lab flag, not reproduced here). Anyone allowed to call ecs:DescribeTaskDefinition can read values stored that way.

04

What I did

  1. Pulled the service details

    I retrieved the cluster, service and task definition with the AWS CLI.

  2. Confirmed the missing role

    The task definition showed taskRoleArn: null.

  3. Checked the environment

    I queried the container's environment variables and found the exposed value.

  4. Created a scoped task role

    room44-app-task-role trusts ecs-tasks.amazonaws.com, sits under the Room44-LearnerBoundary permissions boundary, and allows only s3:GetObject and s3:ListBucket.

  5. Rolled out a new revision

    I exported the task definition, added the new role, registered it as revision :2, and updated the service to use it.

EVIDENCE

BASH
aws iam create-role --role-name room44-app-task-role \
  --assume-role-policy-document file:///tmp/room44-task-role-trust.json \
  --permissions-boundary arn:aws:iam::<ACCOUNT_ID>:policy/Room44-LearnerBoundary

aws iam put-role-policy --role-name room44-app-task-role \
  --policy-name room44-app-inline-policy \
  --policy-document file:///tmp/room44-task-role-policy.json
05

Validation

The role was created with the ECS task trust and the permissions boundary, and the service moved to the new revision:

TEXT
Task definition:  arn:aws:ecs:us-east-1:<ACCOUNT_ID>:task-definition/room44-app:2
Deployment:       revision :2 PRIMARY, revision :1 still the older active deployment
06

Before and after

CONFIGURATIONBEFOREAFTER
Task definitionroom44-app:1room44-app:2
taskRoleArnnullroom44-app-task-role
Application identityNoneDedicated task role
PermissionsNo task roleScoped S3 read
Permissions boundaryNot appliedRoom44-LearnerBoundary
07

What I recommend

  1. 01Give every ECS app that calls AWS its own task role.
  2. 02Keep task roles to least privilege, with permissions boundaries where policy requires them.
  3. 03Never put secrets or sensitive values in task definition environment variables; use a secrets manager.
  4. 04Keep execution roles, task roles and EC2 instance roles separate.
  5. 05Review task definitions regularly for excess permissions and exposed configuration.

“An ECS task should have its own narrowly scoped IAM identity, so the application's permissions stay separate from the infrastructure and sensitive configuration is not exposed through the task definition.”

WHAT I LEARNED

SKILLS IT PROVES

  • Cloud Security
  • Amazon ECS
  • Container Security
  • AWS IAM
  • Least Privilege
  • IAM Role Configuration
  • Task Definition Security
  • Security Remediation
  • AWS CLI
View my labs on GitHub