-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresource.tf
200 lines (192 loc) · 6.12 KB
/
resource.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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
resource "aws_iam_role" "intents_operator_service_account_role" {
assume_role_policy = jsonencode(
{
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Principal" : {
"Federated" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${data.aws_iam_openid_connect_provider.cluster_oidc.url}"
},
"Action" : "sts:AssumeRoleWithWebIdentity",
"Condition" : {
"StringEquals" : {
"${data.aws_iam_openid_connect_provider.cluster_oidc.url}:sub" : "system:serviceaccount:${var.otterize_deploy_namespace}:intents-operator-controller-manager"
}
}
}
]
})
path = "/"
name = substr("${var.eks_cluster_name}-otterize-intents-operator", 0, 64)
tags = {
"otterize/system" = "true"
"otterize/clusterName" = var.eks_cluster_name
}
}
resource "aws_iam_role" "credentials_operator_service_account_role" {
assume_role_policy = jsonencode(
{
"Version" : "2012-10-17",
"Statement" : [
{
"Effect" : "Allow",
"Principal" : {
"Federated" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${data.aws_iam_openid_connect_provider.cluster_oidc.url}"
},
"Action" : "sts:AssumeRoleWithWebIdentity",
"Condition" : {
"StringEquals" : {
"${data.aws_iam_openid_connect_provider.cluster_oidc.url}:sub" : "system:serviceaccount:${var.otterize_deploy_namespace}:credentials-operator-controller-manager"
}
}
}
]
})
path = "/"
name = substr("${var.eks_cluster_name}-otterize-credentials-operator", 0, 64)
tags = {
"otterize/system" = "true"
"otterize/clusterName" = var.eks_cluster_name
}
}
resource "aws_iam_policy" "intents_operator_policy" {
name = "${var.eks_cluster_name}-intents-operator-access-policy"
policy = jsonencode(
{
Version = "2012-10-17",
Statement = [
{
Effect = "Allow"
Action = [
"ec2:DescribeInstances",
"eks:DescribeCluster",
"iam:AttachRolePolicy",
"iam:CreatePolicy",
"iam:CreatePolicyVersion",
"iam:DeletePolicy",
"iam:DeletePolicyVersion",
"iam:DetachRolePolicy",
"iam:GetPolicy",
"iam:GetRole",
"iam:ListAttachedRolePolicies",
"iam:ListEntitiesForPolicy",
"iam:ListPolicyVersions",
"iam:TagPolicy",
"iam:UntagPolicy"
]
Resource = "*"
},
{
Effect = "Deny"
Action = [
"iam:*"
]
Resource = [
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${var.eks_cluster_name}-otterize-intents-operator",
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${var.eks_cluster_name}-otterize-credentials-operator",
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/${var.eks_cluster_name}-limit-iam-permission-boundary"
]
},
{
Effect = "Deny"
Action = [
"iam:DeleteRolePermissionsBoundary"
]
Resource = "*"
}
]
})
}
resource "aws_iam_policy" "credentials_operator_policy" {
name = "${var.eks_cluster_name}-credentials-operator-access-policy"
// CF Property(Roles) = [
// aws_iam_role.credentials_operator_service_account_role.arn
// ]
policy = jsonencode(
{
Version = "2012-10-17",
Statement = [
{
Effect = "Allow"
Action = [
"ec2:DescribeInstances",
"eks:DescribeCluster",
"iam:DeletePolicy",
"iam:DeletePolicyVersion",
"iam:DeleteRole",
"iam:DetachRolePolicy",
"iam:GetPolicy",
"iam:GetRole",
"iam:ListAttachedRolePolicies",
"iam:ListEntitiesForPolicy",
"iam:ListPolicyVersions",
"iam:TagPolicy",
"iam:TagRole",
"iam:UntagPolicy",
"iam:UntagRole"
]
Resource = "*"
},
{
Effect = "Allow"
Action = [
"iam:CreateRole"
]
Resource = [
"*"
]
Condition = {
StringEquals = {
"iam:PermissionsBoundary" : "arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/${var.eks_cluster_name}-limit-iam-permission-boundary"
}
}
},
{
Effect = "Deny"
Action = [
"iam:*"
]
Resource = [
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${var.eks_cluster_name}-otterize-intents-operator",
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${var.eks_cluster_name}-otterize-credentials-operator",
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:policy/${var.eks_cluster_name}-limit-iam-permission-boundary"
]
},
{
Effect = "Deny"
Action = [
"iam:DeleteRolePermissionsBoundary"
]
Resource = "*"
}
]
})
}
resource "awscc_iam_managed_policy" "limit_iam_permission_boundary_policy" {
managed_policy_name = "${var.eks_cluster_name}-limit-iam-permission-boundary"
policy_document = jsonencode({
Version = "2012-10-17"
Statement = [
{
Effect = "Deny"
Action = "iam:*"
Resource = "*"
},
{
Effect = "Allow"
Action = "*"
Resource = "*"
}
]
}
)
}
resource "aws_iam_role_policy_attachment" "intents_operator_policy" {
role = aws_iam_role.intents_operator_service_account_role.name
policy_arn = aws_iam_policy.intents_operator_policy.arn
}
resource "aws_iam_role_policy_attachment" "credentials_operator_policy" {
role = aws_iam_role.credentials_operator_service_account_role.name
policy_arn = aws_iam_policy.credentials_operator_policy.arn
}