-
Notifications
You must be signed in to change notification settings - Fork 50
/
iam.tf
101 lines (82 loc) · 2.22 KB
/
iam.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
data "aws_iam_policy_document" "metadata_svc_ecs_task_assume_role" {
statement {
effect = "Allow"
principals {
identifiers = [
"ecs-tasks.amazonaws.com"
]
type = "Service"
}
actions = [
"sts:AssumeRole"
]
}
}
resource "aws_iam_role" "metadata_ui_ecs_task_role" {
name = "${var.resource_prefix}ui-ecs-task${var.resource_suffix}"
# Read more about ECS' `task_role` and `execution_role` here https://stackoverflow.com/a/49947471
description = "This role is passed to AWS ECS' task definition as the `task_role`. This allows the running of the Metaflow Metadata Service to have the proper permissions to speak to other AWS resources."
assume_role_policy = data.aws_iam_policy_document.metadata_svc_ecs_task_assume_role.json
tags = var.standard_tags
}
data "aws_iam_policy_document" "s3_kms" {
statement {
effect = "Allow"
actions = [
"kms:Decrypt",
"kms:Encrypt",
"kms:GenerateDataKey"
]
resources = [
var.datastore_s3_bucket_kms_key_arn
]
}
}
data "aws_iam_policy_document" "custom_s3_batch" {
statement {
sid = "ObjectAccessMetadataService"
effect = "Allow"
actions = [
"s3:GetObject",
"s3:ListBucket"
]
resources = [
"${var.s3_bucket_arn}/*",
"${var.s3_bucket_arn}"
]
}
}
data "aws_iam_policy_document" "deny_presigned_batch" {
statement {
sid = "DenyPresignedBatch"
effect = "Deny"
actions = [
"s3:*"
]
resources = [
"*"
]
condition {
test = "StringNotEquals"
values = [
"REST-HEADER"
]
variable = "s3:authType"
}
}
}
resource "aws_iam_role_policy" "grant_s3_kms" {
name = "s3_kms"
role = aws_iam_role.metadata_ui_ecs_task_role.name
policy = data.aws_iam_policy_document.s3_kms.json
}
resource "aws_iam_role_policy" "grant_custom_s3_batch" {
name = "custom_s3"
role = aws_iam_role.metadata_ui_ecs_task_role.name
policy = data.aws_iam_policy_document.custom_s3_batch.json
}
resource "aws_iam_role_policy" "grant_deny_presigned_batch" {
name = "deny_presigned"
role = aws_iam_role.metadata_ui_ecs_task_role.name
policy = data.aws_iam_policy_document.deny_presigned_batch.json
}