-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #73 from jouve/bump
bump images
- Loading branch information
Showing
14 changed files
with
293 additions
and
145 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
apiVersion: kustomize.config.k8s.io/v1beta1 | ||
kind: Kustomization | ||
resources: | ||
- github.com/open-policy-agent/gatekeeper-library/library?ref=52cb14a2ef7a9d06908e1543524f283290b8b4f4 | ||
- github.com/open-policy-agent/gatekeeper-library/library?ref=a569ff9f7d99db6a8c177bc6311a998f769ce2f8 |
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
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
57 changes: 57 additions & 0 deletions
57
charts/gatekeeper-library/templates/k8sallowedreposv2.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
apiVersion: templates.gatekeeper.sh/v1 | ||
kind: ConstraintTemplate | ||
metadata: | ||
annotations: | ||
description: 'This policy enforces that container images must begin with a string from a specified list. The updated version, K8sAllowedReposv2, introduces support for exact match and glob-like syntax to enhance security: 1. Exact Match: By default, if the * character is not specified, the policy strictly checks for an exact match of the full registry, repository, and/or the image name. 2. Glob-like Syntax: Adding * at the end of a prefix allows prefix-based matching (e.g., registry.example.com/project/*). Only the * wildcard at the end of a string is supported. 3. Security Note: To avoid bypasses scenarios, ensure prefixes include a trailing / where appropriate (e.g., registry.example.com/project/*).' | ||
metadata.gatekeeper.sh/title: Allowed Images | ||
metadata.gatekeeper.sh/version: 1.0.0 | ||
name: k8sallowedreposv2 | ||
spec: | ||
crd: | ||
spec: | ||
names: | ||
kind: K8sAllowedReposv2 | ||
validation: | ||
openAPIV3Schema: | ||
properties: | ||
allowedImages: | ||
description: A list of allowed container image prefixes. Supports exact matches and prefixes ending with '*'. | ||
items: | ||
type: string | ||
type: array | ||
type: object | ||
targets: | ||
- rego: | | ||
package k8sallowedreposv2 | ||
violation[{"msg": msg}] { | ||
container := input.review.object.spec.containers[_] | ||
not image_matches(container.image, input.parameters.allowedImages) | ||
msg := sprintf("container <%v> has an invalid image <%v>, allowed images are %v", [container.name, container.image, input.parameters.allowedImages]) | ||
} | ||
violation[{"msg": msg}] { | ||
container := input.review.object.spec.initContainers[_] | ||
not image_matches(container.image, input.parameters.allowedImages) | ||
msg := sprintf("initContainer <%v> has an invalid image <%v>, allowed images are %v", [container.name, container.image, input.parameters.allowedImages]) | ||
} | ||
violation[{"msg": msg}] { | ||
container := input.review.object.spec.ephemeralContainers[_] | ||
not image_matches(container.image, input.parameters.allowedImages) | ||
msg := sprintf("ephemeralContainer <%v> has an invalid image <%v>, allowed images are %v", [container.name, container.image, input.parameters.allowedImages]) | ||
} | ||
image_matches(image, images) { | ||
i_image := images[_] # Iterate through all images in the allowed list | ||
not endswith(i_image, "*") # Check for exact match if the image does not end with * | ||
i_image == image | ||
} | ||
image_matches(image, images) { | ||
i_image := images[_] # Iterate through all images in the allowed list | ||
endswith(i_image, "*") # Check for prefix match if the image ends with * | ||
prefix := trim_suffix(i_image, "*") | ||
startswith(image, prefix) | ||
} | ||
target: admission.k8s.gatekeeper.sh |
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
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
Oops, something went wrong.