-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiam_policies.tf
103 lines (87 loc) · 3 KB
/
iam_policies.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
#Creating policy to allow the K8S SA (SA_NAME) to assume to assume IAM role
data "aws_iam_policy_document" "assume_role_vault_server_eks" {
statement {
effect = "Allow"
actions = ["sts:AssumeRoleWithWebIdentity"]
principals {
type = "Federated"
identifiers = [local.provider_arn]
}
condition {
test = "StringEquals"
variable = "${local.issuer_hostpath}:sub"
values = ["system:serviceaccount:${var.sa_namespace}:${var.sa_name}"]
}
}
}
data "aws_iam_policy_document" "vault_kms_unseal" {
statement {
sid = "vaultPolicyDocumentKMSUnseal"
effect = "Allow"
resources = [aws_kms_key.vault_server_kms_key.arn]
actions = [
"kms:Encrypt",
"kms:Decrypt",
"kms:DescribeKey",
]
}
}
# Creating a managed policy for KMS auto unseal feature
resource "aws_iam_policy" "vault_kms_auto_unseal_policy" {
name = "vault-policy-kms-unseal-${random_pet.env.id}"
path = "/"
description = "Policy that provides the needed KMS permission for Vault server's auto unseal feature"
policy = data.aws_iam_policy_document.vault_kms_unseal.json
}
# Policy document (only in TF) that gives permissions to use AWS auth method
data "aws_iam_policy_document" "vault_aws_auth" {
statement {
sid = "vaultPolicyDocumentVaultAWSAuth"
effect = "Allow"
resources = ["*"]
actions = [
"ec2:DescribeInstances",
"iam:GetInstanceProfile",
"iam:GetUser",
"iam:GetRole"
]
}
}
# Creating a managed policy for AWS auth method
resource "aws_iam_policy" "vault_aws_auth_policy" {
name = "vault-policy-vault-aws-auth-${random_pet.env.id}"
path = "/"
description = "Policy that provides the needed permissions for the Vault server to verify users via the AWS authentication method (iam type)"
policy = data.aws_iam_policy_document.vault_aws_auth.json
}
# Policy document (only in TF) that gives needed permissions for AWS secrets engine
data "aws_iam_policy_document" "vault_aws_secret" {
statement {
sid = "vaultPolicyDocumentVaultAWSSecret"
effect = "Allow"
resources = ["arn:aws:iam::${data.aws_caller_identity.current.id}:user/vault-*"]
actions = [
"iam:AttachUserPolicy",
"iam:CreateAccessKey",
"iam:CreateUser",
"iam:DeleteAccessKey",
"iam:DeleteUser",
"iam:DeleteUserPolicy",
"iam:DetachUserPolicy",
"iam:ListAccessKeys",
"iam:ListAttachedUserPolicies",
"iam:ListGroupsForUser",
"iam:ListUserPolicies",
"iam:PutUserPolicy",
"iam:AddUserToGroup",
"iam:RemoveUserFromGroup"
]
}
}
# Creating a managed policy for AWS secrets engine
resource "aws_iam_policy" "vault_aws_secret_policy" {
name = "vault-policy-vault-aws-secret-${random_pet.env.id}"
path = "/"
description = "Policy that provides the needed permissions for the Vault server's aws secrets engine to function properly"
policy = data.aws_iam_policy_document.vault_aws_secret.json
}