Created
November 25, 2020 09:05
-
-
Save developer-guy/bd7bef0fc8c20586bdd24e5b8262e90a to your computer and use it in GitHub Desktop.
test Dockerfile with conftest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
Helpful links down below: