Hijacking Kubernetes Services With Labels
Kubernetes Services and NetworkPolicies select the pods they target using label selectors, and nothing stops a user who can only create deployments from labelling a rogue pod to match. An attacker could then have their own container receive a share of the traffic sent to a legitimate service.
Published on infosecwriteups.com
According to the kubernetes documentation, labels are just intended to be used to identify attributes to users. But what if they were used to authorize how other resources interacted with them?
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the design treats label selectors as an authorisation mechanism for connecting resources, while label creation itself is not restricted by any access control.
Impact
Traffic meant for a legitimate service could be partly routed to an attacker-controlled container, and the same trick may widen network access granted by NetworkPolicies and some custom resources.
What the attacker needed
Permission to create deployments; no permission to edit the service needed
The fix
Labels should be used only to identify objects for users, not to authorise connections between resources, and where possible selectors should not be the sole basis for trust.
How it was found
- Create a deployment and a service whose selector matches the deployment's pod label.
- Note that the service now forwards traffic to the pods carrying that label.
- Create a second, rogue deployment whose pods carry the same label.
- Observe that traffic to the service is now split between the legitimate and the rogue pods.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
Kubernetes groups its objects with labels, which are simple name-and-value tags. A Service, which is the thing that forwards network traffic to your containers, picks its targets by matching those tags rather than by naming a specific pod. If anyone allowed to create a new pod can copy the tag, their pod gets included in the traffic.
What is Access control?
A user can do something their role should not allow: reach an admin function, act on a feature they have not paid for, or skip a permission check. IDOR is the special case where the object belongs to someone else.