Created
May 23, 2019 06:35
-
-
Save timja/88ac3531b273133dcd2aaf65ada71789 to your computer and use it in GitHub Desktop.
white-list-registry-policy
This file contains 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
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