Skip to content

Commit

Permalink
Merge pull request #81 from XenitAB/ephemeral_container
Browse files Browse the repository at this point in the history
Latest gatekeeper lib with ephemeral containers and removal of duplicate lib
  • Loading branch information
phillebaba authored Jun 27, 2022
2 parents da4ca8c + 98d576e commit 5145203
Show file tree
Hide file tree
Showing 34 changed files with 190 additions and 302 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/opa.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v1
- name: Run OPA tests
uses: b4b4r07/action-opa@master
- name: Checkout
uses: actions/checkout@v1
- name: Run OPA tests
uses: b4b4r07/action-opa@master
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,6 @@ k8spodpriorityclass:
kinds:
- apiGroups: [""]
kinds: ["Pod"]
k8srequiredannotations:
match:
kinds:
- apiGroups: [""]
kinds: [""]
parameters:
message: "Resource does not contain the required annotation"
annotations: []
k8srequireingressclass:
match:
kinds:
Expand Down Expand Up @@ -84,6 +76,11 @@ k8scontainerratios:
kinds:
- apiGroups: [""]
kinds: ["Pod"]
k8srequiredresources:
match:
kinds:
- apiGroups: [""]
kinds: ["Pod"]
k8sdisallowanonymous:
match:
kinds:
Expand Down
18 changes: 0 additions & 18 deletions charts/gatekeeper-library-constraints/tests/basic_test.yaml

This file was deleted.

30 changes: 0 additions & 30 deletions charts/gatekeeper-library-constraints/tests/match_test.yaml

This file was deleted.

19 changes: 0 additions & 19 deletions charts/gatekeeper-library-constraints/tests/name_prefix_test.yaml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ spec:
not any(satisfied)
msg := sprintf("initContainer <%v> has an invalid image repo <%v>, allowed repos are %v", [container.name, container.image, input.parameters.repos])
}
violation[{"msg": msg}] {
container := input.review.object.spec.ephemeralContainers[_]
satisfied := [good | repo = input.parameters.repos[_] ; good = startswith(container.image, repo)]
not any(satisfied)
msg := sprintf("ephemeralContainer <%v> has an invalid image repo <%v>, allowed repos are %v", [container.name, container.image, input.parameters.repos])
}
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ spec:
general_violation[{"msg": msg, "field": "initContainers"}]
}
# Ephemeral containers not checked as it is not possible to set field.
general_violation[{"msg": msg, "field": field}] {
container := input.review.object.spec[field][_]
not is_exempt(container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ spec:
general_violation[{"msg": msg, "field": "initContainers"}]
}
# Ephemeral containers not checked as it is not possible to set field.
general_violation[{"msg": msg, "field": field}] {
container := input.review.object.spec[field][_]
not is_exempt(container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ spec:
general_violation[{"msg": msg, "field": "initContainers"}]
}
# Ephemeral containers not checked as it is not possible to set field.
general_violation[{"msg": msg, "field": field}] {
container := input.review.object.spec[field][_]
not is_exempt(container)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ spec:
input_containers[c] {
c := input.review.object.spec.initContainers[_]
}
input_containers[c] {
c := input.review.object.spec.ephemeralContainers[_]
}
libs:
- |
package lib.exempt_container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ spec:
not all(satisfied)
msg := sprintf("initContainer <%v> uses an image without a digest <%v>", [container.name, container.image])
}
violation[{"msg": msg}] {
container := input.review.object.spec.ephemeralContainers[_]
not is_exempt(container)
satisfied := [re_match("@[a-z0-9]+([+._-][a-z0-9]+)*:[a-zA-Z0-9=_-]+", container.image)]
not all(satisfied)
msg := sprintf("ephemeralContainer <%v> uses an image without a digest <%v>", [container.name, container.image])
}
libs:
- |
package lib.exempt_container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ spec:
input_containers[c] {
c := input.review.object.spec.initContainers[_]
}
input_containers[c] {
c := input.review.object.spec.ephemeralContainers[_]
}
libs:
- |
package lib.exempt_container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ spec:
input_containers[c] {
c := input.review.object.spec.initContainers[_]
}
input_containers[c] {
c := input.review.object.spec.ephemeralContainers[_]
}
# has_field returns whether an object has a field
has_field(object, field) = true {
object[field]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ spec:
input_containers[c] {
c := input.review.object.spec.initContainers[_]
}
input_containers[c] {
c := input.review.object.spec.ephemeralContainers[_]
}
get_annotation_for(container, metadata) = out {
out = metadata.annotations[sprintf("container.apparmor.security.beta.kubernetes.io/%v", [container.name])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ spec:
c := input.review.object.spec.initContainers[_]
}
# Ephemeral containers not checked as it is not possible to set field.
has_key(x, k) {
_ = x[k]
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ spec:
}
violation[{"msg": msg}] {
container := input.review.object.spec.ephemeralContainers[_]
not is_exempt(container)
has_disallowed_capabilities(container)
msg := sprintf("ephemeral container <%v> has a disallowed capability. Allowed capabilities are %v", [container.name, get_default(input.parameters, "allowedCapabilities", "NONE")])
}
violation[{"msg": msg}] {
container := input.review.object.spec.ephemeralContainers[_]
not is_exempt(container)
missing_drop_capabilities(container)
msg := sprintf("ephemeral container <%v> is not dropping all required capabilities. Container must drop all of %v or \"ALL\"", [container.name, input.parameters.requiredDropCapabilities])
}
has_disallowed_capabilities(container) {
allowed := {c | c := lower(input.parameters.allowedCapabilities[_])}
not allowed["*"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,7 @@ spec:
input_containers[c] {
c := input.review.object.spec.initContainers[_]
}
input_containers[c] {
c := input.review.object.spec.ephemeralContainers[_]
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ spec:
c := input.review.object.spec.initContainers[_]
not is_exempt(c)
}
input_containers[c] {
c := input.review.object.spec.ephemeralContainers[_]
not is_exempt(c)
}
libs:
- |
package lib.exempt_container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ spec:
input_containers[c] {
c := input.review.object.spec.initContainers[_]
}
input_containers[c] {
c := input.review.object.spec.ephemeralContainers[_]
}
libs:
- |
package lib.exempt_container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ spec:
c := input.review.object.spec.initContainers[_]
c.securityContext.procMount
}
input_containers[c] {
c := input.review.object.spec.ephemeralContainers[_]
c.securityContext.procMount
}
get_allowed_proc_mount(arg) = out {
not arg.parameters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ spec:
input_containers[c] {
c := input.review.object.spec.initContainers[_]
}
input_containers[c] {
c := input.review.object.spec.ephemeralContainers[_]
}
# has_field returns whether an object has a field
has_field(object, field) = true {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ spec:
input_containers[container.name] = container {
container := input.review.object.spec.initContainers[_]
}
input_containers[container.name] = container {
container := input.review.object.spec.ephemeralContainers[_]
}
libs:
- |
package lib.exempt_container
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ spec:
c := input.review.object.spec.initContainers[_]
has_field(c.securityContext, "seLinuxOptions")
}
input_security_context[c] {
c := input.review.object.spec.ephemeralContainers[_]
has_field(c.securityContext, "seLinuxOptions")
}
# has_field returns whether an object has a field
has_field(object, field) = true {
Expand Down
Loading

0 comments on commit 5145203

Please sign in to comment.