Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions configuration/basic-control-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,12 @@ settings:
- 5
maxHighVulnerabilities:
- 10
memoryLimitMax: 4Gi
memoryLimitMin: 0.25Gi
memoryRequestMax: 4Gi
memoryRequestMin: 0.125Gi
# Match regolibrary's default-config-inputs.json: a minimum of 0 keeps only
# the "value is set" check, and an empty maximum means no upper bound.
memoryLimitMax: ""
memoryLimitMin: "0"
memoryRequestMax: ""
memoryRequestMin: "0"
publicRegistries:
- docker.io
- gcr.io
Expand Down
4 changes: 2 additions & 2 deletions controls/C-0004/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ spec:
variables.containers.all(container,
(!(!(has(container.resources)) || !(has(container.resources.requests)) || !(has(container.resources.requests.memory))) &&
quantity(string(params.settings.memoryRequestMin)).compareTo(quantity(string(container.resources.requests.memory))) != 1 &&
quantity(string(params.settings.memoryRequestMax)).compareTo(quantity(string(container.resources.requests.memory))) != -1 ))
(params.settings.memoryRequestMax == "" || quantity(string(params.settings.memoryRequestMax)).compareTo(quantity(string(container.resources.requests.memory))) != -1) ))
messageExpression: 'object.kind + "/" + object.metadata.name + " contains container/s with memory request not set or they are not in the specified range! (see more at https://kubescape.io/docs/controls/c-0004/)"'

- expression: >
variables.containers.all(container,
(!(!(has(container.resources)) || !(has(container.resources.limits)) || !(has(container.resources.limits.memory))) &&
quantity(string(params.settings.memoryLimitMin)).compareTo(quantity(string(container.resources.limits.memory))) != 1 &&
quantity(string(params.settings.memoryLimitMax)).compareTo(quantity(string(container.resources.limits.memory))) != -1 ))
(params.settings.memoryLimitMax == "" || quantity(string(params.settings.memoryLimitMax)).compareTo(quantity(string(container.resources.limits.memory))) != -1) ))
messageExpression: 'object.kind + "/" + object.metadata.name + " contains container/s with memory limit not set or they are not in the specified range! (see more at https://kubescape.io/docs/controls/c-0004/)"'
22 changes: 22 additions & 0 deletions controls/C-0004/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,30 @@
"name": "Pod with container having memory request and limits set and values out of the range is blocked",
"template": "pod.yaml",
"expected": "fail",
"param_template": "memory-range-control-configuration.yaml",
"field_change_list": [
"spec.containers.[0].resources.requests.memory=127Mi",
"spec.containers.[0].resources.limits.memory=1Gi"
]
},
{
"name": "Pod with container having a 64Mi memory request and a 128Mi limit is allowed with the default unbounded range",
"template": "pod.yaml",
"expected": "pass",
"field_change_list": [
"spec.containers.[0].resources.requests.memory=64Mi",
"spec.containers.[0].resources.limits.memory=128Mi"
]
},
{
"name": "Deployment with container having memory request and limit above the former maximum is allowed with the default unbounded range",
"template": "deployment.yaml",
"expected": "pass",
"field_change_list": [
"spec.template.spec.containers.[0].resources.requests.memory=5Gi",
"spec.template.spec.containers.[0].resources.limits.memory=6Gi"
]
},
{
"name": "Deployment with container having memory-request and limits not set is blocked",
"template": "deployment.yaml",
Expand Down Expand Up @@ -169,6 +188,7 @@
"name": "Pod with container having memory request and limits set and init container having memory request and limits set and value not in the limit is blocked",
"template": "pod-with-init-container.yaml",
"expected": "fail",
"param_template": "memory-range-control-configuration.yaml",
"field_change_list": [
"spec.containers.[0].image=registry.k8s.io/e2e-test-images/busybox:1.36.1-1",
"spec.containers.[0].resources.requests.memory=256Mi",
Expand All @@ -182,6 +202,7 @@
"name": "Pod resized below the memory request minimum is blocked",
"template": "pod.yaml",
"expected": "fail",
"param_template": "memory-range-control-configuration.yaml",
"field_change_list": [
"spec.containers.[0].resources.requests.memory=256Mi",
"spec.containers.[0].resources.limits.memory=512Mi"
Expand All @@ -196,6 +217,7 @@
"name": "Pod resized above the memory limit maximum is blocked",
"template": "pod.yaml",
"expected": "fail",
"param_template": "memory-range-control-configuration.yaml",
"field_change_list": [
"spec.containers.[0].resources.requests.memory=256Mi",
"spec.containers.[0].resources.limits.memory=512Mi"
Expand Down
2 changes: 1 addition & 1 deletion controls/C-0269/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ spec:
variables.containers.all(container,
(!(!(has(container.resources)) || !(has(container.resources.requests)) || !(has(container.resources.requests.memory))) &&
quantity(string(params.settings.memoryRequestMin)).compareTo(quantity(string(container.resources.requests.memory))) != 1 &&
quantity(string(params.settings.memoryRequestMax)).compareTo(quantity(string(container.resources.requests.memory))) != -1 ))
(params.settings.memoryRequestMax == "" || quantity(string(params.settings.memoryRequestMax)).compareTo(quantity(string(container.resources.requests.memory))) != -1) ))
messageExpression: 'object.kind + "/" + object.metadata.name + " contains container/s with memory request not set or they are not in the specified range! (see more at https://kubescape.io/docs/controls/c-0269/)"'
11 changes: 11 additions & 0 deletions controls/C-0269/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@
"name": "Pod with container having memory request set and value not in the limit is blocked",
"template": "pod.yaml",
"expected": "fail",
"param_template": "memory-range-control-configuration.yaml",
"field_change_list": [
"spec.containers.[0].resources.requests.memory=4.1Gi"
]
},
{
"name": "Pod with container having a 64Mi memory request is allowed with the default unbounded range",
"template": "pod.yaml",
"expected": "pass",
"field_change_list": [
"spec.containers.[0].resources.requests.memory=64Mi"
]
},
{
"name": "Deployment with container having memory request not set is blocked",
"template": "deployment.yaml",
Expand Down Expand Up @@ -137,6 +146,7 @@
"name": "Pod with container having memory request set and init container having memory request set and value not in the limit is blocked",
"template": "pod-with-init-container.yaml",
"expected": "fail",
"param_template": "memory-range-control-configuration.yaml",
"field_change_list": [
"spec.containers.[0].image=registry.k8s.io/e2e-test-images/busybox:1.36.1-1",
"spec.containers.[0].resources.requests.memory=256Mi",
Expand All @@ -148,6 +158,7 @@
"name": "Pod resized below the memory request minimum is blocked",
"template": "pod.yaml",
"expected": "fail",
"param_template": "memory-range-control-configuration.yaml",
"field_change_list": [
"spec.containers.[0].resources.requests.memory=256Mi"
],
Expand Down
2 changes: 1 addition & 1 deletion controls/C-0271/policy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ spec:
variables.containers.all(container,
(!(!(has(container.resources)) || !(has(container.resources.limits)) || !(has(container.resources.limits.memory))) &&
quantity(string(params.settings.memoryLimitMin)).compareTo(quantity(string(container.resources.limits.memory))) != 1 &&
quantity(string(params.settings.memoryLimitMax)).compareTo(quantity(string(container.resources.limits.memory))) != -1 ))
(params.settings.memoryLimitMax == "" || quantity(string(params.settings.memoryLimitMax)).compareTo(quantity(string(container.resources.limits.memory))) != -1) ))
messageExpression: 'object.kind + "/" + object.metadata.name + " contains container/s with memory limit not set or they are not in the specified range! (see more at https://kubescape.io/docs/controls/c-0271/)"'
12 changes: 12 additions & 0 deletions controls/C-0271/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@
"name": "Pod with container having memory limits set and value not in the limit is blocked",
"template": "pod.yaml",
"expected": "fail",
"param_template": "memory-range-control-configuration.yaml",
"field_change_list": [
"spec.containers.[0].resources.limits.memory=4.1Gi"
]
},
{
"name": "Pod with container having a 128Mi memory limit is allowed with the default unbounded range",
"template": "pod.yaml",
"expected": "pass",
"field_change_list": [
"spec.containers.[0].resources.limits.memory=128Mi"
]
},
{
"name": "Deployment with container having memory limits not set is blocked",
"template": "deployment.yaml",
Expand Down Expand Up @@ -137,6 +146,7 @@
"name": "Pod with container having memory limits set and init container having memory limits set and value not in the limit is blocked",
"template": "pod-with-init-container.yaml",
"expected": "fail",
"param_template": "memory-range-control-configuration.yaml",
"field_change_list": [
"spec.containers.[0].image=registry.k8s.io/e2e-test-images/busybox:1.36.1-1",
"spec.containers.[0].resources.limits.memory=512Mi",
Expand All @@ -148,6 +158,7 @@
"name": "Pod resized below the memory limit minimum is blocked",
"template": "pod.yaml",
"expected": "fail",
"param_template": "memory-range-control-configuration.yaml",
"field_change_list": [
"spec.containers.[0].resources.requests.memory=64Mi",
"spec.containers.[0].resources.limits.memory=512Mi"
Expand All @@ -162,6 +173,7 @@
"name": "Pod resized above the memory limit maximum is blocked",
"template": "pod.yaml",
"expected": "fail",
"param_template": "memory-range-control-configuration.yaml",
"field_change_list": [
"spec.containers.[0].resources.requests.memory=64Mi",
"spec.containers.[0].resources.limits.memory=512Mi"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

If any of the above checks fail, the resource is denied from being deployed in the cluster.

The shipped parameters set the minimum to `0` and leave the maximum empty, which matches the Rego defaults. An empty maximum means no upper bound, so by default only the presence of each field is enforced. Set the minimum and maximum in the `ControlConfiguration` to enforce a range.

The minimum values apply to init containers too, so a small init container that runs one short command still needs a memory request of at least [memoryRequestMin](https://kubescape.io/docs/frameworks-and-controls/configuring-controls/#memory_request_min) and a memory limit of at least [memoryLimitMin](https://kubescape.io/docs/frameworks-and-controls/configuring-controls/#memory_limit_min).

Ephemeral containers (added with `kubectl debug`) are not checked, because the Kubernetes API does not allow `resources` on ephemeral containers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

If any of the above checks fail, the resource is denied from being deployed in the cluster.

The shipped parameters set the minimum to `0` and leave the maximum empty, which matches the Rego defaults. An empty maximum means no upper bound, so by default only the presence of the field is enforced. Set the minimum and maximum in the `ControlConfiguration` to enforce a range.

The minimum values apply to init containers too, so a small init container that runs one short command still needs a memory request of at least [memoryRequestMin](https://kubescape.io/docs/frameworks-and-controls/configuring-controls/#memory_request_min).

Ephemeral containers (added with `kubectl debug`) are not checked, because the Kubernetes API does not allow `resources` on ephemeral containers.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

If any of the above checks fail, the resource is denied from being deployed in the cluster.

The shipped parameters set the minimum to `0` and leave the maximum empty, which matches the Rego defaults. An empty maximum means no upper bound, so by default only the presence of the field is enforced. Set the minimum and maximum in the `ControlConfiguration` to enforce a range.

The minimum values apply to init containers too, so a small init container that runs one short command still needs a memory limit of at least [memoryLimitMin](https://kubescape.io/docs/frameworks-and-controls/configuring-controls/#memory_limit_min).

Ephemeral containers (added with `kubectl debug`) are not checked, because the Kubernetes API does not allow `resources` on ephemeral containers.
Expand Down
10 changes: 6 additions & 4 deletions test-resources/default-control-configuration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,12 @@ settings:
- 5
maxHighVulnerabilities:
- 10
memoryLimitMax: 4Gi
memoryLimitMin: 0.25Gi
memoryRequestMax: 4Gi
memoryRequestMin: 0.125Gi
# Match regolibrary's default-config-inputs.json: a minimum of 0 keeps only
# the "value is set" check, and an empty maximum means no upper bound.
memoryLimitMax: ""
memoryLimitMin: "0"
memoryRequestMax: ""
memoryRequestMin: "0"
publicRegistries:
- docker.io
- gcr.io
Expand Down
137 changes: 137 additions & 0 deletions test-resources/memory-range-control-configuration.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
apiVersion: "kubescape.io/v1"
kind: ControlConfiguration
metadata:
name: placeholder
settings:
hardenedSandboxRuntimeClasses:
- gvisor
cpuLimitMax: 5
cpuLimitMin: 1
cpuRequestMax: 5
cpuRequestMin: 0.1
imageRepositoryAllowList:
- gcr.io
- docker.io # Not in Kubescape's initial configuration but added to test as this is an edge case.
insecureCapabilities:
- SETPCAP
- NET_ADMIN
- NET_RAW
- SYS_MODULE
- SYS_RAWIO
- SYS_PTRACE
- SYS_ADMIN
- SYS_BOOT
- MAC_OVERRIDE
- MAC_ADMIN
- PERFMON
- ALL
- BPF
k8sRecommendedLabels:
- app.kubernetes.io/name
- app.kubernetes.io/instance
- app.kubernetes.io/version
- app.kubernetes.io/component
- app.kubernetes.io/part-of
- app.kubernetes.io/managed-by
- app.kubernetes.io/created-by
listOfDangerousArtifacts:
- bin/bash
- sbin/sh
- bin/ksh
- bin/tcsh
- bin/zsh
- usr/bin/scsh
- bin/csh
- bin/busybox
- usr/bin/busybox
maxCriticalVulnerabilities:
- 5
maxHighVulnerabilities:
- 10
# Bounded values for tests that exercise the range checks. The shipped
# defaults in default-control-configuration.yaml are unbounded.
memoryLimitMax: 4Gi
memoryLimitMin: 0.25Gi
memoryRequestMax: 4Gi
memoryRequestMin: 0.125Gi
publicRegistries:
- docker.io
- gcr.io
- quay.io
- registry.hub.docker.com
recommendedLabels:
- app
- tier
- phase
- version
- owner
- env
sensitiveInterfaces:
- nifi
- argo-server
- weave-scope-app
- kubeflow
- kubernetes-dashboard
- jenkins
- prometheus-deployment
sensitiveKeyNames:
- aws_access_key_id
- aws_secret_access_key
- azure_batchai_storage_account
- azure_batchai_storage_key
- azure_batch_account
- azure_batch_key
- secret
- key
- password
- pwd
- token
- jwt
- bearer
- credential
sensitiveKeyNamesAllowed:
- top-secret-allowed
sensitiveValues:
- BEGIN \w+ PRIVATE KEY
- PRIVATE KEY
- eyJhbGciO
- JWT
- Bearer
- _key_
- _secret_
sensitiveValuesAllowed:
- test-value
- encrypted-password
servicesNames:
- nifi-service
- argo-server
- minio
- postgres
- workflow-controller-metrics
- weave-scope-app
- kubernetes-dashboard
untrustedRegistries:
- docker.io
- gcr.io
- quay.io
- registry.hub.docker.com
wlKnownNames:
- coredns
- kube-proxy
- event-exporter-gke
- kube-dns
- 17-default-backend
- metrics-server
- ca-audit
- ca-dashboard-aggregator
- ca-notification-server
- ca-ocimage
- ca-oracle
- ca-posture
- ca-rbac
- ca-vuln-scan
- ca-webhook
- ca-websocket
- clair-clair

cloudProvider: aks
Loading