-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathpuppet_authz.rego
52 lines (40 loc) · 1.17 KB
/
puppet_authz.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
package puppet.authz
import rego.v1
# regal ignore:unresolved-import
import data.git
default allow := false
allow if not deny
deny if {
some resource_index, resource in input.puppet.catalog.resources
resource.type == "File"
startswith(resource.title, "/etc/app")
email := resource_author[resource_index]
not email in app_team
}
deny if {
some resource_index, resource in input.puppet.catalog.resources
resource.type == "File"
startswith(resource.title, "/etc/infra")
email := resource_author[resource_index]
not email in infra_team
}
resource_author[resource_index] := email if {
# For each "File" resource...
some resource_index, resource in input.puppet.catalog.resources
resource.type == "File"
# Compute the Puppet manifest filename relative to Git repository root...
prefix_length := count(source_root_dir)
local_file := substring(resource.file, prefix_length, -1)
# Lookup author for resource using the line number and Git blame data.
blame_entry := git[local_file]
email := blame_entry[resource.line].Author
}
app_team := {
}
infra_team := {
}
source_root_dir := "/code/"