File tree Expand file tree Collapse file tree 2 files changed +32
-0
lines changed
Expand file tree Collapse file tree 2 files changed +32
-0
lines changed Original file line number Diff line number Diff line change @@ -6,9 +6,12 @@ import (
66 "encoding/json"
77 "flag"
88 "fmt"
9+ "net/http"
910 "strings"
1011 "time"
1112
13+ "github.com/google/uuid"
14+
1215 "k8s.io/apiserver/pkg/authentication/authenticatorfactory"
1316 "k8s.io/apiserver/pkg/authentication/request/headerrequest"
1417 "k8s.io/apiserver/pkg/server/dynamiccertificates"
@@ -195,10 +198,37 @@ func (s *DelegatingAuthenticationOptions) newTokenAccessReview() (authentication
195198 if err != nil {
196199 return nil , err
197200 }
201+
202+ clientConfig .Wrap (auditIDRountripper )
203+
198204 client , err := authenticationclient .NewForConfig (clientConfig )
199205 if err != nil {
200206 return nil , err
201207 }
202208
203209 return client , nil
204210}
211+
212+ func auditIDRountripper (rt http.RoundTripper ) http.RoundTripper {
213+ return roundTripFunc (func (r * http.Request ) (* http.Response , error ) {
214+ const auditIDKey = "Audit-ID"
215+
216+ auditID := r .Header .Get (auditIDKey )
217+ if len (auditID ) == 0 {
218+ auditID = uuid .New ().String ()
219+ }
220+
221+ r .Header .Add ("Audit-ID" , auditID )
222+ resp , err := rt .RoundTrip (r )
223+ if err != nil {
224+ err = fmt .Errorf ("audit-ID %q request failed: %w" , auditID , err )
225+ }
226+ return resp , err
227+ })
228+ }
229+
230+ type roundTripFunc func (* http.Request ) (* http.Response , error )
231+
232+ func (fn roundTripFunc ) RoundTrip (req * http.Request ) (* http.Response , error ) {
233+ return fn (req )
234+ }
Original file line number Diff line number Diff line change @@ -74,6 +74,8 @@ func (s *DelegatingAuthorizationOptions) newSubjectAccessReview() (authorization
7474 return nil , err
7575 }
7676
77+ clientConfig .Wrap (auditIDRountripper )
78+
7779 client , err := authorizationclient .NewForConfig (clientConfig )
7880 if err != nil {
7981 return nil , err
You can’t perform that action at this time.
0 commit comments