@@ -67,11 +67,12 @@ type WebhookAuthorizer struct {
67
67
retryBackoff wait.Backoff
68
68
decisionOnError authorizer.Decision
69
69
metrics AuthorizerMetrics
70
+ cluster string
70
71
}
71
72
72
73
// NewFromInterface creates a WebhookAuthorizer using the given subjectAccessReview client
73
- func NewFromInterface (subjectAccessReview authorizationv1client.AuthorizationV1Interface , authorizedTTL , unauthorizedTTL time.Duration , retryBackoff wait.Backoff , metrics AuthorizerMetrics ) (* WebhookAuthorizer , error ) {
74
- return newWithBackoff (& subjectAccessReviewV1Client {subjectAccessReview .RESTClient ()}, authorizedTTL , unauthorizedTTL , retryBackoff , metrics )
74
+ func NewFromInterface (subjectAccessReview authorizationv1client.AuthorizationV1Interface , authorizedTTL , unauthorizedTTL time.Duration , retryBackoff wait.Backoff , metrics AuthorizerMetrics , cluster string ) (* WebhookAuthorizer , error ) {
75
+ return newWithBackoff (& subjectAccessReviewV1Client {subjectAccessReview .RESTClient (), cluster }, authorizedTTL , unauthorizedTTL , retryBackoff , metrics , cluster )
75
76
}
76
77
77
78
// New creates a new WebhookAuthorizer from the provided kubeconfig file.
@@ -93,19 +94,19 @@ func NewFromInterface(subjectAccessReview authorizationv1client.AuthorizationV1I
93
94
//
94
95
// For additional HTTP configuration, refer to the kubeconfig documentation
95
96
// https://kubernetes.io/docs/user-guide/kubeconfig-file/.
96
- func New (kubeConfigFile string , version string , authorizedTTL , unauthorizedTTL time.Duration , retryBackoff wait.Backoff , customDial utilnet.DialFunc ) (* WebhookAuthorizer , error ) {
97
- subjectAccessReview , err := subjectAccessReviewInterfaceFromKubeconfig (kubeConfigFile , version , retryBackoff , customDial )
97
+ func New (kubeConfigFile , version , cluster string , authorizedTTL , unauthorizedTTL time.Duration , retryBackoff wait.Backoff , customDial utilnet.DialFunc ) (* WebhookAuthorizer , error ) {
98
+ subjectAccessReview , err := subjectAccessReviewInterfaceFromKubeconfig (kubeConfigFile , version , cluster , retryBackoff , customDial )
98
99
if err != nil {
99
100
return nil , err
100
101
}
101
102
return newWithBackoff (subjectAccessReview , authorizedTTL , unauthorizedTTL , retryBackoff , AuthorizerMetrics {
102
103
RecordRequestTotal : noopMetrics {}.RecordRequestTotal ,
103
104
RecordRequestLatency : noopMetrics {}.RecordRequestLatency ,
104
- })
105
+ }, cluster )
105
106
}
106
107
107
108
// newWithBackoff allows tests to skip the sleep.
108
- func newWithBackoff (subjectAccessReview subjectAccessReviewer , authorizedTTL , unauthorizedTTL time.Duration , retryBackoff wait.Backoff , metrics AuthorizerMetrics ) (* WebhookAuthorizer , error ) {
109
+ func newWithBackoff (subjectAccessReview subjectAccessReviewer , authorizedTTL , unauthorizedTTL time.Duration , retryBackoff wait.Backoff , metrics AuthorizerMetrics , cluster string ) (* WebhookAuthorizer , error ) {
109
110
return & WebhookAuthorizer {
110
111
subjectAccessReview : subjectAccessReview ,
111
112
responseCache : cache .NewLRUExpireCache (8192 ),
@@ -114,6 +115,7 @@ func newWithBackoff(subjectAccessReview subjectAccessReviewer, authorizedTTL, un
114
115
retryBackoff : retryBackoff ,
115
116
decisionOnError : authorizer .DecisionNoOpinion ,
116
117
metrics : metrics ,
118
+ cluster : cluster ,
117
119
}, nil
118
120
}
119
121
@@ -272,7 +274,7 @@ func convertToSARExtra(extra map[string][]string) map[string]authorizationv1.Ext
272
274
// subjectAccessReviewInterfaceFromKubeconfig builds a client from the specified kubeconfig file,
273
275
// and returns a SubjectAccessReviewInterface that uses that client. Note that the client submits SubjectAccessReview
274
276
// requests to the exact path specified in the kubeconfig file, so arbitrary non-API servers can be targeted.
275
- func subjectAccessReviewInterfaceFromKubeconfig (kubeConfigFile string , version string , retryBackoff wait.Backoff , customDial utilnet.DialFunc ) (subjectAccessReviewer , error ) {
277
+ func subjectAccessReviewInterfaceFromKubeconfig (kubeConfigFile , version , cluster string , retryBackoff wait.Backoff , customDial utilnet.DialFunc ) (subjectAccessReviewer , error ) {
276
278
localScheme := runtime .NewScheme ()
277
279
if err := scheme .AddToScheme (localScheme ); err != nil {
278
280
return nil , err
@@ -288,7 +290,7 @@ func subjectAccessReviewInterfaceFromKubeconfig(kubeConfigFile string, version s
288
290
if err != nil {
289
291
return nil , err
290
292
}
291
- return & subjectAccessReviewV1ClientGW {gw .RestClient }, nil
293
+ return & subjectAccessReviewV1ClientGW {gw .RestClient , cluster }, nil
292
294
293
295
case authorizationv1beta1 .SchemeGroupVersion .Version :
294
296
groupVersions := []schema.GroupVersion {authorizationv1beta1 .SchemeGroupVersion }
@@ -299,7 +301,7 @@ func subjectAccessReviewInterfaceFromKubeconfig(kubeConfigFile string, version s
299
301
if err != nil {
300
302
return nil , err
301
303
}
302
- return & subjectAccessReviewV1beta1ClientGW {gw .RestClient }, nil
304
+ return & subjectAccessReviewV1beta1ClientGW {gw .RestClient , cluster }, nil
303
305
304
306
default :
305
307
return nil , fmt .Errorf (
@@ -312,13 +314,15 @@ func subjectAccessReviewInterfaceFromKubeconfig(kubeConfigFile string, version s
312
314
}
313
315
314
316
type subjectAccessReviewV1Client struct {
315
- client rest.Interface
317
+ client rest.Interface
318
+ cluster string
316
319
}
317
320
318
321
func (t * subjectAccessReviewV1Client ) Create (ctx context.Context , subjectAccessReview * authorizationv1.SubjectAccessReview , opts metav1.CreateOptions ) (result * authorizationv1.SubjectAccessReview , statusCode int , err error ) {
319
322
result = & authorizationv1.SubjectAccessReview {}
320
323
321
324
restResult := t .client .Post ().
325
+ Cluster (t .cluster ).
322
326
Resource ("subjectaccessreviews" ).
323
327
VersionedParams (& opts , scheme .ParameterCodec ).
324
328
Body (subjectAccessReview ).
@@ -331,14 +335,15 @@ func (t *subjectAccessReviewV1Client) Create(ctx context.Context, subjectAccessR
331
335
332
336
// subjectAccessReviewV1ClientGW used by the generic webhook, doesn't specify GVR.
333
337
type subjectAccessReviewV1ClientGW struct {
334
- client rest.Interface
338
+ client rest.Interface
339
+ cluster string
335
340
}
336
341
337
342
func (t * subjectAccessReviewV1ClientGW ) Create (ctx context.Context , subjectAccessReview * authorizationv1.SubjectAccessReview , _ metav1.CreateOptions ) (* authorizationv1.SubjectAccessReview , int , error ) {
338
343
var statusCode int
339
344
result := & authorizationv1.SubjectAccessReview {}
340
345
341
- restResult := t .client .Post ().Body (subjectAccessReview ).Do (ctx )
346
+ restResult := t .client .Post ().Cluster ( t . cluster ). Body (subjectAccessReview ).Do (ctx )
342
347
343
348
restResult .StatusCode (& statusCode )
344
349
err := restResult .Into (result )
@@ -348,15 +353,16 @@ func (t *subjectAccessReviewV1ClientGW) Create(ctx context.Context, subjectAcces
348
353
349
354
// subjectAccessReviewV1beta1ClientGW used by the generic webhook, doesn't specify GVR.
350
355
type subjectAccessReviewV1beta1ClientGW struct {
351
- client rest.Interface
356
+ client rest.Interface
357
+ cluster string
352
358
}
353
359
354
360
func (t * subjectAccessReviewV1beta1ClientGW ) Create (ctx context.Context , subjectAccessReview * authorizationv1.SubjectAccessReview , _ metav1.CreateOptions ) (* authorizationv1.SubjectAccessReview , int , error ) {
355
361
var statusCode int
356
362
v1beta1Review := & authorizationv1beta1.SubjectAccessReview {Spec : v1SpecToV1beta1Spec (& subjectAccessReview .Spec )}
357
363
v1beta1Result := & authorizationv1beta1.SubjectAccessReview {}
358
364
359
- restResult := t .client .Post ().Body (v1beta1Review ).Do (ctx )
365
+ restResult := t .client .Post ().Cluster ( t . cluster ). Body (v1beta1Review ).Do (ctx )
360
366
361
367
restResult .StatusCode (& statusCode )
362
368
err := restResult .Into (v1beta1Result )
0 commit comments