Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion lib/auth/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,12 @@ func (a *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
ctx = authz.ContextWithClientSrcAddr(ctx, clientSrcAddr)
}
ctx = authz.ContextWithUser(ctx, user)
a.Handler.ServeHTTP(w, r.WithContext(ctx))
r = r.WithContext(ctx)
// set remote address to the one that was passed in the header
// this is needed because impersonation reuses the same connection
// and the remote address is not updated from 0.0.0.0:0
r.RemoteAddr = remoteAddr
a.Handler.ServeHTTP(w, r)
}

// WrapContextWithUser enriches the provided context with the identity information
Expand Down
1 change: 1 addition & 0 deletions lib/auth/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ func (h *fakeHTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
clientSrcAddr, err := authz.ClientSrcAddrFromContext(r.Context())
require.NoError(h.t, err)
require.Equal(h.t, h.userIP, clientSrcAddr.String())
require.Equal(h.t, h.userIP, r.RemoteAddr)
// Ensure that the Teleport-Impersonate-User header is not set on the request
// after the middleware has run.
require.Empty(h.t, r.Header.Get(TeleportImpersonateUserHeader))
Expand Down