@@ -30,6 +30,8 @@ import (
30
30
"k8s.io/apiserver/pkg/authentication/request/union"
31
31
"k8s.io/apiserver/pkg/authentication/request/websocket"
32
32
x509request "k8s.io/apiserver/pkg/authentication/request/x509"
33
+ tokencache "k8s.io/apiserver/pkg/authentication/token/cache"
34
+ tokenunion "k8s.io/apiserver/pkg/authentication/token/union"
33
35
"k8s.io/apiserver/pkg/authentication/user"
34
36
kauthorizer "k8s.io/apiserver/pkg/authorization/authorizer"
35
37
"k8s.io/apiserver/pkg/authorization/authorizerfactory"
@@ -913,7 +915,7 @@ func newServiceAccountTokenGetter(options configapi.MasterConfig) (serviceaccoun
913
915
914
916
func newAuthenticator (config configapi.MasterConfig , restOptionsGetter restoptions.Getter , tokenGetter serviceaccount.ServiceAccountTokenGetter , apiClientCAs * x509.CertPool , groupMapper identitymapper.UserToGroupMapper ) (authenticator.Request , error ) {
915
917
authenticators := []authenticator.Request {}
916
- tokenAuthenticators := []authenticator.Request {}
918
+ tokenAuthenticators := []authenticator.Token {}
917
919
918
920
// ServiceAccount token
919
921
if len (config .ServiceAccountConfig .PublicKeyFiles ) > 0 {
@@ -926,12 +928,7 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
926
928
publicKeys = append (publicKeys , readPublicKeys ... )
927
929
}
928
930
serviceAccountTokenAuthenticator := serviceaccount .JWTTokenAuthenticator (publicKeys , true , tokenGetter )
929
- tokenAuthenticators = append (
930
- tokenAuthenticators ,
931
- bearertoken .New (serviceAccountTokenAuthenticator ),
932
- websocket .NewProtocolAuthenticator (serviceAccountTokenAuthenticator ),
933
- paramtoken .New ("access_token" , serviceAccountTokenAuthenticator , true ),
934
- )
931
+ tokenAuthenticators = append (tokenAuthenticators , serviceAccountTokenAuthenticator )
935
932
}
936
933
937
934
// OAuth token
@@ -940,20 +937,26 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
940
937
if err != nil {
941
938
return nil , fmt .Errorf ("Error building OAuth token authenticator: %v" , err )
942
939
}
943
- oauthTokenRequestAuthenticators := []authenticator.Request {
944
- bearertoken .New (oauthTokenAuthenticator ),
945
- websocket .NewProtocolAuthenticator (oauthTokenAuthenticator ),
946
- paramtoken .New ("access_token" , oauthTokenAuthenticator , true ),
947
- }
948
-
949
940
tokenAuthenticators = append (tokenAuthenticators ,
950
941
// if you have a bearer token, you're a human (usually)
951
942
// if you change this, have a look at the impersonationFilter where we attach groups to the impersonated user
952
- group .NewGroupAdder ( union . New ( oauthTokenRequestAuthenticators ... ) , []string {bootstrappolicy .AuthenticatedOAuthGroup }))
943
+ group .NewTokenGroupAdder ( oauthTokenAuthenticator , []string {bootstrappolicy .AuthenticatedOAuthGroup }))
953
944
}
954
945
955
946
if len (tokenAuthenticators ) > 0 {
956
- authenticators = append (authenticators , union .New (tokenAuthenticators ... ))
947
+ // Combine all token authenticators
948
+ tokenAuth := tokenunion .New (tokenAuthenticators ... )
949
+
950
+ // wrap with short cache on success.
951
+ // this means a revoked service account token or access token will be valid for up to 10 seconds.
952
+ // it also means group membership changes on users may take up to 10 seconds to become effective.
953
+ tokenAuth = tokencache .New (tokenAuth , 10 * time .Second , 0 )
954
+
955
+ authenticators = append (authenticators ,
956
+ bearertoken .New (tokenAuth ),
957
+ websocket .NewProtocolAuthenticator (tokenAuth ),
958
+ paramtoken .New ("access_token" , tokenAuth , true ),
959
+ )
957
960
}
958
961
959
962
if configapi .UseTLS (config .ServingInfo .ServingInfo ) {
0 commit comments