-
-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathpolicies.tf
91 lines (76 loc) · 2.25 KB
/
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
data "aws_caller_identity" "current" {
count = var.aws_account_id == "" ? 1 : 0
}
data "aws_partition" "current" {}
locals {
aws_account_id = try(data.aws_caller_identity.current[0].account_id, var.aws_account_id)
partition = data.aws_partition.current.partition
}
data "aws_iam_policy_document" "iam_self_management" {
statement {
sid = "AllowSelfManagement"
effect = "Allow"
actions = [
"iam:ChangePassword",
"iam:CreateAccessKey",
"iam:CreateLoginProfile",
"iam:CreateVirtualMFADevice",
"iam:DeleteAccessKey",
"iam:DeleteLoginProfile",
"iam:DeleteVirtualMFADevice",
"iam:EnableMFADevice",
"iam:GenerateCredentialReport",
"iam:GenerateServiceLastAccessedDetails",
"iam:Get*",
"iam:List*",
"iam:ResyncMFADevice",
"iam:UpdateAccessKey",
"iam:UpdateLoginProfile",
"iam:UpdateUser",
"iam:UploadSigningCertificate",
"iam:UploadSSHPublicKey",
"iam:TagUser",
"iam:ListUserTags",
"iam:UntagUser",
]
# Allow for both users with "path" and without it
resources = [
"arn:${local.partition}:iam::${local.aws_account_id}:user/*/$${aws:username}",
"arn:${local.partition}:iam::${local.aws_account_id}:user/$${aws:username}",
"arn:${local.partition}:iam::${local.aws_account_id}:mfa/$${aws:username}",
]
}
statement {
sid = "AllowIAMReadOnly"
actions = [
"iam:Get*",
"iam:List*",
]
resources = ["*"]
effect = "Allow"
}
# Allow to deactivate MFA only when logging in with MFA
statement {
sid = "AllowDeactivateMFADevice"
effect = "Allow"
actions = [
"iam:DeactivateMFADevice",
]
# Allow for both users with "path" and without it
resources = [
"arn:${local.partition}:iam::${local.aws_account_id}:user/*/$${aws:username}",
"arn:${local.partition}:iam::${local.aws_account_id}:user/$${aws:username}",
"arn:${local.partition}:iam::${local.aws_account_id}:mfa/$${aws:username}",
]
condition {
test = "Bool"
variable = "aws:MultiFactorAuthPresent"
values = ["true"]
}
condition {
test = "NumericLessThan"
variable = "aws:MultiFactorAuthAge"
values = ["3600"]
}
}
}