Skip to content

Commit f72ca16

Browse files
authored
Add a CustomRule checking for VM overcommitGuestOverhead (#846)
1 parent 5449030 commit f72ca16

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apiVersion: compliance.openshift.io/v1alpha1
2+
kind: CustomRule
3+
metadata:
4+
name: kubevirt-no-vms-overcommitting-guest-memory
5+
namespace: openshift-compliance
6+
spec:
7+
title: "VMs Must Not Overcommit Guests Memory"
8+
id: kubevirt_no_vms_overcommitting_guest_memory
9+
description: |-
10+
The overcommitGuestOverhead configuration option enables the request for
11+
additional virtual machine management memory inside the virt-launcher pod.
12+
The overcommit feature is used to increase virtual machine density on the
13+
node, as long as the virtual machine doesn’t request all the memory that it
14+
would need if fully loaded. However, if the VM were to use all of the
15+
memory it could, this would lead to the OpenShift Scheduler killing the
16+
workload.
17+
failureReason: |-
18+
The '.spec.template.spec.domain.recources.overcommitGuestOverhead' field exists and is
19+
set to "true" in the 'VirtualMachineInstance' resource, allowing VMs to
20+
overcommit KubeVirt's memory which may lead to guests crashing and
21+
interrupting workloads causing malfunctions.
22+
severity: Medium
23+
checkType: Platform
24+
scannerType: CEL
25+
inputs:
26+
- name: vms
27+
kubernetesInputSpec:
28+
apiVersion: kubevirt.io/v1
29+
resource: VirtualMachine
30+
expression: |
31+
vms.all(h,
32+
!has(h.spec.template.spec.domain.resources) ||
33+
!has(h.spec.template.spec.domain.resources.overcommitGuestOverhead) ||
34+
(has(h.spec.template.spec.domain.resources.overcommitGuestOverhead) &&
35+
h.spec.template.spec.domain.resources.overcommitGuestOverhead == false)
36+
)

config/samples/custom-rules/openshift-virtualization/kustomization.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ resources:
44
- kubevirt-nonroot-feature-gate-is-enabled.yaml
55
- kubevirt-no-permitted-host-devices.yaml
66
- kubevirt-persistent-reservation-disabled.yaml
7+
- kubevirt-no-vms-overcommiting-guest-memory
78
- tailored-profile.yaml
89
- scan-setting-binding.yaml

config/samples/custom-rules/openshift-virtualization/tailored-profile.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ spec:
2828
explicitly required. This feature allows VMs to claim exclusive access
2929
to storage resources, potentially impacting availability and enabling
3030
resource manipulation outside normal access controls.
31+
- kind: CustomRule
32+
name: kubevirt-no-vms-overcommiting-guest-memory
33+
rationale: |-
34+
This is a hypervisor-level feature that allows nodes to host more
35+
virtual machines than would normally be allowed by KubeVirt’s
36+
scheduling algorithms. If the VM consumes the entire memory might
37+
cause the guest to crash with workload interruptions and guest
38+
malfunctioning.
3139
title: Platform checks for OpenShift Virtualization

0 commit comments

Comments
 (0)