Skip to content

Commit

Permalink
Ddls 392b - add kms decrypts for secrets key on relevant roles (#1728)
Browse files Browse the repository at this point in the history
* DDLS-392 add secrets decryption to all relevant roles
  • Loading branch information
jamesrwarren authored Nov 12, 2024
1 parent 9980dda commit a2b8b59
Show file tree
Hide file tree
Showing 9 changed files with 96 additions and 13 deletions.
11 changes: 11 additions & 0 deletions terraform/environment/region/ecs_iam_api.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ data "aws_iam_policy_document" "api_permissions" {
]
}

statement {
sid = "DecryptSecretKMS"
effect = "Allow"
actions = [
"kms:Decrypt"
]
resources = [
data.aws_kms_alias.cloudwatch_application_secret_encryption.target_key_arn
]
}

statement {
sid = "ApiGetSiriusS3Bucket"
effect = "Allow"
Expand Down
22 changes: 22 additions & 0 deletions terraform/environment/region/ecs_iam_execution.tf
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,17 @@ data "aws_iam_policy_document" "execution_role_secrets" {
]
actions = ["secretsmanager:GetSecretValue"]
}

statement {
sid = "DecryptSecretKMS"
effect = "Allow"
actions = [
"kms:Decrypt"
]
resources = [
data.aws_kms_alias.cloudwatch_application_secret_encryption.target_key_arn
]
}
}

data "aws_iam_policy_document" "execution_role_secrets_db" {
Expand All @@ -139,4 +150,15 @@ data "aws_iam_policy_document" "execution_role_secrets_db" {
]
actions = ["secretsmanager:GetSecretValue"]
}

statement {
sid = "DecryptSecretKMS"
effect = "Allow"
actions = [
"kms:Decrypt"
]
resources = [
data.aws_kms_alias.cloudwatch_application_secret_encryption.target_key_arn
]
}
}
20 changes: 10 additions & 10 deletions terraform/environment/region/ecs_iam_front.tf
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,16 @@ data "aws_iam_policy_document" "front_query_secretsmanager" {
]
}

# statement {
# sid = "DecryptSecretKMS"
# effect = "Allow"
# actions = [
# "kms:Decrypt"
# ]
# resources = [
# data.aws_kms_alias.cloudwatch_application_secret_encryption.target_key_arn
# ]
# }
statement {
sid = "DecryptSecretKMS"
effect = "Allow"
actions = [
"kms:Decrypt"
]
resources = [
data.aws_kms_alias.cloudwatch_application_secret_encryption.target_key_arn
]
}
}

resource "aws_iam_role_policy" "front_get_log_events" {
Expand Down
11 changes: 11 additions & 0 deletions terraform/environment/region/ecs_task_resilience_tests.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ data "aws_iam_policy_document" "resilience_tests" {
]
}

statement {
sid = "DecryptSecretKMS"
effect = "Allow"
actions = [
"kms:Decrypt"
]
resources = [
data.aws_kms_alias.cloudwatch_application_secret_encryption.target_key_arn
]
}

statement {
sid = "AllowFISRunExperiments"
effect = "Allow"
Expand Down
11 changes: 11 additions & 0 deletions terraform/environment/region/ecs_task_smoke_tests.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ data "aws_iam_policy_document" "smoke_tests" {
data.aws_secretsmanager_secret.smoke_tests_variables.arn
]
}

statement {
sid = "DecryptSecretKMS"
effect = "Allow"
actions = [
"kms:Decrypt"
]
resources = [
data.aws_kms_alias.cloudwatch_application_secret_encryption.target_key_arn
]
}
}

resource "aws_iam_role_policy" "smoke_tests" {
Expand Down
12 changes: 12 additions & 0 deletions terraform/environment/region/lambda_custom_sql_query.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module "lamdba_custom_sql_query" {
vpc_id = data.aws_vpc.vpc.id
secrets = []
logs_kms_key_arn = data.aws_kms_alias.cloudwatch_application_logs_encryption.arn
secrets_kms_key_arn = data.aws_kms_alias.cloudwatch_application_secret_encryption.target_key_arn
}

resource "aws_security_group_rule" "lambda_custom_sql_query_to_front" {
Expand Down Expand Up @@ -72,4 +73,15 @@ data "aws_iam_policy_document" "custom_sql_query_secretsmanager" {
data.aws_secretsmanager_secret.custom_sql_db_password.arn
]
}

statement {
sid = "DecryptSecretKMS"
effect = "Allow"
actions = [
"kms:Decrypt"
]
resources = [
data.aws_kms_alias.cloudwatch_application_secret_encryption.target_key_arn
]
}
}
11 changes: 11 additions & 0 deletions terraform/environment/region/modules/lambda/iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ data "aws_iam_policy_document" "lambda" {
]
}
}

statement {
sid = "DecryptSecretKMS"
effect = "Allow"
actions = [
"kms:Decrypt"
]
resources = [
var.secrets_kms_key_arn
]
}
}

resource "aws_iam_role_policy_attachment" "vpc_access_execution_role" {
Expand Down
5 changes: 5 additions & 0 deletions terraform/environment/region/modules/lambda/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,8 @@ variable "logs_kms_key_arn" {
description = "User managed KMS key for log encryption"
type = string
}

variable "secrets_kms_key_arn" {
description = "User managed KMS key for secrets encryption"
type = string
}
6 changes: 3 additions & 3 deletions terraform/environment/region/secrets.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ data "aws_secretsmanager_secret" "anonymise-default-pw" {
}

##### Shared Application KMS key for logs #####
#data "aws_kms_alias" "cloudwatch_application_secret_encryption" {
# name = "alias/digideps_secret_encryption_key"
#}
data "aws_kms_alias" "cloudwatch_application_secret_encryption" {
name = "alias/digideps_secret_encryption_key"
}

0 comments on commit a2b8b59

Please sign in to comment.