-
Notifications
You must be signed in to change notification settings - Fork 12
/
7_generate_dynamic_policy.sh
executable file
·122 lines (99 loc) · 3.24 KB
/
7_generate_dynamic_policy.sh
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
. env.sh
echo
cyan "Running: $0: Generating a dynamic policy"
UM_ACCESS=$(vault auth list -format=json | jq -r '.["ldap-um/"].accessor')
MO_ACCESS=$(vault auth list -format=json | jq -r '.["ldap-mo/"].accessor')
green "Generating a dynamic policy under policies/kv-user-template-policy.hcl. This needs to be done because the ACL templates need to know the local LDAP auth method accessors"
cat > policies/kv-user-template-policy.hcl << EOF
# Allow full access to the current version of the kv-blog
path "kv-blog/data/{{identity.entity.aliases.${UM_ACCESS}.name}}/*"
{
capabilities = ["create", "read", "update", "delete", "list"]
}
path "kv-blog/data/{{identity.entity.aliases.${UM_ACCESS}.name}}"
{
capabilities = ["create", "read", "update", "delete", "list"]
}
# Allow deletion of any kv-blog version
path "kv-blog/delete/{{identity.entity.aliases.${UM_ACCESS}.name}}/*"
{
capabilities = ["update"]
}
path "kv-blog/delete/{{identity.entity.aliases.${UM_ACCESS}.name}}"
{
capabilities = ["update"]
}
# Allow un-deletion of any kv-blog version
path "kv-blog/undelete/{{identity.entity.aliases.${UM_ACCESS}.name}}/*"
{
capabilities = ["update"]
}
path "kv-blog/undelete/{{identity.entity.aliases.${UM_ACCESS}.name}}"
{
capabilities = ["update"]
}
# Allow destroy of any kv-blog version
path "kv-blog/destroy/{{identity.entity.aliases.${UM_ACCESS}.name}}/*"
{
capabilities = ["update"]
}
path "kv-blog/destroy/{{identity.entity.aliases.${UM_ACCESS}.name}}"
{
capabilities = ["update"]
}
# Allow list and view of metadata and to delete all versions and metadata for a key
path "kv-blog/metadata/{{identity.entity.aliases.${UM_ACCESS}.name}}/*"
{
capabilities = ["list", "read", "delete"]
}
path "kv-blog/metadata/{{identity.entity.aliases.${UM_ACCESS}.name}}"
{
capabilities = ["list", "read", "delete"]
}
# Allow full access to the current version of the kv-blog
path "kv-blog/data/{{identity.entity.aliases.${MO_ACCESS}.name}}/*"
{
capabilities = ["create", "read", "update", "delete", "list"]
}
path "kv-blog/data/{{identity.entity.aliases.${MO_ACCESS}.name}}"
{
capabilities = ["create", "read", "update", "delete", "list"]
}
# Allow deletion of any kv-blog version
path "kv-blog/delete/{{identity.entity.aliases.${MO_ACCESS}.name}}/*"
{
capabilities = ["update"]
}
path "kv-blog/delete/{{identity.entity.aliases.${MO_ACCESS}.name}}"
{
capabilities = ["update"]
}
# Allow un-deletion of any kv-blog version
path "kv-blog/undelete/{{identity.entity.aliases.${MO_ACCESS}.name}}/*"
{
capabilities = ["update"]
}
path "kv-blog/undelete/{{identity.entity.aliases.${MO_ACCESS}.name}}"
{
capabilities = ["update"]
}
# Allow destroy of any kv-blog version
path "kv-blog/destroy/{{identity.entity.aliases.${MO_ACCESS}.name}}/*"
{
capabilities = ["update"]
}
path "kv-blog/destroy/{{identity.entity.aliases.${MO_ACCESS}.name}}"
{
capabilities = ["update"]
}
# Allow list and view of metadata and to delete all versions and metadata for a key
path "kv-blog/metadata/{{identity.entity.aliases.${MO_ACCESS}.name}}/*"
{
capabilities = ["list", "read", "delete"]
}
path "kv-blog/metadata/{{identity.entity.aliases.${MO_ACCESS}.name}}"
{
capabilities = ["list", "read", "delete"]
}
EOF
pe "vault policy write kv-user-template policies/kv-user-template-policy.hcl"