π‘οΈ AWS ECS Task Definition with Host Network Mode runs containers as rootπ’
- Contextual name: π‘οΈ Task Definition with Host Network Mode runs containers as rootπ’
- ID:
/ce/ca/aws/ecs/task-definition-host-network-root-user - Tags:
- π’ Policy with categories
- π’ Policy with type
- π’ Production policy
- Policy Type:
COMPLIANCE_POLICY - Policy Categories:
SECURITY
Logicβ
- π§ prod.logic.yamlπ’
Similar Policiesβ
- AWS Security Hub: [ECS.1] Amazon ECS task definitions should have secure networking modes and user definitions
Descriptionβ
Descriptionβ
This policy identifies AWS ECS Task Definitions that are configured to use the host network mode while simultaneously allowing containers to run with root privileges (User ID 0).
When Network Mode is set to host, the container shares the network namespace of the underlying EC2 instance. If a process within such a container runs as root and an attacker gains the ability to escape the container runtime, they could potentially obtain unauthorized access to the hostβs network interfaces, capture traffic, or modify network configurations.
Rationaleβ
Using the host network mode significantly reduces network isolation between the container and the host. When combined with root-level privileges, this creates a high-risk security scenario:
- Privilege Escalation: If a container escape occurs, the attacker would inherit root privileges and direct access to the hostβs network stack.
- Traffic Interception: A compromised root-level container on the host network could inspect or intercept traffic intended for other services running on the same host.
... see more
Remediationβ
Remediationβ
Update the ECS Task Definition to Run Containers as a Non-Root Userβ
Using the AWS CLIβ
Retrieve the existing task definition JSON
aws ecs describe-task-definition \
--task-definition {{family-or-full-arn}} \
--query 'taskDefinition' > task-def.jsonEdit
task-def.jsonIn the
containerDefinitionsarray, update each container to run as a non-root user by setting theuserparameter to a non-zero UID."containerDefinitions": [
{
"name": "{{my-app}}",
"image": "{{my-image}}",
"user": "{{1000}}",
...
}
]Register the updated task definition
aws ecs register-task-definition --cli-input-json file://task-def.jsonUpdate your ECS service to use the new task definition revision