Created
March 6, 2024 18:02
-
-
Save jmvbxx/1c0e74c8a100d116d8b1f053470071fa to your computer and use it in GitHub Desktop.
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
--- | |
apiVersion: templates.gatekeeper.sh/v1beta1 | |
kind: ConstraintTemplate | |
metadata: | |
name: k8sallowedrepos | |
spec: | |
crd: | |
spec: | |
names: | |
kind: K8sAllowedRepos | |
validation: | |
# Define schema for the parameters | |
openAPIV3Schema: | |
properties: | |
repos: | |
type: array | |
items: | |
type: string | |
targets: | |
- target: admission.k8s.gatekeeper.sh | |
rego: | | |
package k8sallowedrepos | |
violation[{"msg": msg, "details": {"rejected_repo": repo}}] { | |
container := input.review.object.spec.containers[_] | |
repo := container.image | |
not startswith(repo, input.parameters.repos[_]) | |
msg := sprintf("image repo is not in the allowed list: %v", [repo]) | |
} | |
--- | |
apiVersion: constraints.gatekeeper.sh/v1beta1 | |
kind: K8sAllowedRepos | |
metadata: | |
name: allowed-repos | |
spec: | |
match: | |
kinds: | |
- apiGroups: [""] | |
kinds: ["Pod"] | |
parameters: | |
repos: | |
- "ghcr.io" | |
- "docker.io/official" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment