-
Notifications
You must be signed in to change notification settings - Fork 8
/
iam.tf
72 lines (63 loc) · 2.27 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
data "aws_partition" "current" {}
data "aws_region" "current" {}
data "aws_caller_identity" "current" {}
data "aws_iam_policy_document" "snykbroker_secrets_policy_doc" {
statement {
actions = [
"kms:Decrypt",
"kms:Encrypt",
"kms:GenerateDataKey",
"kms:ReEncrypt*",
"ssm:GetParameters",
]
resources = flatten([
module.snykbroker_kms.key_arn,
[for t in aws_ssm_parameter.tokens : t.arn]
])
}
}
data "aws_iam_policy_document" "snykbroker_logs_policy_doc" {
statement {
sid = "logs.${data.aws_region.current.name}"
actions = [
"kms:Decrypt",
"kms:Encrypt",
"kms:GenerateDataKey",
"kms:ReEncrypt*",
"kms:DescribeKey"
]
principals {
identifiers = ["logs.${data.aws_region.current.name}.amazonaws.com"]
type = "Service"
}
resources = ["*"]
condition {
test = "ArnEquals"
values = ["arn:${data.aws_partition.current.partition}:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:*"]
variable = "kms:EncryptionContext:aws:logs:arn"
}
}
}
module "snykbroker_kms_iam_policy" {
source = "terraform-aws-modules/iam/aws//modules/iam-policy"
version = "3.5.0"
description = "SnykBroker KMS key usage policy"
name = "snykbroker_kms_policy"
path = "/"
policy = data.aws_iam_policy_document.snykbroker_secrets_policy_doc.json
}
# attach KMS policy permissions to Fargate execution role
resource "aws_iam_role_policy_attachment" "snykbroker_fargate_exe_kms" {
policy_arn = module.snykbroker_kms_iam_policy.arn
role = module.snykbroker_ecs_task_definition.execution_role_name
}
# attach EFS client readonly policy permissions to Fargate execution role
resource "aws_iam_role_policy_attachment" "snykbroker_fargate_exe_efs" {
policy_arn = "arn:aws:iam::aws:policy/AmazonElasticFileSystemClientReadOnlyAccess"
role = module.snykbroker_ecs_task_definition.execution_role_name
}
# attach EFS client readonly policy permissions for efs access point usage
resource "aws_iam_role_policy_attachment" "snykbroker_fargate_task_efs" {
policy_arn = "arn:aws:iam::aws:policy/AmazonElasticFileSystemClientReadOnlyAccess"
role = module.snykbroker_ecs_task_definition.task_role_name
}