Sub topic 12
Protecting Scheduling Labels from Nodes
This chapter assumes you can label nodes, write a nodeSelector, and read a node affinity rule. It covers a security gap: node labels drive scheduling, so whoever can change them can influence where pods run.
Why labels need protection
Scheduling rules trust node labels. Suppose a team uses the label example.com/dedicated=payments to keep payment pods on isolated nodes. A pod with a matching nodeSelector lands only on those nodes.
Now suppose an attacker controls one ordinary node. The kubelet on that node authenticates to the API server and can update its own Node object. If the kubelet could set any label, the attacker could add example.com/dedicated=payments to the compromised node. The scheduler would then send payment pods there, and the attacker could read their secrets and traffic.
What the NodeRestriction plugin does
The NodeRestriction admission plugin limits what a kubelet can change. With it enabled, a kubelet can modify only its own Node object and the Pod objects bound to its node. It cannot modify other nodes.
The plugin also stops a kubelet from setting or changing labels in a protected set:
- Labels with the prefix
node-restriction.kubernetes.io/. - Labels in the
kubernetes.ioandk8s.ionamespaces that are not on the kubelet's allowed list. Labels such askubernetes.io/hostname,kubernetes.io/os,kubernetes.io/arch, andtopology.kubernetes.io/zoneare among those a kubelet may set.
A kubelet's attempt to set a protected label is rejected. A cluster administrator, who has broader permissions, can still set it.
Using the protected prefix
To isolate workloads, label nodes with a key under node-restriction.kubernetes.io/. Only a cluster administrator can set it, so a compromised kubelet cannot claim it.
kubectl label nodes worker-1 node-restriction.kubernetes.io/tenant=payments
kubectl get nodes -L node-restriction.kubernetes.io/tenantThen select on that label as usual.
apiVersion: v1
kind: Pod
metadata:
name: payments-api
spec:
nodeSelector:
node-restriction.kubernetes.io/tenant: payments
containers:
- name: nginx
image: nginx:1.27How the pieces fit together
Common mistakes
- Using an unprotected key for isolation. A label like
dedicated=paymentshas no protection. A kubelet can set it on its own node. - Assuming labels alone are enough. Labels attract pods. They do not keep other pods away. Pair them with a taint and toleration so unrelated pods stay off the nodes.
- Letting users edit nodes. Anyone with RBAC permission to update Node objects can change labels. Restrict that permission.
- Skipping a check. On a self-managed cluster, confirm NodeRestriction is active before relying on it.
Exercise
A compromised worker node tries to label itself example.com/dedicated=payments so that payment pods are scheduled onto it. Why might NodeRestriction fail to stop this, and what label key would you use instead?
Show answer
NodeRestriction protects only the node-restriction.kubernetes.io/ prefix and certain kubernetes.io and k8s.io labels. A key such as example.com/dedicated is outside that set, so the kubelet can set it. Use a key like node-restriction.kubernetes.io/tenant, which only an administrator can set, and add a taint so other pods stay off those nodes.