Skip to content

Commit 02f9263

Browse files
author
Dieter Bocklandt
authored
feat(policy): migrate policies to Rego v1 syntax (#127)
1 parent 6eb0263 commit 02f9263

File tree

162 files changed

+3341
-4797
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

162 files changed

+3341
-4797
lines changed

.github/actions/action.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ branding:
55
color: "green"
66
runs:
77
using: 'docker'
8-
image: 'docker://openpolicyagent/conftest:v0.24.0'
8+
image: 'docker://openpolicyagent/conftest:v0.60.0'
99
args:
1010
- verify

policy/docker/deny_curl_bashing.rego

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package docker
22

3+
import rego.v1
4+
35
import data.docker
46
import data.lib as l
57

68
check06 := "DOCKER_06"
79

8-
exception[rules] {
10+
exception contains rules if {
911
make_exception(check06)
1012
rules = ["curl_bashing"]
1113
}
1214

1315
# DENY(DOCKER_06): Avoid curl bashing, use a trusted source and verify hash
14-
deny_curl_bashing[msg] {
16+
deny_curl_bashing contains msg if {
1517
docker.runs[run]
1618
regex.match("(curl|wget).*[|>].*", lower(run))
1719
msg = sprintf("%s: Avoid curl/wget bashing (%s). More info: %s", [check06, run, l.get_url(check06)])

policy/docker/deny_curl_bashing_test.rego

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package docker
22

3+
import rego.v1
4+
35
import data.testing as t
46

5-
test_avoid_curl_bashing {
7+
test_avoid_curl_bashing if {
68
curl_bash := [
79
{
810
"Cmd": "run",
@@ -23,16 +25,14 @@ test_avoid_curl_bashing {
2325
t.error_count(deny_curl_bashing, 2) with input as curl_bash
2426
}
2527

26-
test_allow_curl_without_pipe {
27-
curl_bash := [
28-
{
29-
"Cmd": "run",
30-
"Flags": [],
31-
"JSON": false,
32-
"SubCmd": "",
33-
"Value": ["curl", "https://some-url.com"],
34-
},
35-
]
28+
test_allow_curl_without_pipe if {
29+
curl_bash := [{
30+
"Cmd": "run",
31+
"Flags": [],
32+
"JSON": false,
33+
"SubCmd": "",
34+
"Value": ["curl", "https://some-url.com"],
35+
}]
3636

3737
t.no_errors(deny_curl_bashing) with input as curl_bash
3838
}
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package docker
22

3+
import rego.v1
4+
35
import data.docker
46
import data.lib as l
57

68
check01 := "DOCKER_01"
79

8-
exception[rules] {
10+
exception contains rules if {
911
make_exception(check01)
1012
rules = ["no_user"]
1113
}
1214

1315
# DENY(DOCKER_01): if USER is not specified in the Dockerfile it will use root implicitly
14-
deny_no_user[msg] {
16+
deny_no_user contains msg if {
1517
not is_user
1618
msg = sprintf("%s: Please specify a USER, root is not permitted. More info: %s", [check01, l.get_url(check01)])
1719
}

policy/docker/deny_not_specifying_user_test.rego

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package docker
22

3+
import rego.v1
4+
35
import data.testing as t
46

5-
test_deny_no_user {
6-
input := [
7+
test_deny_no_user if {
8+
inp := [
79
{
810
"Cmd": "from",
911
"Flags": [],
@@ -20,5 +22,5 @@ test_deny_no_user {
2022
},
2123
]
2224

23-
t.error_count(deny_no_user, 1) with input as input
25+
t.error_count(deny_no_user, 1) with input as inp
2426
}

policy/docker/deny_port_out_of_range.rego

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
package docker
22

3+
import rego.v1
4+
35
import data.docker
46
import data.lib as l
57

68
check07 := "DOCKER_07"
79

8-
exception[rules] {
10+
exception contains rules if {
911
make_exception(check07)
1012
rules = ["port_out_of_range"]
1113
}
1214

1315
# DENY(DOCKER_07): Port number out of range - https://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers
14-
port_in_range {
16+
port_in_range if {
1517
docker.exposes[expose]
16-
all([to_number(expose) > 0, to_number(expose) < 65535])
18+
to_number(expose) > 0
19+
to_number(expose) < 65535
1720
}
1821

19-
deny_port_out_of_range[msg] {
22+
deny_port_out_of_range contains msg if {
2023
docker.exposes[expose]
2124
not port_in_range
2225
msg = sprintf("%s: Port number out of range (0-65535). More info: %s", [check07, l.get_url(check07)])

policy/docker/deny_port_out_of_range_test.rego

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package docker
22

3+
import rego.v1
4+
35
import data.testing as t
46

5-
test_port_out_of_range {
6-
input := [
7+
test_port_out_of_range if {
8+
inp := [
79
{
810
"Cmd": "from",
911
"Flags": [],
@@ -20,5 +22,5 @@ test_port_out_of_range {
2022
},
2123
]
2224

23-
t.error_count(deny_port_out_of_range, 1) with input as input
25+
t.error_count(deny_port_out_of_range, 1) with input as inp
2426
}

policy/docker/deny_sudo_usage.rego

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package docker
22

3+
import rego.v1
4+
35
import data.docker
46
import data.lib as l
57

68
check04 := "DOCKER_04"
79

8-
exception[rules] {
10+
exception contains rules if {
911
make_exception(check04)
1012
rules = ["sudo_usage"]
1113
}
1214

1315
# DENY(DOCKER_04): Do not allow usage of sudo
14-
deny_sudo_usage[msg] {
16+
deny_sudo_usage contains msg if {
1517
docker.runs[run]
1618
contains(lower(run), "sudo")
1719
msg = sprintf("%s: Avoid using 'sudo' command (%s). More info: %s", [check04, run, l.get_url(check04)])

policy/docker/deny_sudo_usage_test.rego

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package docker
22

3+
import rego.v1
4+
35
import data.testing as t
46

5-
test_deny_sudo_usage {
6-
input := [
7+
test_deny_sudo_usage if {
8+
inp := [
79
{
810
"Cmd": "from",
911
"Flags": [],
@@ -20,5 +22,5 @@ test_deny_sudo_usage {
2022
},
2123
]
2224

23-
t.error_count(deny_sudo_usage, 1) with input as input
25+
t.error_count(deny_sudo_usage, 1) with input as inp
2426
}

policy/docker/deny_using_add.rego

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package docker
22

3+
import rego.v1
4+
35
import data.docker
46
import data.lib as l
57

68
check05 := "DOCKER_05"
79

8-
exception[rules] {
10+
exception contains rules if {
911
make_exception(check05)
1012
rules = ["using_add"]
1113
}
1214

1315
# DENY(DOCKER_05): Use ADD instead of COPY - https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#add-or-copy
14-
deny_using_add[msg] {
16+
deny_using_add contains msg if {
1517
docker.adds[add]
1618
msg = sprintf("%s: Use COPY instead of ADD. More info: %s", [check05, l.get_url(check05)])
1719
}

0 commit comments

Comments
 (0)