Skip to content

Commit 9965cd4

Browse files
authored
[IT-3951] Fix guardduty container (#71)
We enable guardduty security monitoring for ECS in every account. For that to work we need to give Fragate tasks access to do ECS stuff with the service-role/AmazonECSTaskExecutionRolePolicy[1]. [1] https://docs.aws.amazon.com/guardduty/latest/ug/prereq-runtime-monitoring-ecs-support.html#before-enable-runtime-monitoring-ecs
1 parent 1d9e130 commit 9965cd4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

openchallenges/service_stack.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,36 @@ def __init__(
6060
)
6161
)
6262

63+
# default ECS execution policy plus Guardduty access
64+
execution_role = iam.Role(
65+
self,
66+
"ExecutionRole",
67+
assumed_by=iam.ServicePrincipal("ecs-tasks.amazonaws.com"),
68+
managed_policies=[
69+
iam.ManagedPolicy.from_aws_managed_policy_name(
70+
"service-role/AmazonECSTaskExecutionRolePolicy"
71+
),
72+
],
73+
)
74+
execution_role.add_to_policy(
75+
iam.PolicyStatement(
76+
actions=[
77+
"logs:CreateLogStream",
78+
"logs:PutLogEvents",
79+
],
80+
resources=["*"],
81+
effect=iam.Effect.ALLOW,
82+
)
83+
)
84+
6385
# ECS task with fargate
6486
self.task_definition = ecs.FargateTaskDefinition(
6587
self,
6688
"TaskDef",
6789
cpu=1024,
6890
memory_limit_mib=4096,
6991
task_role=task_role,
92+
execution_role=execution_role,
7093
)
7194

7295
image = ecs.ContainerImage.from_registry(props.container_location)

0 commit comments

Comments
 (0)