Description
ECS uses the service role to manage a load balancer. You can specify an explicit role only for a load-balanced service whose tasks use a mode other than awsvpc.
Potential impact
An overprivileged service role can change unrelated resources. Set permissions separately for the application’s task role and the execution role used for image pulls and logging.
Remediation
Review the service role’s managed, inline and trust policies. Limit it to the required actions and resources. In community.aws 11.1.0, ecs_service cannot update an existing service’s role. Adjust its policies or use a supported transition, then verify the role, target registration and health.
Examples
Supply the cluster, task definition, role and actual target_group_arn. The target is port 8080 on app. With desired_count: 0 there are no running tasks to health-check.
Before
- name: ECS Service
community.aws.ecs_service:
state: present
name: console-test-service
cluster: new_cluster
task_definition: "new_cluster-task:1"
desired_count: 0
load_balancers:
- targetGroupArn: "{{ target_group_arn }}"
containerName: app
containerPort: 8080
role: admin
After
- name: ECS Service
community.aws.ecs_service:
state: present
name: console-test-service
cluster: new_cluster
task_definition: "new_cluster-task:1"
desired_count: 0
load_balancers:
- targetGroupArn: "{{ target_group_arn }}"
containerName: app
containerPort: 8080
Omitting role: admin on a new service uses the applicable ECS service-linked role. For an existing service, check the policies on its actual role.