fix(kubernetes-client): resolve named service target ports - #7969
Open
GrosQuildu wants to merge 2 commits into
Open
fix(kubernetes-client): resolve named service target ports#7969GrosQuildu wants to merge 2 commits into
GrosQuildu wants to merge 2 commits into
Conversation
GrosQuildu
marked this pull request as ready for review
June 26, 2026 16:46
GrosQuildu
requested review from
ash-thakur-rh,
manusa and
shawkins
as code owners
June 26, 2026 16:46
GrosQuildu
added a commit
to GrosQuildu/kubernetes-client
that referenced
this pull request
Jun 26, 2026
GrosQuildu
force-pushed
the
ptp-60-named-target-port
branch
from
June 26, 2026 17:16
5d724c8 to
23e64da
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fabric8's Service port-forward implementation resolves numeric Service
targetPortvalues, but it does not resolve namedtargetPortvalues.For a Service port with
targetPort: "http",ServiceOperationsImplcallsgetTargetPort().getIntVal(). That returnsnull, so Fabric8 falls back to the Service port and forwards to the wrong Pod port.This affects the Service port-forward overloads that delegate through
ServiceOperationsImpl:portForward(int, ReadableByteChannel, WritableByteChannel)portForward(int)portForward(int, int)portForward(int, InetAddress, int)Expected Behavior And kubectl Parity
Kubernetes Services support
targetPortas either a number or a name. A namedtargetPortis resolved against the selected Pod's named container ports.kubectl port-forward service/...performs this Service-port-to-Pod-port translation before opening the Podportforwardstream. Fabric8's Service port-forward API should do the same. If the name cannot be resolved on the selected Pod, it should fail closed instead of silently falling back to the Service port.Deduplication found upstream issue fabric8io/kubernetes-client#7372 and PR #7394, but that fix only handled numeric
targetPortvalues. The namedtargetPortcase remains unresolved.Exploit Scenario And PoC
A platform exposes a restricted "connect to my service" workflow backed by Fabric8. Users can choose a namespace, Service name, and Service port, but they cannot choose an arbitrary Pod or Pod port. The platform's Kubernetes credentials can read Services, list matching Pods, and create Pod port-forward streams.
The target Service exposes public HTTP on Service port
80and maps it to a named Pod port:The selected Pod has the public HTTP listener on named container port
httpat Pod port8080, but also has a pod-local admin listener on numeric port80:The platform calls the Service-level API:
Expected result: Fabric8 resolves
targetPort: "http"to Pod port8080and opens:Actual result: Fabric8 ignores the string target port, falls back to the Service port, and opens:
The user receives a tunnel to the pod-local admin listener even though the exposed workflow only allowed Service-level access to port
80.Threat Model
This is in scope when a downstream application exposes Fabric8 Service port-forwarding to lower-privileged users through higher-privileged Kubernetes credentials.
The attacker only needs access to that Service-level workflow and control over, or access to, a Service that uses a named
targetPort. The attacker does not need direct Podexecor arbitrary Pod port-forward permission.Suggested Fix
Resolve string
targetPortvalues against the selected Pod's named container ports before delegating to Pod port-forwarding.The resolver should:
targetPortbehavior;targetPort.getStrVal()by matching Pod container port names;Validation
A regression test should assert that a Service with
port: 80andtargetPort: "http"forwards to the selected Pod's named container port8080, not Pod port80.On the vulnerable implementation:
With the patch applied:
Paweł Płatek from Trail of Bits in collaboration with OpenAI.