-
Notifications
You must be signed in to change notification settings - Fork 1
/
provisiondmarcimport_policy.tf
184 lines (171 loc) · 5.63 KB
/
provisiondmarcimport_policy.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# ------------------------------------------------------------------------------
# Create the IAM policy that allows provisioning of the dmarc-import
# infrastructure.
# ------------------------------------------------------------------------------
data "aws_iam_policy_document" "provisiondmarcimport" {
# Permissions necessary to create and manipulate Cognito resources
statement {
actions = [
"cognito-identity:CreateIdentityPool",
"cognito-identity:DeleteIdentityPool",
"cognito-identity:DescribeIdentityPool",
"cognito-identity:GetIdentityPoolRoles",
"cognito-identity:ListIdentityPools",
"cognito-identity:SetIdentityPoolRoles",
"cognito-identity:TagResource",
"cognito-identity:UntagResource",
"cognito-identity:UpdateIdentityPool",
"cognito-idp:AddCustomAttributes",
"cognito-idp:AdminCreateUser",
"cognito-idp:AdminDeleteUser",
"cognito-idp:AdminGetUser",
"cognito-idp:AdminUpdateUserAttributes",
"cognito-idp:CreateUserPool",
"cognito-idp:CreateUserPoolClient",
"cognito-idp:CreateUserPoolDomain",
"cognito-idp:DeleteUserPool",
"cognito-idp:DeleteUserPoolClient",
"cognito-idp:DeleteUserPoolDomain",
"cognito-idp:DescribeUserPool",
"cognito-idp:DescribeUserPoolClient",
"cognito-idp:DescribeUserPoolDomain",
"cognito-idp:GetUserPoolMfaConfig",
"cognito-idp:ListUserPoolClients",
"cognito-idp:ListUserPools",
"cognito-idp:SetUserPoolMfaConfig",
"cognito-idp:TagResource",
"cognito-idp:UntagResource",
"cognito-idp:UpdateUserPool",
"cognito-idp:UpdateUserPoolClient",
"cognito-idp:UpdateUserPoolDomain",
]
resources = [
"*"
]
}
# Permissions necessary to create and manipulate the Lambda function
statement {
actions = [
"lambda:*",
]
resources = [
"arn:aws:lambda:${var.aws_region}:${local.dns_account_id}:function:${var.lambda_function_name}",
]
}
# Permissions necessary to create and manipulate the temporary and
# permanent buckets
statement {
actions = [
"s3:*",
]
resources = [
"arn:aws:s3:::${var.permanent_bucket_name}",
"arn:aws:s3:::${var.temporary_bucket_name}",
]
}
# Permissions necessary to create and manipulate the queues
statement {
actions = [
"sqs:*",
]
resources = [
"arn:aws:sqs:${var.aws_region}:${local.dns_account_id}:${var.queue_name}",
"arn:aws:sqs:${var.aws_region}:${local.dns_account_id}:${var.queue_name}_dead_letter",
]
}
# Permissions necessary to create and manipulate the elasticsearch
# domain
statement {
actions = [
"es:*",
]
resources = [
"arn:aws:es:${var.aws_region}:${local.dns_account_id}:domain/${var.elasticsearch_domain_name}",
]
}
statement {
actions = [
# This permission should apply from the previous block, but for
# some reason it doesn't. The resource does not appear to be
# incorrect, but for some reason I can't apply tags unless I add
# it here.
"es:AddTags",
"es:CreateElasticsearchServiceRole",
"es:DeleteElasticsearchServiceRole",
"es:Describe*",
"es:List*"
]
resources = [
"*",
]
}
# Permissions necessary to create and manipulate the SES rule set.
# The SES actions only take wildcard resources, so we should only
# list the actions that we actually need.
statement {
actions = [
"ses:CreateReceiptRule",
"ses:CreateReceiptRuleSet",
"ses:DeleteReceiptRule",
"ses:DeleteReceiptRuleSet",
"ses:Describe*",
"ses:List*",
"ses:SetActiveReceiptRuleSet",
"ses:UpdateReceiptRule",
]
resources = [
"*"
]
}
# Permissions necessary to create and manipulate the CloudWatch log
# groups. Here I use specific resource ARNs where possible.
statement {
actions = [
"logs:CreateLogGroup",
"logs:DescribeLogGroups",
"logs:DescribeResourcePolicies",
]
resources = [
"*",
]
}
statement {
actions = [
"logs:DeleteLogGroup",
"logs:DeleteResourcePolicy",
"logs:DeleteRetentionPolicy",
"logs:ListTagsLogGroup",
"logs:PutResourcePolicy",
"logs:PutRetentionPolicy",
"logs:TagLogGroup",
"logs:UntagLogGroup",
]
resources = [
"arn:aws:logs:${var.aws_region}:${local.dns_account_id}:log-group:/aws/aes/domains/${var.elasticsearch_domain_name}/application-logs",
"arn:aws:logs:${var.aws_region}:${local.dns_account_id}:log-group:/aws/aes/domains/${var.elasticsearch_domain_name}/application-logs:*",
"arn:aws:logs:${var.aws_region}:${local.dns_account_id}:log-group:/aws/lambda/${var.lambda_function_name}",
"arn:aws:logs:${var.aws_region}:${local.dns_account_id}:log-group:/aws/lambda/${var.lambda_function_name}:*",
]
}
# Permissions necessary to create and manipulate the CloudWatch
# event rule that regularly kicks off the Lambda
statement {
actions = [
"events:*",
]
resources = [
"arn:aws:events:${var.aws_region}:${local.dns_account_id}:rule/ImportDmarcAggregateReports",
]
}
}
resource "aws_iam_policy" "provisiondmarcimport" {
provider = aws.dnsprovisionaccount
description = var.provisiondmarcimport_policy_description
name = var.provisiondmarcimport_policy_name
policy = data.aws_iam_policy_document.provisiondmarcimport.json
}
resource "aws_iam_role_policy_attachment" "provisiondmarcimport" {
provider = aws.dnsprovisionaccount
policy_arn = aws_iam_policy.provisiondmarcimport.arn
role = data.terraform_remote_state.dns.outputs.provisionaccount_role.name
}