Skip to content
Open
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
16 changes: 14 additions & 2 deletions pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {

subProtocol := ""
proxiedHeader := make(http.Header, len(r.Header))
hasImpersonateUser := false

for key, value := range r.Header {
if key != "Sec-Websocket-Protocol" {
// Do not proxy the subprotocol to the API server because k8s does not understand what we're sending
Expand All @@ -169,6 +171,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
proxiedHeader.Set("Impersonate-User", decodedProtocol)
hasImpersonateUser = true
subProtocol = protocol
} else if strings.HasPrefix(protocol, "Impersonate-Group.") {
encodedProtocol := strings.TrimPrefix(protocol, "Impersonate-Group.")
Expand All @@ -178,8 +181,12 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
http.Error(w, errMsg, http.StatusBadRequest)
return
}
proxiedHeader.Set("Impersonate-User", string(decodedProtocol))
proxiedHeader.Set("Impersonate-Group", string(decodedProtocol))
// If we haven't set Impersonate-User yet, this is single-group impersonation (backward compatibility)
if !hasImpersonateUser {
proxiedHeader.Set("Impersonate-User", string(decodedProtocol))
}
// Add each group as a separate Impersonate-Group header
proxiedHeader.Add("Impersonate-Group", string(decodedProtocol))
subProtocol = protocol
} else {
proxiedHeader.Set("Sec-Websocket-Protocol", protocol)
Expand All @@ -189,6 +196,11 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
}

// Add system:authenticated when impersonating groups
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just try to do the same thing like how it got handled here: https://github.com/openshift/console/pull/4156/files

if len(proxiedHeader["Impersonate-Group"]) > 0 {
proxiedHeader.Add("Impersonate-Group", "system:authenticated")
}

// Filter websocket headers.
websocketHeaders := []string{
"Connection",
Expand Down