Skip to content

Commit 2a2b294

Browse files
authored
Merge pull request kubernetes#107644 from liggitt/integration-test-user-groups
Fix up integration test user groups
2 parents 582aa7d + 57e0c59 commit 2a2b294

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

test/integration/auth/accessreview_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ func (sarAuthorizer) Authorize(ctx context.Context, a authorizer.Attributes) (au
4949
func alwaysAlice(req *http.Request) (*authenticator.Response, bool, error) {
5050
return &authenticator.Response{
5151
User: &user.DefaultInfo{
52-
Name: "alice",
52+
Name: "alice",
53+
UID: "alice",
54+
Groups: []string{user.AllAuthenticated},
5355
},
5456
}, true, nil
5557
}
@@ -149,7 +151,11 @@ func TestSelfSubjectAccessReview(t *testing.T) {
149151
controlPlaneConfig := framework.NewIntegrationTestControlPlaneConfig()
150152
controlPlaneConfig.GenericConfig.Authentication.Authenticator = authenticator.RequestFunc(func(req *http.Request) (*authenticator.Response, bool, error) {
151153
return &authenticator.Response{
152-
User: &user.DefaultInfo{Name: username},
154+
User: &user.DefaultInfo{
155+
Name: username,
156+
UID: username,
157+
Groups: []string{user.AllAuthenticated},
158+
},
153159
}, true, nil
154160
})
155161
controlPlaneConfig.GenericConfig.Authorization.Authorizer = sarAuthorizer{}

test/integration/auth/auth_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ func testWebhookTokenAuthenticator(customDialer bool, t *testing.T) {
14051405

14061406
// Set up an API server
14071407
controlPlaneConfig := framework.NewIntegrationTestControlPlaneConfig()
1408-
controlPlaneConfig.GenericConfig.Authentication.Authenticator = authenticator
1408+
controlPlaneConfig.GenericConfig.Authentication.Authenticator = group.NewAuthenticatedGroupAdder(authenticator)
14091409
controlPlaneConfig.GenericConfig.Authorization.Authorizer = allowAliceAuthorizer{}
14101410
_, s, closeFn := framework.RunAnAPIServer(controlPlaneConfig)
14111411
defer closeFn()

test/integration/auth/bootstraptoken_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
corev1 "k8s.io/api/core/v1"
2828
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2929
"k8s.io/apimachinery/pkg/labels"
30+
"k8s.io/apiserver/pkg/authentication/group"
3031
"k8s.io/apiserver/pkg/authentication/request/bearertoken"
3132
bootstrapapi "k8s.io/cluster-bootstrap/token/api"
3233
"k8s.io/kubernetes/plugin/pkg/auth/authenticator/token/bootstrap"
@@ -115,7 +116,7 @@ func TestBootstrapTokenAuth(t *testing.T) {
115116
}
116117
for _, test := range tests {
117118

118-
authenticator := bearertoken.New(bootstrap.NewTokenAuthenticator(bootstrapSecrets{test.secret}))
119+
authenticator := group.NewAuthenticatedGroupAdder(bearertoken.New(bootstrap.NewTokenAuthenticator(bootstrapSecrets{test.secret})))
119120
// Set up an API server
120121
controlPlaneConfig := framework.NewIntegrationTestControlPlaneConfig()
121122
controlPlaneConfig.GenericConfig.Authentication.Authenticator = authenticator

test/integration/auth/rbac_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"k8s.io/apimachinery/pkg/runtime/schema"
3535
"k8s.io/apimachinery/pkg/types"
3636
"k8s.io/apimachinery/pkg/watch"
37+
"k8s.io/apiserver/pkg/authentication/group"
3738
"k8s.io/apiserver/pkg/authentication/request/bearertoken"
3839
"k8s.io/apiserver/pkg/authentication/token/tokenfile"
3940
"k8s.io/apiserver/pkg/authentication/user"
@@ -521,7 +522,7 @@ func TestRBAC(t *testing.T) {
521522
// Create an API Server.
522523
controlPlaneConfig := framework.NewIntegrationTestControlPlaneConfig()
523524
controlPlaneConfig.GenericConfig.Authorization.Authorizer = newRBACAuthorizer(t, controlPlaneConfig)
524-
controlPlaneConfig.GenericConfig.Authentication.Authenticator = bearertoken.New(tokenfile.New(map[string]*user.DefaultInfo{
525+
controlPlaneConfig.GenericConfig.Authentication.Authenticator = group.NewAuthenticatedGroupAdder(bearertoken.New(tokenfile.New(map[string]*user.DefaultInfo{
525526
superUser: {Name: "admin", Groups: []string{"system:masters"}},
526527
"any-rolebinding-writer": {Name: "any-rolebinding-writer"},
527528
"any-rolebinding-writer-namespace": {Name: "any-rolebinding-writer-namespace"},
@@ -533,7 +534,7 @@ func TestRBAC(t *testing.T) {
533534
"limitrange-updater": {Name: "limitrange-updater"},
534535
"limitrange-patcher": {Name: "limitrange-patcher"},
535536
"user-with-no-permissions": {Name: "user-with-no-permissions"},
536-
}))
537+
})))
537538
controlPlaneConfig.GenericConfig.OpenAPIConfig = framework.DefaultOpenAPIConfig()
538539
_, s, closeFn := framework.RunAnAPIServer(controlPlaneConfig)
539540
defer closeFn()

test/integration/serviceaccount/service_account_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"k8s.io/apimachinery/pkg/util/sets"
3838
"k8s.io/apimachinery/pkg/util/wait"
3939
"k8s.io/apiserver/pkg/authentication/authenticator"
40+
"k8s.io/apiserver/pkg/authentication/group"
4041
"k8s.io/apiserver/pkg/authentication/request/bearertoken"
4142
"k8s.io/apiserver/pkg/authentication/request/union"
4243
serviceaccountapiserver "k8s.io/apiserver/pkg/authentication/serviceaccount"
@@ -355,10 +356,10 @@ func startServiceAccountTestServer(t *testing.T) (*clientset.Clientset, restclie
355356
externalInformers.Core().V1().Pods().Lister(),
356357
)
357358
serviceAccountTokenAuth := serviceaccount.JWTTokenAuthenticator([]string{serviceaccount.LegacyIssuer}, []interface{}{&serviceAccountKey.PublicKey}, nil, serviceaccount.NewLegacyValidator(true, serviceAccountTokenGetter))
358-
authenticator := union.New(
359+
authenticator := group.NewAuthenticatedGroupAdder(union.New(
359360
bearertoken.New(rootTokenAuth),
360361
bearertoken.New(serviceAccountTokenAuth),
361-
)
362+
))
362363

363364
// Set up a stub authorizer:
364365
// 1. The "root" user is allowed to do anything

0 commit comments

Comments
 (0)