AWS Security Hub · ECS
ECS.2: An ECS service auto-assigns public IPs to tasks
Written and reviewed by Emnode · Last reviewed
What does AWS Security Hub ECS.2 check?
ECS.2 inspects each ECS service's awsvpc network configuration and fails when assignPublicIp is set to ENABLED. It passes only when the flag is DISABLED, so tasks no longer receive a routable public IPv4 address at launch.
Why does ECS.2 matter?
A task with a public IP is reachable from the whole internet at the network layer, with only its security group standing in the way. That single layer drifts, gets loosened for debugging, or is copied from a more permissive service. The public IP also bypasses the ALB, WAF, and TLS termination you assume sit in front of the workload, so traffic that should be inspected and logged lands straight on the container.
How do I fix ECS.2?
- Set assignPublicIp to DISABLED in the service's awsvpcConfiguration and move tasks into private subnets.
- Give the tasks outbound access via a NAT gateway or VPC endpoints instead of a public IP.
- Front the service with an ALB or NLB for any inbound traffic.
- Add a Config rule or guardrail so new services cannot re-enable the flag.
Remediation script · bash
# Close the highest-impact public exposure first: databases.
for db in $(aws rds describe-db-instances \
--query 'DBInstances[?PubliclyAccessible==`true`].DBInstanceIdentifier' --output text); do
aws rds modify-db-instance --db-instance-identifier "$db" \
--no-publicly-accessible --apply-immediately
echo "$db: public access removed"
done
# Ratchet S3 shut at the account level so no bucket can be made public again.
aws s3control put-public-access-block --account-id 123456789012 \
--public-access-block-configuration \
'BlockPublicAcls=true,IgnorePublicAcls=true,BlockPublicPolicy=true,RestrictPublicBuckets=true' Full walkthrough (console steps, edge cases and verification) in the lesson Block public access to AWS resources.
Is ECS.2 a false positive?
A public IP is often added just so a task can pull its image or reach an external API. That is a NAT gateway or VPC-endpoint problem: re-enabling the public IP to fix egress will keep ECS.2 FAILED.
More ECS controls
- ECS.3 A task definition shares the host PID namespace
- ECS.4 A container runs in privileged mode
- ECS.5 A container has a writable root filesystem
- ECS.8 Secrets are passed as plaintext container env vars
- ECS.9 A task definition has no logging configuration
- ECS.10 Fargate services should run latest platform version
- ECS.12 ECS clusters should use Container Insights
- ECS.16 An ECS task set auto-assigns public IPs
- ECS.18 ECS task defs should encrypt EFS volumes in transit
- ECS.19 Capacity providers managed termination protection
- ECS.20 Linux containers should run as non-root users
- ECS.21 Windows containers should run as non-admin users