Skip to content

Commit ab6d073

Browse files
committed
Upgrade cel using variables
Signed-off-by: Lavish pal <[email protected]>
1 parent 412727e commit ab6d073

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

pod-security-cel/baseline/disallow-host-ports/artifacthub-pkg.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ annotations:
1919
kyverno/category: "Pod Security Standards (Baseline) in CEL"
2020
kyverno/kubernetesVersion: "1.26-1.27"
2121
kyverno/subject: "Pod"
22-
digest: b95cfe16e11be0b9507736687bd99b5ea78c455f8fc35194220326ea5ff3913c
22+
digest: acd23ec8b3bd13a00e143757b60d027eb084a566839c9cf4caafdb06144b88fb
2323
createdAt: "2023-12-03T00:22:34Z"

pod-security-cel/baseline/disallow-host-ports/disallow-host-ports.yaml

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,19 @@ spec:
2828
- UPDATE
2929
validate:
3030
cel:
31-
expressions:
32-
- expression: >-
33-
object.spec.containers.all(container, !has(container.ports) ||
34-
container.ports.all(port, !has(port.hostPort) || port.hostPort == 0))
35-
message: >-
36-
Use of host ports is disallowed. The field spec.containers[*].ports[*].hostPort
37-
must either be unset or set to `0`.
31+
variables:
32+
- name: allContainers
33+
expression: >-
34+
object.spec.containers +
35+
object.spec.?initContainers.orValue([]) +
36+
object.spec.?ephemeralContainers.orValue([])
37+
expressions:
38+
- expression: >-
39+
variables.allContainers.all(container,
40+
container.?ports.orValue([]).all(port, port.?hostPort.orValue(0) == 0))
41+
message: |-
42+
Use of host ports is disallowed. The field spec.containers[*].ports[*].hostPort,
43+
spec.initContainers[*].ports[*].hostPort, and spec.ephemeralContainers[*].ports[*].hostPort
44+
must either be unset or set to `0`.
3845
39-
- expression: >-
40-
!has(object.spec.initContainers) ||
41-
object.spec.initContainers.all(container, !has(container.ports) ||
42-
container.ports.all(port, !has(port.hostPort) || port.hostPort == 0))
43-
message: >-
44-
Use of host ports is disallowed. The field spec.initContainers[*].ports[*].hostPort
45-
must either be unset or set to `0`.
46-
47-
- expression: >-
48-
!has(object.spec.ephemeralContainers) ||
49-
object.spec.ephemeralContainers.all(container, !has(container.ports) ||
50-
container.ports.all(port, !has(port.hostPort) || port.hostPort == 0))
51-
message: >-
52-
Use of host ports is disallowed. The field spec.ephemeralContainers[*].ports[*].hostPort
53-
must either be unset or set to `0`.
46+

0 commit comments

Comments
 (0)