For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/kubernetes-cluster-allows-unsafe-sysctls.md.
A documentation index is available at /llms.txt.
A Kubernetes cluster must not allow unsafe sysctls. Allowing unsafe sysctls can let a Pod influence other Pods, harm node stability, or consume CPU or memory beyond resource limits.
spec.securityContext.sysctls must not include unsafe sysctls, and allowedUnsafeSysctls must be undefined. This rule detects PodSecurityPolicy resources where allowedUnsafeSysctls is defined and flags any spec.securityContext.sysctls entries that are not in the defined safe list.
Only a limited set of sysctls are considered safe; all others are treated as unsafe and should not be used.
Compliant Code Examples
#this code is a correct code for which the query should not find any resultapiVersion:v1kind:Podmetadata:name:sysctl-examplespec:securityContext:sysctls:- name:kernel.shm_rmid_forcedvalue:"0"- name:net.ipv4.ip_local_port_rangevalue:"0"containers:- name:test1image:nginx---apiVersion:policy/v1beta1kind:PodSecurityPolicymetadata:name:sysctl-pspspec:forbiddenSysctls:- kernel.shm_rmid_forcedseLinux:rule:RunAsAnysupplementalGroups:rule:RunAsAnyrunAsUser:rule:RunAsAnyfsGroup:rule:RunAsAny
#this is a problematic code where the query should report a result(s)apiVersion:v1kind:Podmetadata:name:sysctl-examplespec:securityContext:sysctls:- name:kernel.shm_rmid_forcedvalue:"0"- name:net.core.somaxconnvalue:"1024"- name:kernel.msgmaxvalue:"65536"containers:- name:test1image:nginx---apiVersion:policy/v1beta1kind:PodSecurityPolicymetadata:name:sysctl-pspspec:allowedUnsafeSysctls:- kernel.msg*forbiddenSysctls:- kernel.shm_rmid_forcedseLinux:rule:RunAsAnysupplementalGroups:rule:RunAsAnyrunAsUser:rule:RunAsAnyfsGroup:rule:RunAsAny