-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathaws_iam_role.bridgecrew_account_role.tf
113 lines (93 loc) · 2.97 KB
/
aws_iam_role.bridgecrew_account_role.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
resource "aws_iam_role" "bridgecrew_account_role" {
count = var.create_bridgecrew_connection ? 1 : 0
name = "${local.resource_name_prefix}-bridgecrewcwssarole"
assume_role_policy = data.aws_iam_policy_document.bridgecrew_account_assume_role[0].json
}
data "aws_iam_policy_document" "bridgecrew_account_assume_role" {
count = var.create_bridgecrew_connection ? 1 : 0
statement {
actions = [
"sts:AssumeRole",
]
effect = "Allow"
principals {
type = "AWS"
identifiers = ["arn:aws:iam::${var.bridgecrew_account_id}:root"]
}
condition {
test = "StringEquals"
variable = "sts:ExternalId"
values = [random_uuid.external_id.result]
}
}
}
data "aws_iam_policy_document" "bridgecrew_describe_policy_document" {
statement {
sid = "AllowDescribingResources"
effect = "Allow"
resources = ["*"]
actions = [
"dynamodb:ListTagsOfResource",
"Lambda:Get*",
"s3:ListBucket",
"sns:ListTagsForResource",
"ecr:GetLifecyclePolicy",
"es:ListTags",
"sns:GetSubscriptionAttributes"
]
}
}
resource "aws_iam_role_policy" "bridgecrew_describe_policy" {
count = var.create_bridgecrew_connection ? 1 : 0
policy = data.aws_iam_policy_document.bridgecrew_describe_policy_document.json
name = "BridgecrewDescribePolicy"
role = aws_iam_role.bridgecrew_account_role[0].id
}
resource "aws_iam_role_policy_attachment" "bridgecrew_security_audit" {
count = var.create_bridgecrew_connection ? 1 : 0
role = aws_iam_role.bridgecrew_account_role[0].name
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
}
resource "aws_iam_role_policy" "bridgecrew_cws_policy" {
count = var.create_bridgecrew_connection ? 1 : 0
name = "bridgecrew_cws_policy"
policy = data.aws_iam_policy_document.bridgecrew_cws_policy[0].json
role = aws_iam_role.bridgecrew_account_role[0].name
}
data "aws_iam_policy_document" "bridgecrew_cws_policy" {
count = var.create_bridgecrew_connection ? 1 : 0
statement {
sid = "ConsumeNotifications"
actions = [
"sqs:GetQueueAttributes",
"sqs:GetQueueUrl",
"sqs:DeleteMessage",
"sqs:ReceiveMessage",
]
effect = "Allow"
resources = [aws_sqs_queue.cloudtrail_queue[0].arn]
}
statement {
sid = "ListLogFiles"
actions = ["s3:ListBucket"]
effect = "Allow"
resources = ["arn:aws:s3:::${local.s3_bucket}/${local.log_file_prefix}AWSLogs/*"]
condition {
test = "StringLike"
variable = "s3:prefix"
values = ["${local.log_file_prefix}AWSLogs/*"]
}
}
statement {
sid = "ReadLogFiles"
actions = ["s3:Get*"]
effect = "Allow"
resources = ["arn:aws:s3:::${local.s3_bucket}/${local.log_file_prefix}AWSLogs/*"]
}
statement {
sid = "GetAccountAlias"
actions = ["iam:ListAccountAliases", "cloudwatch:GetMetricData", "sns:ListSubscriptions"]
effect = "Allow"
resources = ["*"]
}
}