-
Notifications
You must be signed in to change notification settings - Fork 4
VED-982: MNS Notification Complete #1309
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
Changes from all commits
328626a
605eb2f
7dff1b2
0be8254
295a1d5
b49dfe4
44eef2a
85f7fbc
7fa22f3
2a22b0b
dc892e1
1a5c2e1
26f4059
59f3ab7
ebcc051
005482c
e83b0fe
4bbfac8
de180d7
074e855
c4fcf75
56581e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| module "mns_publisher" { | ||
| source = "./modules/mns_publisher" | ||
|
|
||
| ddb_delta_stream_arn = aws_dynamodb_table.delta-dynamodb-table.stream_arn | ||
| dynamo_kms_encryption_key_arn = data.aws_kms_key.existing_dynamo_encryption_key.arn | ||
| enable_lambda_alarm = var.error_alarm_notifications_enabled | ||
| immunisation_account_id = var.immunisation_account_id | ||
| is_temp = local.is_temp | ||
| enable_mns_test_queue = var.mns_environment == "dev" | ||
| resource_scope = local.resource_scope | ||
| imms_base_path = strcontains(var.sub_environment, "pr-") ? "immunisation-fhir-api/FHIR/R4-${var.sub_environment}" : "immunisation-fhir-api/FHIR/R4" | ||
| lambda_kms_encryption_key_arn = data.aws_kms_key.existing_lambda_encryption_key.arn | ||
| mns_publisher_resource_name_prefix = "${local.resource_scope}-mns-outbound-events" | ||
| mns_test_notification_name_prefix = "${local.resource_scope}-mns-test-notification" | ||
| secrets_manager_policy_path = "${local.policy_path}/secret_manager.json" | ||
| account_id = data.aws_caller_identity.current.account_id | ||
| pds_environment = var.pds_environment | ||
| mns_environment = var.mns_environment | ||
|
|
||
| private_subnet_ids = local.private_subnet_ids | ||
| security_group_id = data.aws_security_group.existing_securitygroup.id | ||
|
|
||
| shared_dir_sha = local.shared_dir_sha | ||
| splunk_firehose_stream_name = module.splunk.firehose_stream_name | ||
|
|
||
| short_prefix = local.short_prefix | ||
|
|
||
| system_alarm_sns_topic_arn = data.aws_sns_topic.imms_system_alert_errors.arn | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| # IAM Role for EventBridge Pipe | ||
| resource "aws_iam_role" "mns_outbound_events_eb_pipe" { | ||
| name = "${var.mns_publisher_resource_name_prefix}-eventbridge-pipe-role" | ||
| assume_role_policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Action = "sts:AssumeRole" | ||
| Effect = "Allow" | ||
| Principal = { | ||
| Service = "pipes.amazonaws.com" | ||
| } | ||
| Condition = { | ||
| StringEquals = { | ||
| "aws:SourceAccount" = var.immunisation_account_id | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy" "mns_outbound_events_eb_pipe_source_policy" { | ||
| role = aws_iam_role.mns_outbound_events_eb_pipe.id | ||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| "Effect" : "Allow", | ||
| "Action" : [ | ||
| "dynamodb:DescribeStream", | ||
| "dynamodb:GetRecords", | ||
| "dynamodb:GetShardIterator", | ||
| "dynamodb:ListStreams" | ||
| ], | ||
| "Resource" : var.ddb_delta_stream_arn | ||
| }, | ||
| { | ||
| "Effect" : "Allow", | ||
| "Action" : [ | ||
| "kms:Decrypt", | ||
| "kms:GenerateDataKey" | ||
| ], | ||
| "Resource" : var.dynamo_kms_encryption_key_arn | ||
| }, | ||
| ] | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy" "mns_outbound_events_eb_pipe_target_policy" { | ||
| role = aws_iam_role.mns_outbound_events_eb_pipe.id | ||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Effect = "Allow" | ||
| Action = [ | ||
| "sqs:GetQueueAttributes", | ||
| "sqs:SendMessage", | ||
| ], | ||
| Resource = [ | ||
| aws_sqs_queue.mns_outbound_events.arn, | ||
| ] | ||
| }, | ||
| ] | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_iam_role_policy" "mns_outbound_events_eb_pipe_cw_log_policy" { | ||
| role = aws_iam_role.mns_outbound_events_eb_pipe.id | ||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Effect = "Allow" | ||
| Action = [ | ||
| "logs:CreateLogGroup", | ||
| "logs:CreateLogStream", | ||
| "logs:PutLogEvents" | ||
| ], | ||
| Resource = [ | ||
| "arn:aws:logs:${var.aws_region}:${var.immunisation_account_id}:log-group:/aws/vendedlogs/pipes/${var.mns_publisher_resource_name_prefix}-pipe-logs:*", | ||
| ] | ||
| }, | ||
| ] | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_cloudwatch_log_group" "mns_outbound_events_eb_pipe" { | ||
| name = "/aws/vendedlogs/pipes/${var.mns_publisher_resource_name_prefix}-pipe-logs" | ||
| retention_in_days = 30 | ||
| } | ||
|
|
||
| resource "aws_pipes_pipe" "mns_outbound_events" { | ||
| depends_on = [ | ||
| aws_iam_role_policy.mns_outbound_events_eb_pipe_source_policy, | ||
| aws_iam_role_policy.mns_outbound_events_eb_pipe_target_policy, | ||
| aws_iam_role_policy.mns_outbound_events_eb_pipe_cw_log_policy, | ||
| ] | ||
| name = "${var.mns_publisher_resource_name_prefix}-pipe" | ||
| role_arn = aws_iam_role.mns_outbound_events_eb_pipe.arn | ||
| source = var.ddb_delta_stream_arn | ||
| target = aws_sqs_queue.mns_outbound_events.arn | ||
|
|
||
| source_parameters { | ||
| dynamodb_stream_parameters { | ||
| starting_position = "TRIM_HORIZON" | ||
| } | ||
| } | ||
|
|
||
| log_configuration { | ||
| include_execution_data = ["ALL"] | ||
| level = "ERROR" | ||
| cloudwatch_logs_log_destination { | ||
| log_group_arn = aws_cloudwatch_log_group.mns_outbound_events_eb_pipe.arn | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| resource "aws_kms_key" "mns_outbound_events" { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we only have a single queue for outbound events shared by the blue and green sides (which I think is the correct thing to do), then we probably want a single KMS key for it as well, rather than a blue and a green key. The other KMS keys are defined in the account terraform and then referenced in the instance terraform using a data source. Should we be doing the same here?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will make it harder to lock down usage of the key to specific roles, as they won't exist yet. To discuss
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Matt, I have looked into this, it would be very hard to move the mns module kms into the account infra since those resource where not created at the account level. How do I attribute the policy permission to the right mns role and resources if I move the kms encryption to the account infra folder |
||
| description = "KMS key for encrypting MNS outbound immunisation events in SQS" | ||
| key_usage = "ENCRYPT_DECRYPT" | ||
| enable_key_rotation = true | ||
|
|
||
| policy = jsonencode({ | ||
| Version = "2012-10-17" | ||
| Statement = [ | ||
| { | ||
| Sid = "EnableRootPermissions" | ||
| Effect = "Allow" | ||
| Principal = { | ||
| AWS = "arn:aws:iam::${var.immunisation_account_id}:root" | ||
| }, | ||
| Action = [ | ||
| "kms:Create*", | ||
| "kms:Describe*", | ||
| "kms:Enable*", | ||
| "kms:List*", | ||
| "kms:Put*", | ||
| "kms:Update*", | ||
| "kms:Revoke*", | ||
| "kms:Disable*", | ||
| "kms:Get*", | ||
| "kms:Delete*", | ||
| "kms:ScheduleKeyDeletion", | ||
| "kms:CancelKeyDeletion", | ||
| "kms:GenerateDataKey*", | ||
| "kms:Decrypt", | ||
| "kms:Tag*" | ||
| ], | ||
| Resource = "*" | ||
| }, | ||
| { | ||
| Sid = "AllowSQSUseOfKey" | ||
| Effect = "Allow" | ||
| Principal = { | ||
| Service = "sqs.amazonaws.com" | ||
| } | ||
| Action = [ | ||
| "kms:GenerateDataKey", | ||
| "kms:Decrypt" | ||
| ] | ||
| Resource = "*" | ||
| Condition = { | ||
| StringEquals = { | ||
| "kms:EncryptionContext:aws:sqs:queue_arn" = [ | ||
| "arn:aws:sqs:${var.aws_region}:${var.immunisation_account_id}:${var.mns_publisher_resource_name_prefix}-queue", | ||
| "arn:aws:sqs:${var.aws_region}:${var.immunisation_account_id}:${var.mns_publisher_resource_name_prefix}-dead-letter-queue" | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| Sid = "AllowLambdaToDecrypt" | ||
| Effect = "Allow" | ||
| Principal = { | ||
| AWS = "arn:aws:iam::${var.immunisation_account_id}:role/${var.short_prefix}-mns-publisher-lambda-exec-role" | ||
| } | ||
| Action = [ | ||
| "kms:Decrypt", | ||
| "kms:GenerateDataKey" | ||
| ] | ||
| Resource = "*" | ||
| }, | ||
| { | ||
| Sid = "AllowEventBridgePipesUseOfKey" | ||
| Effect = "Allow" | ||
| Principal = { | ||
| AWS = "arn:aws:iam::${var.immunisation_account_id}:role/${var.mns_publisher_resource_name_prefix}-eventbridge-pipe-role" | ||
| } | ||
| Action = [ | ||
| "kms:GenerateDataKey", | ||
| "kms:Encrypt", | ||
| "kms:DescribeKey" | ||
|
|
||
| ] | ||
| Resource = "*" | ||
| } | ||
| ] | ||
| }) | ||
| } | ||
|
|
||
| resource "aws_kms_alias" "mns_outbound_events_key" { | ||
| name = "alias/${var.mns_publisher_resource_name_prefix}-key" | ||
| target_key_id = aws_kms_key.mns_outbound_events.id | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.