Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve suspicious env checks #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions dockerfile-security.rego
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,39 @@ secrets_env = [
"tkn"
]

deny[msg] {
input[i].Cmd == "env"
val := input[i].Value
contains(lower(val[_]), secrets_env[_])
msg = sprintf("Line %d: Potential secret in ENV key found: %s", [i, val])
deny[msg] {
dockerenvs := [val | input[i].Cmd == "env"; val := input[i].Value]
dockerenv := dockerenvs[_]
envvar := dockerenv[_]
lower(envvar) == secrets_env[_]
msg = sprintf("Line %d: Potential secret in ENV key found: %s", [i, envvar])
}

deny[msg] {
dockerenvs := [val | input[i].Cmd == "env"; val := input[i].Value]
dockerenv := dockerenvs[_]
envvar := dockerenv[_]
startswith(lower(envvar), secrets_env[_])
msg = sprintf("Line %d: Potential secret in ENV key found: %s", [i, envvar])
}

deny[msg] {
dockerenvs := [val | input[i].Cmd == "env"; val := input[i].Value]
dockerenv := dockerenvs[_]
envvar := dockerenv[_]
endswith(lower(envvar), secrets_env[_])
msg = sprintf("Line %d: Potential secret in ENV key found: %s", [i, envvar])
}

deny[msg] {
dockerenvs := [val | input[i].Cmd == "env"; val := input[i].Value]
dockerenv := dockerenvs[_]
envvar := dockerenv[_]
parts := regex.split("[ :=_-]", envvar)
part := parts[_]
lower(part) == secrets_env[_]
msg = sprintf("Line %d: Potential secret in ENV key found: %s", [i, envvar])

# Only use trusted base images
deny[msg] {
input[i].Cmd == "from"
Expand Down