Description
Prefer safe sysctls supported by both Kubernetes and the node kernel in the Pod’s securityContext.sysctls. Unsafe settings such as kernel.sem are disabled by default and require explicit permission on the node.
Potential impact
A Pod that requests a disallowed setting fails to start. An unsuitable kernel setting can affect resource use and other Pods on the same node.
Remediation
Remove unnecessary requests and node allowances. For an essential exception, test the value, restrict scheduling to dedicated nodes, then check Pod startup, resource use and neighboring workloads.
Examples
For older clusters, review PodSecurityPolicy.allowedUnsafeSysctls as well. PSP was deprecated in 1.21 and removed in 1.25. Use Pod Security Admission or another admission policy on current clusters.
Before
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-app
spec:
selector:
matchLabels:
app: test-app
template:
metadata:
labels:
app: test-app
spec:
securityContext:
sysctls:
- name: kernel.sem
value: "128 32768 128 4096"
containers:
- name: test-ubuntu
image: ubuntu
test-app-neg has a new name and selector, so applying it leaves test-app running. Update the existing Deployment’s Pod template while keeping its selector, or verify the replacement before retiring test-app.
After
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-app-neg
spec:
selector:
matchLabels:
app: test-app-neg
template:
metadata:
labels:
app: test-app-neg
spec:
securityContext:
sysctls:
- name: kernel.shm_rmid_forced
value: "0"
- name: net/ipv4/tcp_syncookies
value: "1"
containers:
- name: test-ubuntu
image: ubuntu
Both settings in the second example are on the safe list. The / form in net/ipv4/tcp_syncookies requires Kubernetes 1.25 or later in a Pod spec. Choose values, an image and a command for your application.