Skip to content

Commit 64e05b8

Browse files
authored
Revert "Forward the caller's identity to virtual workspaces" (#4307)
This reverts commit fc9691c.
1 parent fc9691c commit 64e05b8

3 files changed

Lines changed: 6 additions & 137 deletions

File tree

pkg/proxy/authheaders/authheaders.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,6 @@ import (
3030
userinfo "k8s.io/apiserver/pkg/authentication/user"
3131
)
3232

33-
// The header names a backend is conventionally configured to trust, matching
34-
// the --requestheader-username-headers, --requestheader-group-headers and
35-
// --requestheader-extra-headers-prefix that kcp starts its shards and virtual
36-
// workspace servers with.
37-
const (
38-
DefaultUserHeader = "X-Remote-User"
39-
DefaultGroupHeader = "X-Remote-Group"
40-
DefaultExtraHeaderPrefix = "X-Remote-Extra-"
41-
)
42-
4333
// ClearAuthHeaders deletes any inbound copies of the request-header identity
4434
// headers.
4535
func ClearAuthHeaders(header http.Header, userHeader, groupHeader, extraHeaderPrefix string) {

pkg/server/virtualresources/server.go

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ import (
4747
"github.com/kcp-dev/kcp/pkg/cache/client/shard"
4848
"github.com/kcp-dev/kcp/pkg/endpointslice"
4949
"github.com/kcp-dev/kcp/pkg/indexers"
50-
"github.com/kcp-dev/kcp/pkg/proxy/authheaders"
5150
"github.com/kcp-dev/kcp/pkg/reconciler/dynamicrestmapper"
5251
kcpfilters "github.com/kcp-dev/kcp/pkg/server/filters"
5352
)
@@ -405,26 +404,13 @@ func newVirtualResourceHandler(cfg *rest.Config, vwURL, clusterNameOrWildcard st
405404
Transport: tr,
406405
Rewrite: func(r *httputil.ProxyRequest) {
407406
r.SetURL(scopedURL)
407+
r.SetXForwarded()
408+
// SetURL clears the outbound Host along with pointing the request at
409+
// the virtual workspace; keep the host the caller asked for, which is
410+
// what a single-host reverse proxy forwards.
411+
r.Out.Host = r.In.Host
412+
408413
hops.SetHeader(r.Out.Header, inboundHops+1)
409-
// Say who asked.
410-
//
411-
// The connection to the virtual workspace authenticates as this shard,
412-
// so without this the virtual workspace sees the shard and authorizes
413-
// that instead of the caller -- and a provider's backend is told the
414-
// shard's identity rather than the user's. The virtual workspace
415-
// believes these headers only over a connection whose client
416-
// certificate its --requestheader-client-ca-file trusts, which is the
417-
// same arrangement the front proxy already uses to reach shards.
418-
//
419-
// Stamping strips any inbound copies first, so a client cannot assert
420-
// an identity by setting the headers itself.
421-
if user, ok := genericapirequest.UserFrom(r.Out.Context()); ok {
422-
authheaders.SetAuthHeaders(r.Out.Header, user,
423-
authheaders.DefaultUserHeader, authheaders.DefaultGroupHeader, authheaders.DefaultExtraHeaderPrefix)
424-
} else {
425-
authheaders.ClearAuthHeaders(r.Out.Header,
426-
authheaders.DefaultUserHeader, authheaders.DefaultGroupHeader, authheaders.DefaultExtraHeaderPrefix)
427-
}
428414
},
429415
}
430416

pkg/server/virtualresources/server_test.go

Lines changed: 0 additions & 107 deletions
This file was deleted.

0 commit comments

Comments
 (0)