Skip to content

Commit a807cb6

Browse files
authored
Merge pull request kubernetes#79153 from MikeSpreitzer/fix73409
Make AuthorizeClientBearerToken actually return if authn or authz is nil
2 parents b3c6e21 + 7056e21 commit a807cb6

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

staging/src/k8s.io/apiserver/pkg/server/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ func AuthorizeClientBearerToken(loopback *restclient.Config, authn *Authenticati
662662
}
663663
if authn == nil || authz == nil {
664664
// prevent nil pointer panic
665+
return
665666
}
666667
if authn.Authenticator == nil || authz.Authorizer == nil {
667668
// authenticator or authorizer might be nil if we want to bypass authz/authn

staging/src/k8s.io/apiserver/pkg/server/config_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"net/http"
2424
"net/http/httptest"
2525
"net/http/httputil"
26+
"reflect"
2627
"testing"
2728

2829
"k8s.io/apimachinery/pkg/util/sets"
@@ -32,6 +33,39 @@ import (
3233
"k8s.io/client-go/rest"
3334
)
3435

36+
func TestAuthorizeClientBearerTokenNoops(t *testing.T) {
37+
// All of these should do nothing (not panic, no side-effects)
38+
cfgGens := []func() *rest.Config{
39+
func() *rest.Config { return nil },
40+
func() *rest.Config { return &rest.Config{} },
41+
func() *rest.Config { return &rest.Config{BearerToken: "mu"} },
42+
}
43+
authcGens := []func() *AuthenticationInfo{
44+
func() *AuthenticationInfo { return nil },
45+
func() *AuthenticationInfo { return &AuthenticationInfo{} },
46+
}
47+
authzGens := []func() *AuthorizationInfo{
48+
func() *AuthorizationInfo { return nil },
49+
func() *AuthorizationInfo { return &AuthorizationInfo{} },
50+
}
51+
for _, cfgGen := range cfgGens {
52+
for _, authcGen := range authcGens {
53+
for _, authzGen := range authzGens {
54+
pConfig := cfgGen()
55+
pAuthc := authcGen()
56+
pAuthz := authzGen()
57+
AuthorizeClientBearerToken(pConfig, pAuthc, pAuthz)
58+
if before, after := authcGen(), pAuthc; !reflect.DeepEqual(before, after) {
59+
t.Errorf("AuthorizeClientBearerToken(%v, %#+v, %v) changed %#+v", pConfig, pAuthc, pAuthz, *before)
60+
}
61+
if before, after := authzGen(), pAuthz; !reflect.DeepEqual(before, after) {
62+
t.Errorf("AuthorizeClientBearerToken(%v, %v, %#+v) changed %#+v", pConfig, pAuthc, pAuthz, *before)
63+
}
64+
}
65+
}
66+
}
67+
}
68+
3569
func TestNewWithDelegate(t *testing.T) {
3670
delegateConfig := NewConfig(codecs)
3771
delegateConfig.ExternalAddress = "192.168.10.4:443"

0 commit comments

Comments
 (0)