Skip to content

Commit

Permalink
Added permissions to service discovery task
Browse files Browse the repository at this point in the history
  • Loading branch information
LDiazN committed Feb 4, 2025
1 parent 3cfc063 commit c4c8e9c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
14 changes: 12 additions & 2 deletions tf/modules/ooni_monitoring/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ resource "aws_ecs_task_definition" "ooni_service_discovery" {
{
name = "AWS_REGION"
value = var.aws_region
},
{
name = "DiscoveryOptions__EcsClusters"
value = var.cluster_name
}
]
secrets = [
Expand Down Expand Up @@ -94,7 +98,6 @@ resource "aws_ecs_task_definition" "ooni_service_discovery" {
resource "aws_ecs_service" "service" {
name = local.name
cluster = var.cluster_id
launch_type = "EC2"
task_definition = aws_ecs_task_definition.ooni_service_discovery.id
desired_count = 1

Expand All @@ -115,7 +118,7 @@ resource "aws_ecs_service" "service" {
}

resource "aws_iam_role" "ecs_sd_task" {
name = "${local.name}-task-role"
name = "${local.name}-task-role-execution"

tags = var.tags

Expand All @@ -136,6 +139,13 @@ resource "aws_iam_role" "ecs_sd_task" {
EOF
}

resource "aws_iam_role_policy" "ooni_ecs_sd_task" {
name = "${local.name}-task-role-execution"
role = aws_iam_role.ecs_sd_task.name

policy = templatefile("${path.module}/templates/profile_policy.json", {})
}

resource "aws_cloudwatch_log_group" "ooni_ecs_sd" {
name = "ooni-ecs-group/${local.name}"
}
57 changes: 57 additions & 0 deletions tf/modules/ooni_monitoring/templates/profile_policy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ecsInstanceRole",
"Effect": "Allow",
"Action": [
"ecs:DeregisterContainerInstance",
"ecs:DiscoverPollEndpoint",
"ecs:Poll",
"ecs:RegisterContainerInstance",
"ecs:Submit*",
"ecs:StartTelemetrySession"
],
"Resource": ["*"]
},
{
"Sid": "CloudWatchLogsFullAccess",
"Effect": "Allow",
"Action": ["logs:*", "cloudwatch:GenerateQuery"],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ssm:GetParameter",
"ssm:GetParameters",
"ssm:GetParameterHistory",
"ssm:GetParametersByPath"
],
"Resource": "arn:aws:ssm:*"
},
{
"Effect": "Allow",
"Action": [
"ec2:Describe*",
"elasticloadbalancing:DeregisterInstancesFromLoadBalancer",
"elasticloadbalancing:DeregisterTargets",
"elasticloadbalancing:Describe*",
"elasticloadbalancing:RegisterInstancesWithLoadBalancer",
"elasticloadbalancing:RegisterTargets"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"ecs:DescribeClusters",
"ecs:ListServices",
"ecs:DescribeServices",
"ecs:ListTasks",
"ecs:DescribeTasks"
],
"Resource": "*"
}
]
}
4 changes: 4 additions & 0 deletions tf/modules/ooni_monitoring/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,8 @@ variable "task_secrets" {

variable "cluster_id" {
type = string
}

variable "cluster_name" {
type = string
}

0 comments on commit c4c8e9c

Please sign in to comment.