-
Notifications
You must be signed in to change notification settings - Fork 27
/
security.rego
106 lines (93 loc) · 2.71 KB
/
security.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
package main
suspicious_env_keys = [
"passwd",
"password",
"secret",
"key",
"access",
"api_key",
"apikey",
"token",
]
pkg_update_commands = [
"apk upgrade",
"apt-get upgrade",
"dist-upgrade",
]
image_tag_list = [
"latest",
"LATEST",
]
# Looking for suspicious environment variable settings
deny[msg] {
dockerenvs := [val | input[i].Cmd == "env"; val := input[i].Value]
dockerenv := dockerenvs[_]
envvar := dockerenv[_]
lower(envvar) == suspicious_env_keys[_]
msg = sprintf("Potential secret in ENV found: %s", [envvar])
}
# Looking for suspicious environment variable settings
deny[msg] {
dockerenvs := [val | input[i].Cmd == "env"; val := input[i].Value]
dockerenv := dockerenvs[_]
envvar := dockerenv[_]
startswith(lower(envvar), suspicious_env_keys[_])
msg = sprintf("Potential secret in ENV found: %s", [envvar])
}
# Looking for suspicious environment variable settings
deny[msg] {
dockerenvs := [val | input[i].Cmd == "env"; val := input[i].Value]
dockerenv := dockerenvs[_]
envvar := dockerenv[_]
endswith(lower(envvar), suspicious_env_keys[_])
msg = sprintf("Potential secret in ENV found: %s", [envvar])
}
# Looking for suspicious environment variable settings
deny[msg] {
dockerenvs := [val | input[i].Cmd == "env"; val := input[i].Value]
dockerenv := dockerenvs[_]
envvar := dockerenv[_]
parts := regex.split("[ :=_-]", envvar)
part := parts[_]
lower(part) == suspicious_env_keys[_]
msg = sprintf("Potential secret in ENV found: %s", [envvar])
}
# Looking for latest docker image used
warn[msg] {
input[i].Cmd == "from"
val := split(input[i].Value[0], ":")
count(val) == 1
msg = sprintf("Do not use latest tag with image: %s", [val])
}
# Looking for latest docker image used
warn[msg] {
input[i].Cmd == "from"
val := split(input[i].Value[0], ":")
contains(val[1], image_tag_list[_])
msg = sprintf("Do not use latest tag with image: %s", [input[i].Value])
}
# Looking for apk upgrade command used in Dockerfile
deny[msg] {
input[i].Cmd == "run"
val := concat(" ", input[i].Value)
contains(val, pkg_update_commands[_])
msg = sprintf("Do not use upgrade commands: %s", [val])
}
# Looking for ADD command instead using COPY command
deny[msg] {
input[i].Cmd == "add"
val := concat(" ", input[i].Value)
msg = sprintf("Use COPY instead of ADD: %s", [val])
}
# sudo usage
deny[msg] {
input[i].Cmd == "run"
val := concat(" ", input[i].Value)
contains(lower(val), "sudo")
msg = sprintf("Avoid using 'sudo' command: %s", [val])
}
# # No Healthcheck usage
# deny[msg] {
# input[i].Cmd == "healthcheck"
# msg := "no healthcheck"
# }