Skip to content

Commit

Permalink
[IT-3951] Fix guardduty container (#71)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zaro0508 authored Dec 3, 2024
1 parent 1d9e130 commit 9965cd4
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions openchallenges/service_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,36 @@ def __init__(
)
)

# default ECS execution policy plus Guardduty access
execution_role = iam.Role(
self,
"ExecutionRole",
assumed_by=iam.ServicePrincipal("ecs-tasks.amazonaws.com"),
managed_policies=[
iam.ManagedPolicy.from_aws_managed_policy_name(
"service-role/AmazonECSTaskExecutionRolePolicy"
),
],
)
execution_role.add_to_policy(
iam.PolicyStatement(
actions=[
"logs:CreateLogStream",
"logs:PutLogEvents",
],
resources=["*"],
effect=iam.Effect.ALLOW,
)
)

# ECS task with fargate
self.task_definition = ecs.FargateTaskDefinition(
self,
"TaskDef",
cpu=1024,
memory_limit_mib=4096,
task_role=task_role,
execution_role=execution_role,
)

image = ecs.ContainerImage.from_registry(props.container_location)
Expand Down

0 comments on commit 9965cd4

Please sign in to comment.