-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhdfs.rego
260 lines (237 loc) · 7.98 KB
/
hdfs.rego
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
package hdfs
import rego.v1
default allow := false
default matches_identity(identity) := false
# HDFS authorizer
allow if {
some acl in acls
matches_identity(acl.identity)
matches_resource(input.path, acl.resource)
action_sufficient_for_operation(acl.action, input.operationName)
}
# Identity mentions the (long) userName or shortUsername explicitly
matches_identity(identity) if {
identity in {
concat("", ["user:", input.callerUgi.userName]),
concat("", ["shortUser:", input.callerUgi.shortUserName])
}
}
# Identity regex matches the (long) userName
matches_identity(identity) if {
match_entire(identity, concat("", ["userRegex:", input.callerUgi.userName]))
}
# Identity regex matches the shortUsername
matches_identity(identity) if {
match_entire(identity, concat("", ["shortUserRegex:", input.callerUgi.shortUserName]))
}
# Identity mentions group the user is part of (by looking up using the (long) userName)
matches_identity(identity) if {
some group in groups_for_user[input.callerUgi.userName]
identity == concat("", ["group:", group])
}
# Identity regex matches group the user is part of (by looking up using the (long) userName)
matches_identity(identity) if {
some group in groups_for_user[input.callerUgi.userName]
match_entire(identity, concat("", ["groupRegex:", group]))
}
# Identity mentions group the user is part of (by looking up using the shortUserName)
matches_identity(identity) if {
some group in groups_for_short_user_name[input.callerUgi.shortUserName]
identity == concat("", ["group:", group])
}
# Identity regex matches group the user is part of (by looking up using the shortUserName)
matches_identity(identity) if {
some group in groups_for_short_user_name[input.callerUgi.shortUserName]
match_entire(identity, concat("", ["groupRegex:", group]))
}
# Resource mentions the file explicitly
matches_resource(file, resource) if {
resource == concat("", ["hdfs:file:", file])
}
# Resource mentions the directory explicitly
matches_resource(file, resource) if {
trim_suffix(resource, "/") == concat("", ["hdfs:dir:", file])
}
# Resource mentions a folder higher up the tree, which will will grant access recursively
matches_resource(file, resource) if {
startswith(resource, "hdfs:dir:/")
# directories need to have a trailing slash
endswith(resource, "/")
startswith(file, trim_prefix(resource, "hdfs:dir:"))
}
action_sufficient_for_operation(action, operation) if {
action_hierarchy[action][_] == action_for_operation[operation]
}
action_hierarchy := {
"full": ["full", "rw", "ro"],
"rw": ["rw", "ro"],
"ro": ["ro"],
}
match_entire(pattern, value) if {
# Add the anchors ^ and $
pattern_with_anchors := concat("", ["^", pattern, "$"])
regex.match(pattern_with_anchors, value)
}
# To get a (hopefully complete) list of actions run "ack 'String operationName = '" in the hadoop source code
action_for_operation := {
# The "rename" operation will be actually called on both - the source and the target location.
# Because of this you need to have rw permissions on the source and target file - which is desired
"abandonBlock": "rw",
"addCacheDirective": "rw",
"addCachePool": "full",
"addErasureCodingPolicies": "full",
"allowSnapshot": "full",
"append": "rw",
"cancelDelegationToken": "ro",
"checkAccess": "ro",
"clearQuota": "full",
"clearSpaceQuota": "full",
"completeFile": "rw",
"computeSnapshotDiff": "full",
"concat": "rw",
"contentSummary": "ro",
"create": "rw",
"createEncryptionZone": "full",
"createSnapshot": "full",
"createSymlink": "rw",
"delete": "rw",
"deleteSnapshot": "full",
"disableErasureCodingPolicy": "full",
"disallowSnapshot": "full",
"enableErasureCodingPolicy": "full",
"finalizeRollingUpgrade": "full",
"fsck": "full",
"fsckGetBlockLocations": "full",
"fsync": "rw",
"gcDeletedSnapshot": "full",
"getAclStatus": "ro",
"getAdditionalBlock": "ro",
"getAdditionalDatanode": "ro",
"getDelegationToken": "ro",
"getECTopologyResultForPolicies": "ro",
"getErasureCodingCodecs": "ro",
"getErasureCodingPolicies": "ro",
"getErasureCodingPolicy": "ro",
"getEZForPath": "ro",
"getfileinfo": "ro",
"getPreferredBlockSize": "ro",
"getStoragePolicy": "ro",
"getXAttrs": "ro",
"isFileClosed": "ro",
"listCacheDirectives": "ro",
"listCachePools": "ro",
"listCorruptFileBlocks": "ro",
"listEncryptionZones": "ro",
"listOpenFiles": "ro",
"listReencryptionStatus": "ro",
"ListSnapshot": "ro", # Yeah, this really starts with a capital letter
"listSnapshottableDirectory": "ro",
"listStatus": "ro",
"listXAttrs": "ro",
"mkdirs": "rw",
"modifyAclEntries": "full",
"modifyCacheDirective": "rw",
"modifyCachePool": "full",
"open": "ro",
"queryRollingUpgrade": "ro",
"quotaUsage": "ro",
"recoverLease": "full",
"reencryptEncryptionZone": "full",
"removeAcl": "full",
"removeAclEntries": "full",
"removeCacheDirective": "rw",
"removeCachePool": "full",
"removeDefaultAcl": "full",
"removeErasureCodingPolicy": "full",
"removeXAttr": "rw",
"rename": "rw",
"renameSnapshot": "full",
"renewDelegationToken": "ro",
"satisfyStoragePolicy": "full",
"setAcl": "full",
"setErasureCodingPolicy": "full",
"setOwner": "full",
"setPermission": "full",
"setQuota": "full",
"setReplication": "full",
"setSpaceQuota": "full",
"setStoragePolicy": "full",
"setTimes": "rw",
"setXAttr": "rw",
"startRollingUpgrade": "full",
"truncate": "rw",
"unsetErasureCodingPolicy": "full",
"unsetStoragePolicy": "full",
}
# Actions I think are only relevant for the whole filesystem, and not specific to a file or directory
admin_actions := {
"checkRestoreFailedStorage": "ro",
"datanodeReport": "ro",
"disableRestoreFailedStorage": "full",
"enableRestoreFailedStorage": "full",
"finalizeUpgrade": "rw",
"getDatanodeStorageReport": "ro",
"metaSave": "ro",
"monitorHealth": "ro",
"refreshNodes": "rw",
"rollEditLog": "rw",
"saveNamespace": "full",
"setBalancerBandwidth": "rw",
"slowDataNodesReport": "ro",
"transitionToActive": "full",
"transitionToObserver": "full",
"transitionToStandby": "full",
}
groups_for_user := {
"admin/test-hdfs-permissions.default.svc.cluster.local@CLUSTER.LOCAL": ["admins"],
"alice/test-hdfs-permissions.default.svc.cluster.local@CLUSTER.LOCAL": ["developers"],
"bob/test-hdfs-permissions.default.svc.cluster.local@CLUSTER.LOCAL": []
}
groups_for_short_user_name := {}
acls := [
{
"identity": "group:admins",
"action": "full",
"resource": "hdfs:dir:/",
},
{
"identity": "groupRegex:(developers)",
"action": "rw",
"resource": "hdfs:dir:/developers/",
},
{
"identity": "group:developers",
"action": "ro",
"resource": "hdfs:dir:/developers-ro/",
},
{
"identity": "user:alice/test-hdfs-permissions.default.svc.cluster.local@CLUSTER.LOCAL",
"action": "rw",
"resource": "hdfs:dir:/alice/",
},
{
"identity": `userRegex:bob/.+\.default\.svc\.cluster\.local@CLUSTER\.LOCAL`,
"action": "rw",
"resource": "hdfs:dir:/bob/",
},
{
"identity": "user:bob/test-hdfs-permissions.default.svc.cluster.local@CLUSTER.LOCAL",
"action": "ro",
"resource": "hdfs:dir:/developers/",
},
{
"identity": "user:bob/test-hdfs-permissions.default.svc.cluster.local@CLUSTER.LOCAL",
"action": "rw",
"resource": "hdfs:file:/developers/file-from-bob-via-user",
},
{
"identity": "shortUser:bob",
"action": "rw",
"resource": "hdfs:file:/developers/file-from-bob-via-short-user",
},
{
"identity": "shortUserRegex:(bob|bobby)",
"action": "rw",
"resource": "hdfs:file:/developers/file-from-bob-via-short-user-regex",
},
]