Skip to content

Commit 457c0f1

Browse files
authored
Merge branch 'main' into dependabot/pip/source/src/posting/requests-2.32.0
2 parents d8b226b + ba376c3 commit 457c0f1

File tree

13 files changed

+216
-58
lines changed

13 files changed

+216
-58
lines changed

.github/solutionid_validator.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
#set -e
3+
4+
echo "checking solution id $1"
5+
echo "grep -nr --exclude-dir='.github' "$1" ./.."
6+
result=$(grep -nr --exclude-dir='.github' "$1" ./..)
7+
if [ $? -eq 0 ]
8+
then
9+
echo "Solution ID $1 found\n"
10+
echo "$result"
11+
exit 0
12+
else
13+
echo "Solution ID $1 not found"
14+
exit 1
15+
fi
16+
17+
export result
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Workflows managed by aws-solutions-library-samples maintainers
2+
name: Maintainer Workflows
3+
on:
4+
# Triggers the workflow on push or pull request events but only for the "main" branch
5+
push:
6+
branches: [ "main" ]
7+
pull_request:
8+
branches: [ "main" ]
9+
types: [opened, reopened, edited]
10+
11+
jobs:
12+
CheckSolutionId:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Run solutionid validator
17+
run: |
18+
chmod u+x ./.github/solutionid_validator.sh
19+
./.github/solutionid_validator.sh ${{ vars.SOLUTIONID }}

CODEOWNERS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
CODEOWNERS @aws-solutions-library-samples/maintainers
2+
/.github/workflows/maintainer_workflows.yml @aws-solutions-library-samples/maintainers
3+
/.github/solutionid_validator.sh @aws-solutions-library-samples/maintainers

README.md

Lines changed: 45 additions & 49 deletions
Large diffs are not rendered by default.
253 KB
Loading

source/event-pipes/main.tf

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,28 @@ resource "aws_iam_role_policy" "target" {
5858
})
5959
}
6060

61+
resource "aws_iam_role_policy" "kms" {
62+
role = aws_iam_role.this.id
63+
policy = jsonencode({
64+
Version = "2012-10-17"
65+
Statement = [
66+
{
67+
Effect = "Allow"
68+
Action = [
69+
"kms:Encrypt",
70+
"kms:Decrypt",
71+
"kms:ReEncrypt*",
72+
"kms:GenerateDataKey*",
73+
"kms:DescribeKey"
74+
],
75+
Resource = [
76+
"*"
77+
]
78+
},
79+
]
80+
})
81+
}
82+
6183
resource "aws_iam_role_policy" "invoke_dedup" {
6284
role = aws_iam_role.this.id
6385
policy = jsonencode({
@@ -81,6 +103,7 @@ resource "aws_pipes_pipe" "this" {
81103
role_arn = aws_iam_role.this.arn
82104
source = var.stream_arn
83105
target = var.eb_arn
106+
kms_key_identifier = var.kms_key_id
84107
#target = "arn:aws:events:eu-west-1:926516876030:event-bus/default"
85108

86109
source_parameters {
@@ -146,4 +169,4 @@ resource "aws_pipes_pipe" "this" {
146169
EOT
147170
}
148171

149-
}
172+
}

source/event-pipes/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,10 @@ variable "target_event_source" {
2626
type = string
2727
description = "Source property of the event published to the target."
2828
default = null
29-
}
29+
}
30+
31+
variable "kms_key_id" {
32+
description = "Pass the ARN of the KMS Key Id for CMK"
33+
type = string
34+
default = null
35+
}

source/event_bridge/main.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ locals {
4545
}
4646
}
4747
resource "aws_cloudwatch_event_bus" "this" {
48-
name = var.event_bridge_name
48+
name = var.event_bridge_name
49+
kms_key_identifier = var.kms_key_id
4950
}
5051

5152
resource "aws_schemas_discoverer" "this" {
@@ -285,4 +286,4 @@ resource "aws_cloudwatch_event_target" "posted_queue" {
285286
dead_letter_config {
286287
arn = aws_sqs_queue.dlq.arn
287288
}
288-
}
289+
}

source/event_bridge/variables.tf

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,10 @@ variable "state_machine_arn" {
5050
type = string
5151
default = ""
5252
description = "Pass the State Machine arn"
53-
}
53+
}
54+
55+
variable "kms_key_id" {
56+
description = "Pass the ARN of the KMS Key Id for CMK"
57+
type = string
58+
default = null
59+
}

source/main.tf

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ provider "aws" {
33
}
44

55
provider "random" {}
6+
data "aws_caller_identity" "current" {}
67

78
locals {
89
definition_template = <<EOF
@@ -203,6 +204,10 @@ locals {
203204
}
204205
}
205206
EOF
207+
tags = {
208+
Name = "payments"
209+
Environment = "PROD"
210+
}
206211
}
207212

208213

@@ -225,6 +230,7 @@ module "dynamodb" {
225230
module "event_bridge" {
226231
source = "./event_bridge"
227232
event_bridge_name = var.event_bridge_name
233+
kms_key_id = module.kms.key_arn
228234
posting_queue_arn = module.posting_queue.arn
229235
posted_queue_arn = module.posted_queue.arn
230236
enrich_lambda_arn = module.enrich_lambda.arn
@@ -263,6 +269,7 @@ module "event-pipes" {
263269
stream_arn = module.dynamodb.stream_arn
264270
eb_arn = module.event_bridge.arn
265271
lambda_arn = module.dedup_lambda.arn
272+
kms_key_id = module.kms.key_arn
266273
target_event_detail_type = "TransactionAuthorized"
267274
target_event_source = "octank.payments.posting.visaIngest"
268275
}
@@ -369,6 +376,51 @@ module "fx_lambda" {
369376

370377
}
371378

379+
module "kms" {
380+
source = "terraform-aws-modules/kms/aws"
381+
version = "~> 1.0"
382+
description = "Securing SFN and EventBridge with KMS Keys"
383+
384+
# Aliases
385+
aliases = ["realtimepayments"]
386+
aliases_use_name_prefix = true
387+
388+
#key_owners = [data.aws_caller_identity.current.arn]
389+
policy = jsonencode({
390+
Version = "2012-10-17",
391+
Id = "default",
392+
Statement = [
393+
{
394+
Sid = "Enable IAM User Permissions"
395+
Effect = "Allow"
396+
Principal = {
397+
AWS = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:root"
398+
}
399+
Action = "kms:*"
400+
Resource = "*"
401+
},
402+
{
403+
Sid = "AllowSFNEventBridgeToGenerateDataKey",
404+
Effect = "Allow",
405+
Principal = {
406+
#Service = "events.amazonaws.com"
407+
Service = ["events.amazonaws.com", "pipes.amazonaws.com", "states.amazonaws.com"]
408+
},
409+
Action = [
410+
"kms:Encrypt",
411+
"kms:Decrypt",
412+
"kms:ReEncrypt*",
413+
"kms:GenerateDataKey*",
414+
"kms:DescribeKey"
415+
]
416+
Resource = "*"
417+
}
418+
]
419+
})
420+
421+
tags = local.tags
422+
}
423+
372424
module "sfn" {
373425
source = "./stepfunction"
374426

@@ -379,6 +431,12 @@ module "sfn" {
379431
definition = local.definition_template
380432
publish = true
381433

434+
encryption_configuration = {
435+
type = "CUSTOMER_MANAGED_KMS_KEY"
436+
kms_key_id = module.kms.key_arn
437+
kms_data_key_reuse_period_seconds = 600
438+
}
439+
382440
logging_configuration = {
383441
include_execution_data = true
384442
level = "ALL"
@@ -390,6 +448,10 @@ module "sfn" {
390448
xray = true
391449
}
392450

451+
kms = {
452+
kms = true
453+
}
454+
393455
stepfunction = {
394456
stepfunction = true
395457
}
@@ -460,7 +522,7 @@ resource "aws_cloudformation_stack" "guidance_deployment_metrics" {
460522
template_body = <<STACK
461523
{
462524
"AWSTemplateFormatVersion": "2010-09-09",
463-
"Description": "AWS Guidance ID (SO123456)",
525+
"Description": "Guidance for Building Payment Systems Using Event-Driven Architecture (SO9470)",
464526
"Resources": {
465527
"EmptyResource": {
466528
"Type": "AWS::CloudFormation::WaitConditionHandle"

0 commit comments

Comments
 (0)