@@ -474,11 +474,31 @@ def _load_from_exec_plugin(self):
474
474
return
475
475
try :
476
476
status = ExecProvider (self ._user ['exec' ]).run ()
477
- if 'token' not in status :
478
- logging .error ('exec: missing token field in plugin output' )
479
- return None
480
- self .token = "Bearer %s" % status ['token' ]
481
- return True
477
+ if 'token' in status :
478
+ self .token = "Bearer %s" % status ['token' ]
479
+ return True
480
+ if 'clientCertificateData' in status :
481
+ # https://kubernetes.io/docs/reference/access-authn-authz/authentication/#input-and-output-formats
482
+ # Plugin has provided certificates instead of a token.
483
+ if 'clientKeyData' not in status :
484
+ logging .error ('exec: missing clientKeyData field in '
485
+ 'plugin output' )
486
+ return None
487
+ base_path = self ._get_base_path (self ._cluster .path )
488
+ self .cert_file = FileOrData (
489
+ status , None ,
490
+ data_key_name = 'clientCertificateData' ,
491
+ file_base_path = base_path ,
492
+ base64_file_content = False ).as_file ()
493
+ self .key_file = FileOrData (
494
+ status , None ,
495
+ data_key_name = 'clientKeyData' ,
496
+ file_base_path = base_path ,
497
+ base64_file_content = False ).as_file ()
498
+ return True
499
+ logging .error ('exec: missing token or clientCertificateData field '
500
+ 'in plugin output' )
501
+ return None
482
502
except Exception as e :
483
503
logging .error (str (e ))
484
504
@@ -514,12 +534,16 @@ def _load_cluster_info(self):
514
534
self .ssl_ca_cert = FileOrData (
515
535
self ._cluster , 'certificate-authority' ,
516
536
file_base_path = base_path ).as_file ()
517
- self .cert_file = FileOrData (
518
- self ._user , 'client-certificate' ,
519
- file_base_path = base_path ).as_file ()
520
- self .key_file = FileOrData (
521
- self ._user , 'client-key' ,
522
- file_base_path = base_path ).as_file ()
537
+ if 'cert_file' not in self .__dict__ :
538
+ # cert_file could have been provided by
539
+ # _load_from_exec_plugin; only load from the _user
540
+ # section if we need it.
541
+ self .cert_file = FileOrData (
542
+ self ._user , 'client-certificate' ,
543
+ file_base_path = base_path ).as_file ()
544
+ self .key_file = FileOrData (
545
+ self ._user , 'client-key' ,
546
+ file_base_path = base_path ).as_file ()
523
547
if 'insecure-skip-tls-verify' in self ._cluster :
524
548
self .verify_ssl = not self ._cluster ['insecure-skip-tls-verify' ]
525
549
0 commit comments