mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #95725 from p0lyn0mial/delegated-authz-sar-timeout
sets explicit timeout for SubjectAccessReview client
This commit is contained in:
		@@ -116,6 +116,7 @@ func TestDefaultFlags(t *testing.T) {
 | 
				
			|||||||
		Authorization: &apiserveroptions.DelegatingAuthorizationOptions{
 | 
							Authorization: &apiserveroptions.DelegatingAuthorizationOptions{
 | 
				
			||||||
			AllowCacheTTL:                10 * time.Second,
 | 
								AllowCacheTTL:                10 * time.Second,
 | 
				
			||||||
			DenyCacheTTL:                 10 * time.Second,
 | 
								DenyCacheTTL:                 10 * time.Second,
 | 
				
			||||||
 | 
								ClientTimeout:                10 * time.Second,
 | 
				
			||||||
			RemoteKubeConfigFileOptional: true,
 | 
								RemoteKubeConfigFileOptional: true,
 | 
				
			||||||
			AlwaysAllowPaths:             []string{"/healthz"}, // note: this does not match /healthz/ or
 | 
								AlwaysAllowPaths:             []string{"/healthz"}, // note: this does not match /healthz/ or
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
@@ -248,6 +249,7 @@ func TestAddFlags(t *testing.T) {
 | 
				
			|||||||
		Authorization: &apiserveroptions.DelegatingAuthorizationOptions{
 | 
							Authorization: &apiserveroptions.DelegatingAuthorizationOptions{
 | 
				
			||||||
			AllowCacheTTL:                10 * time.Second,
 | 
								AllowCacheTTL:                10 * time.Second,
 | 
				
			||||||
			DenyCacheTTL:                 10 * time.Second,
 | 
								DenyCacheTTL:                 10 * time.Second,
 | 
				
			||||||
 | 
								ClientTimeout:                10 * time.Second,
 | 
				
			||||||
			RemoteKubeConfigFileOptional: true,
 | 
								RemoteKubeConfigFileOptional: true,
 | 
				
			||||||
			AlwaysAllowPaths:             []string{"/healthz"}, // note: this does not match /healthz/ or
 | 
								AlwaysAllowPaths:             []string{"/healthz"}, // note: this does not match /healthz/ or
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -417,6 +417,7 @@ func TestAddFlags(t *testing.T) {
 | 
				
			|||||||
		Authorization: &apiserveroptions.DelegatingAuthorizationOptions{
 | 
							Authorization: &apiserveroptions.DelegatingAuthorizationOptions{
 | 
				
			||||||
			AllowCacheTTL:                10 * time.Second,
 | 
								AllowCacheTTL:                10 * time.Second,
 | 
				
			||||||
			DenyCacheTTL:                 10 * time.Second,
 | 
								DenyCacheTTL:                 10 * time.Second,
 | 
				
			||||||
 | 
								ClientTimeout:                10 * time.Second,
 | 
				
			||||||
			RemoteKubeConfigFileOptional: true,
 | 
								RemoteKubeConfigFileOptional: true,
 | 
				
			||||||
			AlwaysAllowPaths:             []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/*
 | 
								AlwaysAllowPaths:             []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/*
 | 
				
			||||||
		},
 | 
							},
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -59,6 +59,10 @@ type DelegatingAuthorizationOptions struct {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	// AlwaysAllowGroups are groups which are allowed to take any actions.  In kube, this is system:masters.
 | 
						// AlwaysAllowGroups are groups which are allowed to take any actions.  In kube, this is system:masters.
 | 
				
			||||||
	AlwaysAllowGroups []string
 | 
						AlwaysAllowGroups []string
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// ClientTimeout specifies a time limit for requests made by SubjectAccessReviews client.
 | 
				
			||||||
 | 
						// The default value is set to 10 seconds.
 | 
				
			||||||
 | 
						ClientTimeout time.Duration
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func NewDelegatingAuthorizationOptions() *DelegatingAuthorizationOptions {
 | 
					func NewDelegatingAuthorizationOptions() *DelegatingAuthorizationOptions {
 | 
				
			||||||
@@ -66,6 +70,7 @@ func NewDelegatingAuthorizationOptions() *DelegatingAuthorizationOptions {
 | 
				
			|||||||
		// very low for responsiveness, but high enough to handle storms
 | 
							// very low for responsiveness, but high enough to handle storms
 | 
				
			||||||
		AllowCacheTTL: 10 * time.Second,
 | 
							AllowCacheTTL: 10 * time.Second,
 | 
				
			||||||
		DenyCacheTTL:  10 * time.Second,
 | 
							DenyCacheTTL:  10 * time.Second,
 | 
				
			||||||
 | 
							ClientTimeout: 10 * time.Second,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -81,6 +86,11 @@ func (s *DelegatingAuthorizationOptions) WithAlwaysAllowPaths(paths ...string) *
 | 
				
			|||||||
	return s
 | 
						return s
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					// WithClientTimeout sets the given timeout for SAR client used by this authorizer
 | 
				
			||||||
 | 
					func (s *DelegatingAuthorizationOptions) WithClientTimeout(timeout time.Duration) {
 | 
				
			||||||
 | 
						s.ClientTimeout = timeout
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
func (s *DelegatingAuthorizationOptions) Validate() []error {
 | 
					func (s *DelegatingAuthorizationOptions) Validate() []error {
 | 
				
			||||||
	allErrors := []error{}
 | 
						allErrors := []error{}
 | 
				
			||||||
	return allErrors
 | 
						return allErrors
 | 
				
			||||||
@@ -186,6 +196,7 @@ func (s *DelegatingAuthorizationOptions) getClient() (kubernetes.Interface, erro
 | 
				
			|||||||
	// set high qps/burst limits since this will effectively limit API server responsiveness
 | 
						// set high qps/burst limits since this will effectively limit API server responsiveness
 | 
				
			||||||
	clientConfig.QPS = 200
 | 
						clientConfig.QPS = 200
 | 
				
			||||||
	clientConfig.Burst = 400
 | 
						clientConfig.Burst = 400
 | 
				
			||||||
 | 
						clientConfig.Timeout = s.ClientTimeout
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return kubernetes.NewForConfig(clientConfig)
 | 
						return kubernetes.NewForConfig(clientConfig)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user