Skip to content

Commit 1c03437

Browse files
committed
Add CEL CustomRules from CO
1 parent ed45ffe commit 1c03437

5 files changed

Lines changed: 274 additions & 0 deletions

File tree

  • applications/openshift-virtualization
    • kubevirt-enforce-trusted-tls-registries
    • kubevirt-no-permitted-host-devices
    • kubevirt-no-vms-overcommitting-guest-memory
    • kubevirt-nonroot-feature-gate-is-enabled
    • kubevirt-persistent-reservation-disabled
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
documentation_complete: true
2+
3+
title: 'Only Trusted Registries Using TLS Can Be Used'
4+
5+
description: |-
6+
By only pulling container images from trusted registries using TLS, organizations
7+
can reduce the risk of introducing unknown vulnerabilities or malicious
8+
software into their systems. This helps ensure that their applications and systems
9+
remain secure and stable. All container image registries used by KubeVirt should
10+
require TLS connections to protect the integrity and authenticity of images.
11+
12+
rationale: |-
13+
When the <tt>.spec.storageImport.insecureRegistries</tt> field contains entries in
14+
the <tt>kubevirt-hyperconverged</tt> resource, KubeVirt is configured to allow
15+
connections to container registries that do not use TLS encryption. This creates
16+
a significant security risk as images could be intercepted or tampered with during
17+
transit. Man-in-the-middle attacks could result in malicious images being pulled
18+
and executed within virtual machines. To maintain security, only registries using
19+
TLS should be permitted, and the insecureRegistries list should be empty.
20+
21+
failureReason: |-
22+
There are registries not using TLS in '.spec.storageImport.insecureRegistries' in
23+
the 'kubevirt-hyperconverged' resource.
24+
25+
severity: medium
26+
27+
ocil_clause: 'insecure registries are configured'
28+
29+
ocil: |-
30+
Run the following command to check for insecure registries:
31+
<pre>$ oc get hyperconverged kubevirt-hyperconverged -n openshift-cnv -o jsonpath='{.spec.storageImport.insecureRegistries}'</pre>
32+
The output should be empty or the field should not exist.
33+
34+
checkType: Platform
35+
36+
scannerType: CEL
37+
38+
inputs:
39+
- name: hco
40+
kubernetesInputSpec:
41+
apiVersion: hco.kubevirt.io/v1beta1
42+
resource: hyperconvergeds
43+
resourceName: kubevirt-hyperconverged
44+
resourceNamespace: openshift-cnv
45+
46+
expression: |-
47+
!has(hco.spec.storageImport) ||
48+
hco.spec.storageImport.insecureRegistries.size() == 0
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
documentation_complete: true
2+
3+
title: 'KubeVirt Must Not Permit Host Devices'
4+
5+
description: |-
6+
Host devices should not be permitted to virtualization workloads unless
7+
absolutely necessary for workload execution. Allowing host devices provides
8+
direct access to host hardware, which can introduce security risks including
9+
unauthorized access to sensitive hardware resources, potential for privilege
10+
escalation, and bypass of virtualization security boundaries.
11+
12+
By default, no host devices should be trusted or permitted for use by
13+
virtualization workloads.
14+
15+
rationale: |-
16+
The <tt>.spec.permittedHostDevices</tt> field in the <tt>kubevirt-hyperconverged</tt>
17+
resource controls which host devices can be used by virtualization workloads.
18+
Permitting host devices allows virtual machines to bypass virtualization boundaries
19+
and directly access host hardware, which introduces significant security risks.
20+
This can lead to unauthorized access to sensitive hardware resources, privilege
21+
escalation opportunities, and potential compromise of the host system. Unless
22+
explicitly required, no host devices should be permitted.
23+
24+
failureReason: |-
25+
The '.spec.permittedHostDevices' field is set in the 'kubevirt-hyperconverged'
26+
resource, allowing host devices to be used by virtualization workloads.
27+
28+
severity: medium
29+
30+
ocil_clause: 'permittedHostDevices are configured in kubevirt-hyperconverged'
31+
32+
ocil: |-
33+
Run the following command to check the HyperConverged configuration:
34+
<pre>$ oc get hyperconverged kubevirt-hyperconverged -n openshift-cnv -o jsonpath='{.spec.permittedHostDevices}'</pre>
35+
The output should be empty or show empty lists for both <tt>pciHostDevices</tt> and <tt>mediatedDevices</tt>.
36+
37+
checkType: Platform
38+
39+
scannerType: CEL
40+
41+
inputs:
42+
- name: hcoList
43+
kubernetesInputSpec:
44+
apiVersion: hco.kubevirt.io/v1beta1
45+
resource: hyperconvergeds
46+
47+
expression: |
48+
hcoList.items.filter(h,
49+
h.metadata.name == 'kubevirt-hyperconverged' &&
50+
h.metadata.namespace == 'openshift-cnv'
51+
).size() == 1 &&
52+
hcoList.items.filter(h,
53+
h.metadata.name == 'kubevirt-hyperconverged' &&
54+
h.metadata.namespace == 'openshift-cnv'
55+
).all(h,
56+
!has(h.spec.permittedHostDevices) ||
57+
h.spec.permittedHostDevices == null ||
58+
(has(h.spec.permittedHostDevices.pciHostDevices) && size(h.spec.permittedHostDevices.pciHostDevices) == 0) &&
59+
(has(h.spec.permittedHostDevices.mediatedDevices) && size(h.spec.permittedHostDevices.mediatedDevices) == 0)
60+
)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
documentation_complete: true
2+
3+
title: 'VMs Must Not Overcommit Guest Memory'
4+
5+
description: |-
6+
The <tt>overcommitGuestOverhead</tt> configuration option enables the request for
7+
additional virtual machine management memory inside the virt-launcher pod.
8+
The overcommit feature is used to increase virtual machine density on the
9+
node, as long as the virtual machine doesn't request all the memory that it
10+
would need if fully loaded. However, if the VM were to use all of the
11+
memory it could, this would lead to the OpenShift Scheduler killing the
12+
workload.
13+
14+
rationale: |-
15+
When the <tt>.spec.template.spec.domain.resources.overcommitGuestOverhead</tt> field is
16+
set to <tt>true</tt> in the <tt>VirtualMachine</tt> resource, VMs are allowed to
17+
overcommit KubeVirt's memory which may lead to guests crashing and
18+
interrupting workloads causing malfunctions. To prevent memory-related failures
19+
and ensure workload stability, this setting should not be enabled.
20+
21+
failureReason: |-
22+
The '.spec.template.spec.domain.resources.overcommitGuestOverhead' field exists and is
23+
set to "true" in the 'VirtualMachine' resource, allowing VMs to
24+
overcommit KubeVirt's memory which may lead to guests crashing and
25+
interrupting workloads causing malfunctions.
26+
27+
severity: medium
28+
29+
ocil_clause: 'VMs have overcommitGuestOverhead set to true'
30+
31+
ocil: |-
32+
Run the following command to check VirtualMachine configurations:
33+
<pre>$ oc get virtualmachines -A -o jsonpath='{range .items[*]}{.metadata.namespace}{"/"}{.metadata.name}{": "}{.spec.template.spec.domain.resources.overcommitGuestOverhead}{"\n"}{end}'</pre>
34+
Make sure no VirtualMachine has <tt>overcommitGuestOverhead</tt> set to <tt>true</tt>.
35+
36+
checkType: Platform
37+
38+
scannerType: CEL
39+
40+
inputs:
41+
- name: vms
42+
kubernetesInputSpec:
43+
apiVersion: kubevirt.io/v1
44+
resource: VirtualMachine
45+
46+
expression: |
47+
vms.all(h,
48+
!has(h.spec.template.spec.domain.resources) ||
49+
!has(h.spec.template.spec.domain.resources.overcommitGuestOverhead) ||
50+
(has(h.spec.template.spec.domain.resources.overcommitGuestOverhead) &&
51+
h.spec.template.spec.domain.resources.overcommitGuestOverhead == false)
52+
)
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
documentation_complete: true
2+
3+
title: 'KubeVirt nonRoot Feature Gate Must Be Enabled'
4+
5+
description: |-
6+
The <tt>nonRoot</tt> feature gate in KubeVirt enables restrictions that prevent
7+
virtual machines from running with root privileges. This feature enforces
8+
security boundaries and helps prevent privilege escalation attacks. All virtual
9+
machines should operate with the minimum necessary privileges, and the nonRoot
10+
feature gate ensures this principle is enforced at the platform level.
11+
12+
rationale: |-
13+
Unauthorized access to a root account without restrictions implemented by
14+
the nonRoot feature introduces the risk of unintended or unauthorized
15+
access to privilege elevation and the ability to perform administrative
16+
tasks. When the <tt>.spec.featureGates.nonRoot</tt> field is set to <tt>true</tt>
17+
in the <tt>kubevirt-hyperconverged</tt> resource, KubeVirt enforces non-root
18+
execution for virtual machine workloads, significantly reducing the attack
19+
surface and limiting the potential impact of security vulnerabilities.
20+
21+
failureReason: |-
22+
The '.spec.featureGates.nonRoot' field is missing or not set to 'true' in
23+
the 'kubevirt-hyperconverged' resource.
24+
25+
severity: medium
26+
27+
ocil_clause: 'nonRoot feature gate is not set to true'
28+
29+
ocil: |-
30+
Run the following command to check the feature gate configuration:
31+
<pre>$ oc get hyperconverged kubevirt-hyperconverged -n openshift-cnv -o jsonpath='{.spec.featureGates.nonRoot}'</pre>
32+
The output should be <tt>true</tt>.
33+
34+
checkType: Platform
35+
36+
scannerType: CEL
37+
38+
inputs:
39+
- name: hcoList
40+
kubernetesInputSpec:
41+
apiVersion: hco.kubevirt.io/v1beta1
42+
resource: hyperconvergeds
43+
44+
expression: |
45+
hcoList.items.filter(h,
46+
h.metadata.name == 'kubevirt-hyperconverged' &&
47+
h.metadata.namespace == 'openshift-cnv'
48+
).size() == 1 &&
49+
hcoList.items.filter(h,
50+
h.metadata.name == 'kubevirt-hyperconverged' &&
51+
h.metadata.namespace == 'openshift-cnv'
52+
).all(h,
53+
has(h.spec.featureGates) &&
54+
has(h.spec.featureGates.nonRoot) &&
55+
h.spec.featureGates.nonRoot == true
56+
)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
documentation_complete: true
2+
3+
title: 'KubeVirt Persistent Reservation Feature Gate Must Be Disabled'
4+
5+
description: |-
6+
The persistent reservation feature gate in KubeVirt allows virtual machines
7+
to use SCSI persistent reservations, which provide exclusive access to shared
8+
storage. This feature should be disabled unless explicitly required for
9+
workload operation, as it can introduce security risks by allowing VMs to
10+
claim exclusive access to storage resources, potentially impacting availability
11+
and enabling resource manipulation outside normal access controls.
12+
13+
rationale: |-
14+
The <tt>.spec.featureGates.persistentReservation</tt> field in the
15+
<tt>kubevirt-hyperconverged</tt> resource controls whether virtual machines can
16+
use SCSI persistent reservations. When enabled, this feature allows VMs to claim
17+
exclusive access to shared storage resources, which can be exploited to cause
18+
denial of service conditions or manipulate storage access in ways that bypass
19+
normal Kubernetes access controls. Unless this capability is explicitly required
20+
for specific workload requirements, it should remain disabled to minimize the
21+
attack surface.
22+
23+
failureReason: |-
24+
The '.spec.featureGates.persistentReservation' field is missing, not set,
25+
or not set to 'false' in the 'kubevirt-hyperconverged' resource.
26+
27+
severity: medium
28+
29+
ocil_clause: 'persistentReservation feature gate is not explicitly set to false'
30+
31+
ocil: |-
32+
Run the following command to check the feature gate configuration:
33+
<pre>$ oc get hyperconverged kubevirt-hyperconverged -n openshift-cnv -o jsonpath='{.spec.featureGates.persistentReservation}'</pre>
34+
The output should be <tt>false</tt>.
35+
36+
checkType: Platform
37+
38+
scannerType: CEL
39+
40+
inputs:
41+
- name: hcoList
42+
kubernetesInputSpec:
43+
apiVersion: hco.kubevirt.io/v1beta1
44+
resource: hyperconvergeds
45+
46+
expression: |
47+
hcoList.items.filter(h,
48+
h.metadata.name == 'kubevirt-hyperconverged' &&
49+
h.metadata.namespace == 'openshift-cnv'
50+
).size() == 1 &&
51+
hcoList.items.filter(h,
52+
h.metadata.name == 'kubevirt-hyperconverged' &&
53+
h.metadata.namespace == 'openshift-cnv'
54+
).all(h,
55+
has(h.spec.featureGates) &&
56+
has(h.spec.featureGates.persistentReservation) &&
57+
h.spec.featureGates.persistentReservation == false
58+
)

0 commit comments

Comments
 (0)