Skip to content

Commit 8155327

Browse files
authored
Merge pull request kubernetes#127902 from p0lyn0mial/upstream-system-authenticated-for-system-apiserver
server/config: assing system:apiserver user to system:authenticated group
2 parents 7ab8a2b + dfeb560 commit 8155327

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ func AuthorizeClientBearerToken(loopback *restclient.Config, authn *Authenticati
11701170
tokens[privilegedLoopbackToken] = &user.DefaultInfo{
11711171
Name: user.APIServerUser,
11721172
UID: uid,
1173-
Groups: []string{user.SystemPrivilegedGroup},
1173+
Groups: []string{user.AllAuthenticated, user.SystemPrivilegedGroup},
11741174
}
11751175

11761176
tokenAuthenticator := authenticatorfactory.NewFromTokens(tokens, authn.APIAudiences)

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"k8s.io/apiserver/pkg/audit/policy"
3939
"k8s.io/apiserver/pkg/authentication/authenticator"
4040
"k8s.io/apiserver/pkg/authentication/user"
41+
"k8s.io/apiserver/pkg/authorization/authorizer"
4142
"k8s.io/apiserver/pkg/endpoints/request"
4243
"k8s.io/apiserver/pkg/server/healthz"
4344
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -83,6 +84,34 @@ func TestAuthorizeClientBearerTokenNoops(t *testing.T) {
8384
}
8485
}
8586

87+
func TestAuthorizeClientBearerTokenRequiredGroups(t *testing.T) {
88+
fakeAuthenticator := authenticator.RequestFunc(func(req *http.Request) (*authenticator.Response, bool, error) {
89+
return &authenticator.Response{User: &user.DefaultInfo{}}, false, nil
90+
})
91+
fakeAuthorizer := authorizer.AuthorizerFunc(func(ctx context.Context, a authorizer.Attributes) (authorizer.Decision, string, error) {
92+
return authorizer.DecisionAllow, "", nil
93+
})
94+
target := &rest.Config{BearerToken: "secretToken"}
95+
authN := &AuthenticationInfo{Authenticator: fakeAuthenticator}
96+
authC := &AuthorizationInfo{Authorizer: fakeAuthorizer}
97+
98+
AuthorizeClientBearerToken(target, authN, authC)
99+
100+
fakeRequest, err := http.NewRequest("", "", nil)
101+
if err != nil {
102+
t.Fatal(err)
103+
}
104+
fakeRequest.Header.Set("Authorization", "bearer secretToken")
105+
rsp, _, err := authN.Authenticator.AuthenticateRequest(fakeRequest)
106+
if err != nil {
107+
t.Fatal(err)
108+
}
109+
expectedGroups := []string{user.AllAuthenticated, user.SystemPrivilegedGroup}
110+
if !reflect.DeepEqual(expectedGroups, rsp.User.GetGroups()) {
111+
t.Fatalf("unexpected groups = %v returned, expected = %v", rsp.User.GetGroups(), expectedGroups)
112+
}
113+
}
114+
86115
func TestNewWithDelegate(t *testing.T) {
87116
_, ctx := ktesting.NewTestContext(t)
88117
ctx, cancel := context.WithCancelCause(ctx)

0 commit comments

Comments
 (0)