@@ -11,20 +11,31 @@ const HeadersKey string = "headers"
11
11
12
12
func contextToHeaders (ctx context.Context , request * http.Request ) {
13
13
if ctx .Value (HeadersKey ) != nil {
14
- headers , ok := ctx .Value (HeadersKey ).(map [string ]string )
14
+ headers , ok := ctx .Value (HeadersKey ).(map [string ]interface {} )
15
15
if ok {
16
16
for key , value := range headers {
17
- if value != "" {
18
- request .Header .Add (key , value )
17
+ switch v := value .(type ) {
18
+ case string :
19
+ if v != "" {
20
+ request .Header .Add (key , v )
21
+ }
22
+ case []string :
23
+ // Handle multiple values for the same header (e.g., Impersonate-Group)
24
+ for _ , val := range v {
25
+ if val != "" {
26
+ request .Header .Add (key , val )
27
+ }
28
+ }
19
29
}
20
30
}
21
31
}
22
32
}
23
33
}
24
34
25
35
type initPayload struct {
26
- ImpersonateUser string `json:"Impersonate-User"`
27
- ImpersonateGroup string `json:"Impersonate-Group"`
36
+ ImpersonateUser string `json:"Impersonate-User"`
37
+ ImpersonateGroup string `json:"Impersonate-Group"`
38
+ ImpersonateGroups []string `json:"Impersonate-Groups"`
28
39
}
29
40
30
41
func InitPayload (ctx context.Context , payload json.RawMessage ) context.Context {
@@ -33,10 +44,19 @@ func InitPayload(ctx context.Context, payload json.RawMessage) context.Context {
33
44
if err != nil {
34
45
return ctx
35
46
}
36
- headers , ok := ctx .Value (HeadersKey ).(map [string ]string )
47
+ headers , ok := ctx .Value (HeadersKey ).(map [string ]interface {} )
37
48
if ok {
38
- headers ["Impersonate-User" ] = initPayload .ImpersonateUser
39
- headers ["Impersonate-Group" ] = initPayload .ImpersonateGroup
49
+ if initPayload .ImpersonateUser != "" {
50
+ headers ["Impersonate-User" ] = initPayload .ImpersonateUser
51
+ }
52
+ // Support both single group (backward compatibility) and multiple groups
53
+ if len (initPayload .ImpersonateGroups ) > 0 {
54
+ groups := initPayload .ImpersonateGroups
55
+ groups = append (groups , "system:authenticated" )
56
+ headers ["Impersonate-Group" ] = groups
57
+ } else if initPayload .ImpersonateGroup != "" {
58
+ headers ["Impersonate-Group" ] = []string {initPayload .ImpersonateGroup , "system:authenticated" }
59
+ }
40
60
ctx = context .WithValue (ctx , HeadersKey , headers )
41
61
}
42
62
return ctx
0 commit comments