Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for issue 1166: Allow CAP_NET_RAW and NET_RAW drop capabilities #1168

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,20 @@ spec:
securityContext:
capabilities:
drop:
- CAP_NET_RAW
- CAP_NET_RAW
---
apiVersion: v1
kind: Pod
metadata:
name: drop-netraw-good
spec:
containers:
- args:
- sleep
- infinity
image: ghcr.io/kyverno/test-busybox:1.35
name: busybox
securityContext:
capabilities:
drop:
- NET_RAW
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ readme: |
annotations:
kyverno/category: "Best Practices"
kyverno/subject: "Pod"
digest: 97e963f073e6324fa514015bc8fd8564b93fb7da6f8564fcf8a8fefc4c9da784
digest: 594b30a84f36a2b46b723a4110d843f6099d7e7c17c82b70a91942c7081bb901
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ kind: ClusterPolicy
metadata:
name: drop-cap-net-raw
annotations:
policies.kyverno.io/title: Drop CAP_NET_RAW
policies.kyverno.io/category: Best Practices
policies.kyverno.io/minversion: 1.6.0
policies.kyverno.io/title: Drop CAP_NET_RAW in CEL expressions
policies.kyverno.io/category: Best Practices in CEL
policies.kyverno.io/minversion: 1.11.0
kyverno.io/kubernetes-version: "1.26-1.27"
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: Pod
policies.kyverno.io/description: >-
Expand All @@ -25,19 +26,19 @@ spec:
- resources:
kinds:
- Pod
preconditions:
all:
- key: "{{ request.operation || 'BACKGROUND' }}"
operator: NotEquals
value: DELETE
operations:
- CREATE
- UPDATE
validate:
message: >-
Containers must drop the `CAP_NET_RAW` capability.
foreach:
- list: request.object.spec.[ephemeralContainers, initContainers, containers][]
deny:
conditions:
all:
- key: CAP_NET_RAW
operator: AnyNotIn
value: "{{ element.securityContext.capabilities.drop[].to_upper(@) || `[]` }}"
cel:
variables:
- name: mustDropCapabilities
expression: "['CAP_NET_RAW','NET_RAW']"
- name: allContainers
expression: "object.spec.containers + object.spec.?initContainers.orValue([]) + object.spec.?ephemeralContainers.orValue([])"
expressions:
- expression: >-
variables.allContainers.all(container,
container.?securityContext.?capabilities.?drop.orValue([]).exists(capability, capability.upperAscii() in variables.mustDropCapabilities))
message: >-
Containers must drop the `CAP_NET_RAW` capability.
Loading