@@ -29,6 +29,8 @@ import (
29
29
"k8s.io/apiserver/pkg/authentication/request/union"
30
30
"k8s.io/apiserver/pkg/authentication/request/websocket"
31
31
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"
32
34
"k8s.io/apiserver/pkg/authentication/user"
33
35
kauthorizer "k8s.io/apiserver/pkg/authorization/authorizer"
34
36
"k8s.io/apiserver/pkg/authorization/authorizerfactory"
@@ -924,7 +926,7 @@ func newServiceAccountTokenGetter(options configapi.MasterConfig) (serviceaccoun
924
926
925
927
func newAuthenticator (config configapi.MasterConfig , restOptionsGetter restoptions.Getter , tokenGetter serviceaccount.ServiceAccountTokenGetter , apiClientCAs * x509.CertPool , groupMapper identitymapper.UserToGroupMapper ) (authenticator.Request , error ) {
926
928
authenticators := []authenticator.Request {}
927
- tokenAuthenticators := []authenticator.Request {}
929
+ tokenAuthenticators := []authenticator.Token {}
928
930
929
931
// ServiceAccount token
930
932
if len (config .ServiceAccountConfig .PublicKeyFiles ) > 0 {
@@ -937,12 +939,7 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
937
939
publicKeys = append (publicKeys , readPublicKeys ... )
938
940
}
939
941
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 )
946
943
}
947
944
948
945
// OAuth token
@@ -951,20 +948,26 @@ func newAuthenticator(config configapi.MasterConfig, restOptionsGetter restoptio
951
948
if err != nil {
952
949
return nil , fmt .Errorf ("Error building OAuth token authenticator: %v" , err )
953
950
}
954
- oauthTokenRequestAuthenticators := []authenticator.Request {
955
- bearertoken .New (oauthTokenAuthenticator ),
956
- websocket .NewProtocolAuthenticator (oauthTokenAuthenticator ),
957
- paramtoken .New ("access_token" , oauthTokenAuthenticator , true ),
958
- }
959
-
960
951
tokenAuthenticators = append (tokenAuthenticators ,
961
952
// if you have a bearer token, you're a human (usually)
962
953
// 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 }))
964
955
}
965
956
966
957
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
+ )
968
971
}
969
972
970
973
if configapi .UseTLS (config .ServingInfo .ServingInfo ) {
0 commit comments