-
Notifications
You must be signed in to change notification settings - Fork 6
/
jira_step_function.tf
131 lines (111 loc) · 4.17 KB
/
jira_step_function.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
locals {
sfn_jira_orchestrator_name = "securityhub-findings-manager-orchestrator"
}
# IAM role to be assumed by Step Function
module "jira_step_function_iam_role" {
count = var.jira_integration.enabled ? 1 : 0
source = "schubergphilis/mcaf-role/aws"
version = "~> 0.3.2"
name = var.jira_step_function_iam_role_name
create_policy = true
principal_identifiers = ["states.amazonaws.com"]
principal_type = "Service"
role_policy = data.aws_iam_policy_document.jira_step_function_iam_role[0].json
tags = var.tags
}
data "aws_iam_policy_document" "jira_step_function_iam_role" {
count = var.jira_integration.enabled ? 1 : 0
statement {
sid = "LambdaInvokeAccess"
actions = [
"lambda:InvokeFunction"
]
resources = [
module.findings_manager_events_lambda.arn,
module.jira_lambda[0].arn
]
}
statement {
sid = "CloudWatchLogDeliveryResourcePolicyAccess"
actions = [
"logs:CreateLogDelivery",
"logs:DeleteLogDelivery",
"logs:DescribeLogGroups",
"logs:DescribeResourcePolicies",
"logs:GetLogDelivery",
"logs:ListLogDeliveries",
"logs:PutResourcePolicy",
"logs:UpdateLogDelivery"
]
resources = [
"*"
]
}
statement {
sid = "TrustEventsToStoreLogEvent"
actions = [
"logs:CreateLogStream",
"logs:PutLogEvents"
]
resources = [
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:*"
]
}
}
resource "aws_cloudwatch_log_group" "log_group_jira_orchestrator_sfn" {
#checkov:skip=CKV_AWS_338:Ensure CloudWatch log groups retains logs for at least 1 year
count = var.jira_integration.enabled ? 1 : 0
name = "/aws/sfn/${local.sfn_jira_orchestrator_name}"
retention_in_days = var.jira_integration.step_function_settings.retention
kms_key_id = var.kms_key_arn
}
# Step Function to orchestrate findings manager lambda functions
resource "aws_sfn_state_machine" "jira_orchestrator" {
#checkov:skip=CKV_AWS_284:x-ray is not enabled due to the simplicity of this state machine and the costs involved with enabling this feature.
#checkov:skip=CKV_AWS_285:logging configuration is only supported for SFN type 'EXPRESS'.
count = var.jira_integration.enabled ? 1 : 0
name = local.sfn_jira_orchestrator_name
role_arn = module.jira_step_function_iam_role[0].arn
tags = var.tags
definition = templatefile("${path.module}/files/step-function-artifacts/${local.sfn_jira_orchestrator_name}.json.tpl", {
finding_severity_normalized = var.jira_integration.finding_severity_normalized_threshold
findings_manager_events_lambda = module.findings_manager_events_lambda.arn
jira_autoclose_enabled = var.jira_integration.autoclose_enabled
jira_lambda = module.jira_lambda[0].arn
})
logging_configuration {
include_execution_data = true
level = var.jira_integration.step_function_settings.log_level
log_destination = "${aws_cloudwatch_log_group.log_group_jira_orchestrator_sfn[0].arn}:*"
}
}
# IAM role to be assumed by EventBridge
module "jira_eventbridge_iam_role" {
count = var.jira_integration.enabled ? 1 : 0
source = "schubergphilis/mcaf-role/aws"
version = "~> 0.3.2"
name = var.jira_eventbridge_iam_role_name
create_policy = true
principal_identifiers = ["events.amazonaws.com"]
principal_type = "Service"
role_policy = data.aws_iam_policy_document.jira_eventbridge_iam_role[0].json
tags = var.tags
}
data "aws_iam_policy_document" "jira_eventbridge_iam_role" {
count = var.jira_integration.enabled ? 1 : 0
statement {
sid = "StepFunctionExecutionAccess"
actions = [
"states:StartExecution"
]
resources = [
aws_sfn_state_machine.jira_orchestrator[0].arn
]
}
}
resource "aws_cloudwatch_event_target" "jira_orchestrator" {
count = var.jira_integration.enabled ? 1 : 0
arn = aws_sfn_state_machine.jira_orchestrator[0].arn
role_arn = module.jira_eventbridge_iam_role[0].arn
rule = aws_cloudwatch_event_rule.securityhub_findings_events.name
}