Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: DBTP-1563 - Use iam_role_policy instead of deprecated inline policies #347

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions elasticache-redis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ resource "aws_iam_role" "conduit_ecs_task_role" {
name = "${var.name}-${var.application}-${var.environment}-conduitEcsTask"
assume_role_policy = data.aws_iam_policy_document.assume_ecstask_role.json

inline_policy {
name = "AllowReadingofCMKSecrets"
policy = data.aws_iam_policy_document.access_ssm_with_kms.json
}

tags = local.tags
}

Expand All @@ -110,6 +105,12 @@ data "aws_iam_policy_document" "assume_ecstask_role" {
}
}

resource "aws_iam_role_policy" "kms_access_for_conduit_ecs_task" {
name = "AllowReadingofCMKSecrets"
role = aws_iam_role.conduit_ecs_task_role.name
policy = data.aws_iam_policy_document.access_ssm_with_kms.json
}

data "aws_iam_policy_document" "access_ssm_with_kms" {
statement {
actions = [
Expand Down
10 changes: 10 additions & 0 deletions elasticache-redis/tests/unit.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,14 @@ run "test_create_conduit_iam_role" {
condition = strcontains(jsonencode(data.aws_iam_policy_document.assume_ecstask_role.statement[0].principals), "ecs-tasks.amazonaws.com")
error_message = "Should be: ecs-tasks.amazonaws.com"
}

# Check kms access role policy
assert {
condition = aws_iam_role_policy.kms_access_for_conduit_ecs_task.name == "AllowReadingofCMKSecrets"
error_message = "Should be: 'AllowReadingofCMKSecrets'"
}
assert {
condition = aws_iam_role_policy.kms_access_for_conduit_ecs_task.role == "test-redis-test-application-test-environment-conduitEcsTask"
error_message = "Should be: 'test-redis-test-application-test-environment-conduitEcsTask'"
}
}
4 changes: 2 additions & 2 deletions monitoring/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ resource "aws_cloudwatch_dashboard" "compute" {
x : 0,
type : "log",
properties : {
query : "SOURCE '/aws/ecs/containerinsights/${var.application}-${var.environment}/performance' | fields fromMillis(Timestamp) as Time, ClusterName as Cluster, TaskDefinitionFamily as Service, ContainerName as Container, Image\n| filter @message like 'application:'\n| sort Cluster, Service, Container\n| dedup Service, Container",
query : "SOURCE '/aws/ecs/containerinsights/${var.application}-${var.environment}/performance' | fields fromMillis(Timestamp) as Time, ClusterName as Cluster, TaskDefinitionFamily as Service, ContainerName as Container, Image\n| filter @message like '${var.application}/'\n| sort Cluster, Service, Container\n| dedup Service, Container",
region : "eu-west-2",
stacked : false,
title : "Deployed Application Images",
Expand All @@ -23,7 +23,7 @@ resource "aws_cloudwatch_dashboard" "compute" {
x : 0,
type : "log",
properties : {
query : "SOURCE '/aws/ecs/containerinsights/${var.application}-${var.environment}/performance' | fields fromMillis(Timestamp) as Time, ClusterName as Cluster, TaskDefinitionFamily as Service, ContainerName as Container, Image\n| filter @message like '\"Image\":'\n| filter @message not like 'application:'\n| sort Cluster, Service, Container\n| dedup Service, Container",
query : "SOURCE '/aws/ecs/containerinsights/${var.application}-${var.environment}/performance' | fields fromMillis(Timestamp) as Time, ClusterName as Cluster, TaskDefinitionFamily as Service, ContainerName as Container, Image\n| filter @message like '\"Image\":'\n| filter @message not like '${var.application}/'\n| sort Cluster, Service, Container\n| dedup Service, Container",
region : "eu-west-2",
stacked : false,
title : "Deployed Sidecar Images",
Expand Down
11 changes: 6 additions & 5 deletions opensearch/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,6 @@ resource "aws_iam_role" "conduit_ecs_task_role" {
name = "${var.name}-${var.application}-${var.environment}-conduitEcsTask"
assume_role_policy = data.aws_iam_policy_document.assume_ecstask_role.json

inline_policy {
name = "AllowReadingofCMKSecrets"
policy = data.aws_iam_policy_document.access_ssm_with_kms.json
}

tags = local.tags
}

Expand All @@ -250,6 +245,12 @@ data "aws_iam_policy_document" "assume_ecstask_role" {
}
}

resource "aws_iam_role_policy" "kms_access_for_conduit_ecs_task" {
name = "AllowReadingofCMKSecrets"
role = aws_iam_role.conduit_ecs_task_role.name
policy = data.aws_iam_policy_document.access_ssm_with_kms.json
}

data "aws_iam_policy_document" "access_ssm_with_kms" {
statement {
actions = [
Expand Down
10 changes: 10 additions & 0 deletions opensearch/tests/unit.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -462,4 +462,14 @@ run "aws_kms_key_unit_test" {
condition = strcontains(jsonencode(data.aws_iam_policy_document.assume_ecstask_role.statement[0].principals), "ecs-tasks.amazonaws.com")
error_message = "Should be: ecs-tasks.amazonaws.com"
}

# Check kms access role policy
assert {
condition = aws_iam_role_policy.kms_access_for_conduit_ecs_task.name == "AllowReadingofCMKSecrets"
error_message = "Should be: 'AllowReadingofCMKSecrets'"
}
assert {
condition = aws_iam_role_policy.kms_access_for_conduit_ecs_task.role == "my_name-my_app-my_env-conduitEcsTask"
error_message = "Should be: 'my_name-my_app-my_env-conduitEcsTask'"
}
}
9 changes: 5 additions & 4 deletions postgres/lambda.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,12 @@ resource "aws_iam_role" "lambda-execution-role" {
name = "${local.name}-lambda-role"
path = "/"
assume_role_policy = data.aws_iam_policy_document.lambda-assume-role-policy.json
}

inline_policy {
name = "${local.name}-execution-policy"
policy = data.aws_iam_policy_document.lambda-execution-policy.json
}
resource "aws_iam_role_policy" "lambda-execution-role-policy" {
name = "${local.name}-execution-policy"
role = aws_iam_role.lambda-execution-role.name
policy = data.aws_iam_policy_document.lambda-execution-policy.json
}

data "aws_security_group" "rds-endpoint" {
Expand Down
14 changes: 14 additions & 0 deletions postgres/tests/unit.tftest.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,20 @@ run "aws_iam_role_unit_test" {
error_message = "Should be: {\"Sid\": \"AllowLambdaAssumeRole\"}"
}

# Check lambda execution role policy
assert {
condition = aws_iam_role_policy.lambda-execution-role-policy.name == "test-application-test-env-test-name-execution-policy"
error_message = "Should be: 'test-application-test-env-test-name-execution-policy'"
}
assert {
condition = aws_iam_role_policy.lambda-execution-role-policy.role == "test-application-test-env-test-name-lambda-role"
error_message = "Should be: 'test-application-test-env-test-name-lambda-role'"
}
assert {
condition = aws_iam_role_policy.lambda-execution-role-policy.policy == "{\"Sid\": \"LambdaExecutionPolicy\"}"
error_message = "Unexpected policy"
}

# Check the contents of the policy document
assert {
condition = contains(data.aws_iam_policy_document.lambda-assume-role-policy.statement[0].actions, "sts:AssumeRole")
Expand Down