Skip to content

Commit 5e3b41c

Browse files
committed
CONSOLE-4788: Backend Request Headers Updates for multi-group impersonation
Handle X-Console-Impersonate-Groups header by splitting comma-separated groups into multiple Impersonate-Group headers for Kubernetes API.
1 parent d62c016 commit 5e3b41c

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

pkg/proxy/proxy.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
123123
r.Header.Del(h)
124124
}
125125

126+
// Handle X-Console-Impersonate-Groups header for multi-group impersonation
127+
// The fetch() API doesn't support multiple headers with the same name,
128+
// so the frontend sends a comma-separated list that we split here
129+
if consoleGroups := r.Header.Get("X-Console-Impersonate-Groups"); consoleGroups != "" {
130+
r.Header.Del("X-Console-Impersonate-Groups")
131+
groups := strings.Split(consoleGroups, ",")
132+
for _, group := range groups {
133+
group = strings.TrimSpace(group)
134+
if group != "" {
135+
r.Header.Add("Impersonate-Group", group)
136+
}
137+
}
138+
}
139+
126140
// Include `system:authenticated` when impersonating groups so that basic requests that all
127141
// users can run like self-subject access reviews work.
128142
if len(r.Header["Impersonate-Group"]) > 0 {

0 commit comments

Comments
 (0)