Skip to content

Instantly share code, notes, and snippets.

@macox
Last active June 29, 2021 03:43
Show Gist options
  • Save macox/b2dc351f09c6664bc24544195561db56 to your computer and use it in GitHub Desktop.
Save macox/b2dc351f09c6664bc24544195561db56 to your computer and use it in GitHub Desktop.
OPA exceptions - data driven
dockerfile:
policies:
- name: warn_latest_tag
enabled: true
package main
import data.dockerfile
# read disabled policies from data file and set as exceptions
exception[disabledPolicies] {
disabledPolicies := [p | p = substring(dockerfile.policies[i].name, indexof(dockerfile.policies[i].name,"_") +1 ,-1); dockerfile.policies[i].enabled == false]
}
# images do not use latest tag
warn_latest_tag[msg] {
input[i].Cmd == "from"
split_image := split(input[i].Value[0], ":")
lower(split_image[1]) == "latest"
msg = sprintf("Do not use latest tag with image: %s", [input[i].Value[0]])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment