Skip to content

Instantly share code, notes, and snippets.

@developer-guy
Created November 25, 2020 09:05
Show Gist options
  • Save developer-guy/bd7bef0fc8c20586bdd24e5b8262e90a to your computer and use it in GitHub Desktop.
Save developer-guy/bd7bef0fc8c20586bdd24e5b8262e90a to your computer and use it in GitHub Desktop.
test Dockerfile with conftest
#!/usr/bin/env bash
set -e
cat << EOF > Dockerfile
FROM kalilinux/kali-linux-docker:latest
ENTRYPOINT ["echo"]
EOF
cat <<< EOF > test.rego
package main
disallowed_tags := ["latest"]
disallowed_images := ["kalilinux/kali-linux-docker"]
deny[msg] {
input[i].Cmd == "from"
val := input[i].Value
tag := split(val[i], ":")[1]
contains(tag, disallowed_tags[_])
msg = sprintf("[%s] tag is not allowed", [tag])
}
deny[msg] {
input[i].Cmd == "from"
val := input[i].Value
image := split(val[i], ":")[0]
contains(image, disallowed_images[_])
msg = sprintf("[%s] image is not allowed", [image])
}
EOF
conftest test -p . Dockerfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment