fix(yurthub): reject unauthenticated requests on insecure proxy port - #2783
Open
sultancodesss wants to merge 1 commit into
Open
Conversation
Without this fix, RemoteProxy.RoundTrip forwards any request that lacks an Authorization header using YurtHub's own node client certificate. This means any pod able to reach the plain-HTTP proxy (127.0.0.1:10261 / 169.254.2.1:10261) can make Kubernetes API requests authenticated as system:node:<node> without supplying any credentials of its own. Fix: add a WithRequireAuthorization middleware that is applied exclusively to the insecure (plain-HTTP) proxy serving path in RunYurtHubServers. The middleware returns 401 Unauthorized for any request that carries no Authorization header, closing the credential- lending path in RemoteProxy.RoundTrip. YurtHub's own internal clients (multiplexer-proxy-<node> and the shared-informer clients with User-Agent prefix 'yurthub') are explicitly exempted so existing internal communication is unaffected. Fixes: openyurtio#2782
|
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.



What this PR does
Fixes #2782
Problem
When
--enable-dummy-if=true(the default), YurtHub exposes a plain-HTTP proxy on127.0.0.1:10261(and169.254.2.1:10261for the dummy interface). The proxy handler has no authentication layer on this port.In
RemoteProxy.RoundTrip, requests that carry noAuthorizationheader are forwarded to the Kubernetes API using YurtHub's own node client certificate:Any pod that can route traffic to the dummy IP can therefore cause Kubernetes API calls authenticated as
system:node:<node>without supplying any credentials.Fix
Add a
WithRequireAuthorizationmiddleware inpkg/yurthub/proxy/util/util.gothat returns401 Unauthorizedfor any request arriving on the plain-HTTP proxy port without anAuthorizationheader.The middleware is wired in
pkg/yurthub/server/server.goexclusively for the insecure proxy serving path (YurtHubProxyServerServing). The secure TLS port (YurtHubSecureProxyServerServing) is unaffected -- it already enforces mutual TLS client certificate authentication.YurtHub's own internal clients are explicitly exempted to preserve existing behaviour:
User-Agent: multiplexer-proxy-<node>)User-Agentprefix:yurthub)Testing
Both modified packages build cleanly for
linux/amd64:Related