@@ -37,7 +37,6 @@ import (
37
37
netutil "k8s.io/utils/net"
38
38
39
39
_ "k8s.io/kubernetes/pkg/features"
40
- kubeauthenticator "k8s.io/kubernetes/pkg/kubeapiserver/authenticator"
41
40
kubeoptions "k8s.io/kubernetes/pkg/kubeapiserver/options"
42
41
"k8s.io/kubernetes/pkg/serviceaccount"
43
42
)
@@ -230,49 +229,36 @@ func (o *Options) Complete(alternateDNS []string, alternateIPs []net.IP) (Comple
230
229
// adjust authentication for completed authorization
231
230
completed .Authentication .ApplyAuthorization (completed .Authorization )
232
231
233
- // Use (ServiceAccountSigningKeyFile != "") as a proxy to the user enabling
234
- // TokenRequest functionality. This defaulting was convenient, but messed up
235
- // a lot of people when they rotated their serving cert with no idea it was
236
- // connected to their service account keys. We are taking this opportunity to
237
- // remove this problematic defaulting.
238
- if completed .ServiceAccountSigningKeyFile == "" {
239
- // Default to the private server key for service account token signing
240
- if len (completed .Authentication .ServiceAccounts .KeyFiles ) == 0 && completed .SecureServing .ServerCert .CertKey .KeyFile != "" {
241
- if kubeauthenticator .IsValidServiceAccountKeyFile (completed .SecureServing .ServerCert .CertKey .KeyFile ) {
242
- completed .Authentication .ServiceAccounts .KeyFiles = []string {completed .SecureServing .ServerCert .CertKey .KeyFile }
243
- } else {
244
- klog .Warning ("No TLS key provided, service account token authentication disabled" )
232
+ // verify and adjust ServiceAccountTokenMaxExpiration
233
+ if completed .Authentication .ServiceAccounts .MaxExpiration != 0 {
234
+ lowBound := time .Hour
235
+ upBound := time .Duration (1 << 32 ) * time .Second
236
+ if completed .Authentication .ServiceAccounts .MaxExpiration < lowBound ||
237
+ completed .Authentication .ServiceAccounts .MaxExpiration > upBound {
238
+ return CompletedOptions {}, fmt .Errorf ("the service-account-max-token-expiration must be between 1 hour and 2^32 seconds" )
239
+ }
240
+ if completed .Authentication .ServiceAccounts .ExtendExpiration {
241
+ if completed .Authentication .ServiceAccounts .MaxExpiration < serviceaccount .WarnOnlyBoundTokenExpirationSeconds * time .Second {
242
+ klog .Warningf ("service-account-extend-token-expiration is true, in order to correctly trigger safe transition logic, service-account-max-token-expiration must be set longer than %d seconds (currently %s)" , serviceaccount .WarnOnlyBoundTokenExpirationSeconds , completed .Authentication .ServiceAccounts .MaxExpiration )
243
+ }
244
+ if completed .Authentication .ServiceAccounts .MaxExpiration < serviceaccount .ExpirationExtensionSeconds * time .Second {
245
+ klog .Warningf ("service-account-extend-token-expiration is true, enabling tokens valid up to %d seconds, which is longer than service-account-max-token-expiration set to %s seconds" , serviceaccount .ExpirationExtensionSeconds , completed .Authentication .ServiceAccounts .MaxExpiration )
245
246
}
246
247
}
247
248
}
249
+ completed .ServiceAccountTokenMaxExpiration = completed .Authentication .ServiceAccounts .MaxExpiration
248
250
249
- if completed .ServiceAccountSigningKeyFile != "" && len (completed .Authentication .ServiceAccounts .Issuers ) != 0 && completed .Authentication .ServiceAccounts .Issuers [0 ] != "" {
250
- sk , err := keyutil .PrivateKeyFromFile (completed .ServiceAccountSigningKeyFile )
251
- if err != nil {
252
- return CompletedOptions {}, fmt .Errorf ("failed to parse service-account-issuer-key-file: %v" , err )
253
- }
254
- if completed .Authentication .ServiceAccounts .MaxExpiration != 0 {
255
- lowBound := time .Hour
256
- upBound := time .Duration (1 << 32 ) * time .Second
257
- if completed .Authentication .ServiceAccounts .MaxExpiration < lowBound ||
258
- completed .Authentication .ServiceAccounts .MaxExpiration > upBound {
259
- return CompletedOptions {}, fmt .Errorf ("the service-account-max-token-expiration must be between 1 hour and 2^32 seconds" )
251
+ if len (completed .Authentication .ServiceAccounts .Issuers ) != 0 && completed .Authentication .ServiceAccounts .Issuers [0 ] != "" {
252
+ if completed .ServiceAccountSigningKeyFile != "" {
253
+ sk , err := keyutil .PrivateKeyFromFile (completed .ServiceAccountSigningKeyFile )
254
+ if err != nil {
255
+ return CompletedOptions {}, fmt .Errorf ("failed to parse service-account-issuer-key-file: %w" , err )
260
256
}
261
- if completed .Authentication .ServiceAccounts .ExtendExpiration {
262
- if completed .Authentication .ServiceAccounts .MaxExpiration < serviceaccount .WarnOnlyBoundTokenExpirationSeconds * time .Second {
263
- klog .Warningf ("service-account-extend-token-expiration is true, in order to correctly trigger safe transition logic, service-account-max-token-expiration must be set longer than %d seconds (currently %s)" , serviceaccount .WarnOnlyBoundTokenExpirationSeconds , completed .Authentication .ServiceAccounts .MaxExpiration )
264
- }
265
- if completed .Authentication .ServiceAccounts .MaxExpiration < serviceaccount .ExpirationExtensionSeconds * time .Second {
266
- klog .Warningf ("service-account-extend-token-expiration is true, enabling tokens valid up to %d seconds, which is longer than service-account-max-token-expiration set to %s seconds" , serviceaccount .ExpirationExtensionSeconds , completed .Authentication .ServiceAccounts .MaxExpiration )
267
- }
257
+ completed .ServiceAccountIssuer , err = serviceaccount .JWTTokenGenerator (completed .Authentication .ServiceAccounts .Issuers [0 ], sk )
258
+ if err != nil {
259
+ return CompletedOptions {}, fmt .Errorf ("failed to build token generator: %w" , err )
268
260
}
269
261
}
270
-
271
- completed .ServiceAccountIssuer , err = serviceaccount .JWTTokenGenerator (completed .Authentication .ServiceAccounts .Issuers [0 ], sk )
272
- if err != nil {
273
- return CompletedOptions {}, fmt .Errorf ("failed to build token generator: %v" , err )
274
- }
275
- completed .ServiceAccountTokenMaxExpiration = completed .Authentication .ServiceAccounts .MaxExpiration
276
262
}
277
263
278
264
for key , value := range completed .APIEnablement .RuntimeConfig {
0 commit comments