@@ -29,6 +29,8 @@ import (
2929 "k8s.io/apiserver/pkg/authentication/request/union"
3030 "k8s.io/apiserver/pkg/authentication/request/websocket"
3131 x509request "k8s.io/apiserver/pkg/authentication/request/x509"
32+ tokencache "k8s.io/apiserver/pkg/authentication/token/cache"
33+ tokenunion "k8s.io/apiserver/pkg/authentication/token/union"
3234 "k8s.io/apiserver/pkg/authentication/user"
3335 kauthorizer "k8s.io/apiserver/pkg/authorization/authorizer"
3436 "k8s.io/apiserver/pkg/authorization/authorizerfactory"
@@ -924,7 +926,7 @@ func newServiceAccountTokenGetter(options configapi.MasterConfig) (serviceaccoun
924926
925927func newAuthenticator (config configapi.MasterConfig , restOptionsGetter restoptions.Getter , tokenGetter serviceaccount.ServiceAccountTokenGetter , apiClientCAs * x509.CertPool , groupMapper identitymapper.UserToGroupMapper ) (authenticator.Request , error ) {
926928 authenticators := []authenticator.Request {}
927- tokenAuthenticators := []authenticator.Request {}
929+ tokenAuthenticators := []authenticator.Token {}
928930
929931 // ServiceAccount token
930932 if len (config .ServiceAccountConfig .PublicKeyFiles ) > 0 {
@@ -937,12 +939,7 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
937939 publicKeys = append (publicKeys , readPublicKeys ... )
938940 }
939941 serviceAccountTokenAuthenticator := serviceaccount .JWTTokenAuthenticator (publicKeys , true , tokenGetter )
940- tokenAuthenticators = append (
941- tokenAuthenticators ,
942- bearertoken .New (serviceAccountTokenAuthenticator ),
943- websocket .NewProtocolAuthenticator (serviceAccountTokenAuthenticator ),
944- paramtoken .New ("access_token" , serviceAccountTokenAuthenticator , true ),
945- )
942+ tokenAuthenticators = append (tokenAuthenticators , serviceAccountTokenAuthenticator )
946943 }
947944
948945 // OAuth token
@@ -951,20 +948,26 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
951948 if err != nil {
952949 return nil , fmt .Errorf ("Error building OAuth token authenticator: %v" , err )
953950 }
954- oauthTokenRequestAuthenticators := []authenticator.Request {
955- bearertoken .New (oauthTokenAuthenticator ),
956- websocket .NewProtocolAuthenticator (oauthTokenAuthenticator ),
957- paramtoken .New ("access_token" , oauthTokenAuthenticator , true ),
958- }
959-
960951 tokenAuthenticators = append (tokenAuthenticators ,
961952 // if you have a bearer token, you're a human (usually)
962953 // if you change this, have a look at the impersonationFilter where we attach groups to the impersonated user
963- group .NewGroupAdder ( union . New ( oauthTokenRequestAuthenticators ... ) , []string {bootstrappolicy .AuthenticatedOAuthGroup }))
954+ group .NewTokenGroupAdder ( oauthTokenAuthenticator , []string {bootstrappolicy .AuthenticatedOAuthGroup }))
964955 }
965956
966957 if len (tokenAuthenticators ) > 0 {
967- authenticators = append (authenticators , union .New (tokenAuthenticators ... ))
958+ // Combine all token authenticators
959+ tokenAuth := tokenunion .New (tokenAuthenticators ... )
960+
961+ // wrap with short cache on success.
962+ // this means a revoked service account token or access token will be valid for up to 10 seconds.
963+ // it also means group membership changes on users may take up to 10 seconds to become effective.
964+ tokenAuth = tokencache .New (tokenAuth , 10 * time .Second , 0 )
965+
966+ authenticators = append (authenticators ,
967+ bearertoken .New (tokenAuth ),
968+ websocket .NewProtocolAuthenticator (tokenAuth ),
969+ paramtoken .New ("access_token" , tokenAuth , true ),
970+ )
968971 }
969972
970973 if configapi .UseTLS (config .ServingInfo .ServingInfo ) {
0 commit comments