Skip to content

Instantly share code, notes, and snippets.

@timja
Created May 23, 2019 06:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timja/88ac3531b273133dcd2aaf65ada71789 to your computer and use it in GitHub Desktop.
Save timja/88ac3531b273133dcd2aaf65ada71789 to your computer and use it in GitHub Desktop.
white-list-registry-policy
package admission
import data.k8s.matches
###############################################################################
#
# Policy : Container image name check if it matches the whitelisted patterns
# e.g. should be from an organization registry.
#
###############################################################################
deny[{
"id": "{{AzurePolicyID}}", # identifies type of violation
"resource": {
"kind": "pods", # identifies kind of resource
"namespace": namespace, # identifies namespace of resource
"name": name # identifies name of resource
},
"resolution": {"message": msg}, # provides human-readable message to display
}] {
matches[["pods", namespace, name, matched_pod]]
namespace != "kube-system"
namespace != "admin"
container = matched_pod.spec.containers[_]
not re_match("{{policyParameters.containerAllowedImagesRegex}}", container.image)
msg := sprintf("The operation was disallowed by policy ‘{{AzurePolicyID}}’. Error details: container image %q has not been whitelisted.", [container.image])
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment