Skip to content

Commit 2160cbc

Browse files
committed
DelegatingAuthorizationOptions: exposes and sets a default timeout for SubjectAccessReview client
previously no timeout was set. Requests without explicit timeout might potentially hang forever and lead to starvation of the application.
1 parent a285e3f commit 2160cbc

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

cmd/cloud-controller-manager/app/options/options_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ func TestDefaultFlags(t *testing.T) {
116116
Authorization: &apiserveroptions.DelegatingAuthorizationOptions{
117117
AllowCacheTTL: 10 * time.Second,
118118
DenyCacheTTL: 10 * time.Second,
119+
ClientTimeout: 10 * time.Second,
119120
RemoteKubeConfigFileOptional: true,
120121
AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or
121122
},
@@ -248,6 +249,7 @@ func TestAddFlags(t *testing.T) {
248249
Authorization: &apiserveroptions.DelegatingAuthorizationOptions{
249250
AllowCacheTTL: 10 * time.Second,
250251
DenyCacheTTL: 10 * time.Second,
252+
ClientTimeout: 10 * time.Second,
251253
RemoteKubeConfigFileOptional: true,
252254
AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or
253255
},

cmd/kube-controller-manager/app/options/options_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,7 @@ func TestAddFlags(t *testing.T) {
417417
Authorization: &apiserveroptions.DelegatingAuthorizationOptions{
418418
AllowCacheTTL: 10 * time.Second,
419419
DenyCacheTTL: 10 * time.Second,
420+
ClientTimeout: 10 * time.Second,
420421
RemoteKubeConfigFileOptional: true,
421422
AlwaysAllowPaths: []string{"/healthz"}, // note: this does not match /healthz/ or /healthz/*
422423
},

staging/src/k8s.io/apiserver/pkg/server/options/authorization.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,18 @@ type DelegatingAuthorizationOptions struct {
5959

6060
// AlwaysAllowGroups are groups which are allowed to take any actions. In kube, this is system:masters.
6161
AlwaysAllowGroups []string
62+
63+
// ClientTimeout specifies a time limit for requests made by SubjectAccessReviews client.
64+
// The default value is set to 10 seconds.
65+
ClientTimeout time.Duration
6266
}
6367

6468
func NewDelegatingAuthorizationOptions() *DelegatingAuthorizationOptions {
6569
return &DelegatingAuthorizationOptions{
6670
// very low for responsiveness, but high enough to handle storms
6771
AllowCacheTTL: 10 * time.Second,
6872
DenyCacheTTL: 10 * time.Second,
73+
ClientTimeout: 10 * time.Second,
6974
}
7075
}
7176

@@ -81,6 +86,11 @@ func (s *DelegatingAuthorizationOptions) WithAlwaysAllowPaths(paths ...string) *
8186
return s
8287
}
8388

89+
// WithClientTimeout sets the given timeout for SAR client used by this authorizer
90+
func (s *DelegatingAuthorizationOptions) WithClientTimeout(timeout time.Duration) {
91+
s.ClientTimeout = timeout
92+
}
93+
8494
func (s *DelegatingAuthorizationOptions) Validate() []error {
8595
allErrors := []error{}
8696
return allErrors
@@ -186,6 +196,7 @@ func (s *DelegatingAuthorizationOptions) getClient() (kubernetes.Interface, erro
186196
// set high qps/burst limits since this will effectively limit API server responsiveness
187197
clientConfig.QPS = 200
188198
clientConfig.Burst = 400
199+
clientConfig.Timeout = s.ClientTimeout
189200

190201
return kubernetes.NewForConfig(clientConfig)
191202
}

0 commit comments

Comments
 (0)