Skip to content

Commit b877c5d

Browse files
Encrypting SNS topic as is required for the 30 day guardrails (#76)
* Encrypting SNS topic as is required for the 30 day guardrails * Formatting and adding checkov skip checks
1 parent a61b9ed commit b877c5d

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

terragrunt/aws/api/sns.tf

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# SNS: topic & subscription
33
#
44
resource "aws_sns_topic" "cloudwatch_warning" {
5-
name = "gc-design-system-cloudwatch-alarms-warning"
5+
name = "gc-design-system-cloudwatch-alarms-warning"
6+
kms_master_key_id = aws_kms_key.sns_cloudwatch.id
67

78
tags = {
89
CostCentre = var.billing_code
@@ -14,4 +15,42 @@ resource "aws_sns_topic_subscription" "alert_warning" {
1415
topic_arn = aws_sns_topic.cloudwatch_warning.arn
1516
protocol = "https"
1617
endpoint = var.slack_webhook_url
18+
}
19+
20+
# KMS Key for SNS CloudWatch topic
21+
# This key is used to encrypt messages sent to the SNS topic for CloudWatch alarms.
22+
resource "aws_kms_key" "sns_cloudwatch" {
23+
# checkov:skip=CKV_AWS_7: key rotation not required for CloudWatch SNS topic's messages
24+
description = "KMS key for CloudWatch SNS topic"
25+
policy = data.aws_iam_policy_document.sns_cloudwatch.json
26+
}
27+
28+
# IAM policy document for the KMS key used by SNS CloudWatch topic
29+
data "aws_iam_policy_document" "sns_cloudwatch" {
30+
# checkov:skip=CKV_AWS_109: `resources = ["*"]` identifies the KMS key to which the key policy is attached
31+
# checkov:skip=CKV_AWS_111: `resources = ["*"]` identifies the KMS key to which the key policy is attached
32+
statement {
33+
effect = "Allow"
34+
resources = ["*"]
35+
actions = ["kms:*"]
36+
37+
principals {
38+
type = "AWS"
39+
identifiers = ["arn:aws:iam::${var.account_id}:root"]
40+
}
41+
}
42+
43+
statement {
44+
effect = "Allow"
45+
resources = ["*"]
46+
actions = [
47+
"kms:Decrypt",
48+
"kms:GenerateDataKey*",
49+
]
50+
51+
principals {
52+
type = "Service"
53+
identifiers = ["cloudwatch.amazonaws.com"]
54+
}
55+
}
1756
}

0 commit comments

Comments
 (0)