-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathwho-when-where-access-restrictions.rego
More file actions
53 lines (40 loc) · 1.34 KB
/
who-when-where-access-restrictions.rego
File metadata and controls
53 lines (40 loc) · 1.34 KB
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
package spacelift
# This import is required for Rego v0 compatibility and can be removed if you are only using Rego v1.
import rego.v1
# In case things go wrong, we want you to be there.
#
# You know when things go wrong it's usually because someone did something.
# Like an infra deployment. Let's try to make sure they're in the office
# when doing so and restrict write access to business hours and office IP range.
# This policy is best combined with one that gives read access.
# Let's set some variables we can reference later
now := input.request.timestamp_ns
clock := time.clock([now, "America/Los_Angeles"])
weekend := {"Saturday", "Sunday"}
weekday := time.weekday(now)
ip := input.request.remote_ip
# Now let's define use those above variables to define the criteria
# for who can have write access, when, and from where (the ip)
#
# Allow write access from the Product team
write if {
"Product team" in input.session.teams
}
# Only allow access during weekdays
deny_write if {
weekend[weekday]
}
# Only allow access during 9-5 time zone
deny_write if {
clock[0] < 9
}
deny_write if {
clock[0] > 17
}
# Only allow access from the 12.34.56.0/24 CIDR
deny_write if {
not net.cidr_contains("12.34.56.0/24", ip)
}
# Learn more about sampling policy evaluations here:
# https://docs.spacelift.io/concepts/policy#sampling-policy-inputs
sample := true