@@ -265,11 +265,9 @@ def set_active_context(self, context_name=None):
265
265
266
266
def _load_authentication (self ):
267
267
"""Read authentication from kube-config user section if exists.
268
-
269
268
This function goes through various authentication methods in user
270
269
section of kube-config and stops if it finds a valid authentication
271
270
method. The order of authentication methods is:
272
-
273
271
1. auth-provider (gcp, azure, oidc)
274
272
2. token field (point to a token file)
275
273
3. exec provided plugin
@@ -368,31 +366,36 @@ def _load_oid_token(self, provider):
368
366
if 'config' not in provider :
369
367
return
370
368
371
- reserved_characters = frozenset ([ "=" , "+" , "/" ])
369
+ urlunsafe_revision = { "=" : "" , "+" : "-" , "/" : "_" }
372
370
token = provider ['config' ]['id-token' ]
373
371
374
- if any (char in token for char in reserved_characters ):
375
- # Invalid jwt, as it contains url-unsafe chars
376
- return
372
+ if any (char in token for char in urlunsafe_revision . keys () ):
373
+ for key , value in urlunsafe_revision . items ():
374
+ token = token . replace ( key , value )
377
375
378
376
parts = token .split ('.' )
379
- if len (parts ) != 3 : # Not a valid JWT
380
- return
377
+ if len (parts ) != 3 :
378
+ # Not a valid JWT
379
+ raise ConfigException (
380
+ 'Invalid kube-config file. '
381
+ 'Not a vaild oidc token' )
381
382
382
383
padding = (4 - len (parts [1 ]) % 4 ) * '='
383
384
if len (padding ) == 3 :
384
385
# According to spec, 3 padding characters cannot occur
385
386
# in a valid jwt
386
387
# https://tools.ietf.org/html/rfc7515#appendix-C
387
- return
388
+ raise ConfigException (
389
+ 'Invalid kube-config file. '
390
+ 'Not a vaild oidc token' )
388
391
389
392
if PY3 :
390
393
jwt_attributes = json .loads (
391
- base64 .b64decode (parts [1 ] + padding ).decode ('utf-8' )
394
+ base64 .urlsafe_b64decode (parts [1 ] + padding ).decode ('utf-8' )
392
395
)
393
396
else :
394
397
jwt_attributes = json .loads (
395
- base64 .b64decode (parts [1 ] + padding )
398
+ base64 .urlsafe_b64decode (parts [1 ] + padding )
396
399
)
397
400
398
401
expire = jwt_attributes .get ('exp' )
@@ -416,11 +419,11 @@ def _refresh_oidc(self, provider):
416
419
ca_cert = tempfile .NamedTemporaryFile (delete = True )
417
420
418
421
if PY3 :
419
- cert = base64 .b64decode (
422
+ cert = base64 .urlsafe_b64decode (
420
423
provider ['config' ]['idp-certificate-authority-data' ]
421
424
).decode ('utf-8' )
422
425
else :
423
- cert = base64 .b64decode (
426
+ cert = base64 .urlsafe_b64decode (
424
427
provider ['config' ]['idp-certificate-authority-data' ] + "=="
425
428
)
426
429
@@ -655,10 +658,8 @@ class KubeConfigMerger:
655
658
656
659
"""Reads and merges configuration from one or more kube-config's.
657
660
The propery `config` can be passed to the KubeConfigLoader as config_dict.
658
-
659
661
It uses a path attribute from ConfigNode to store the path to kubeconfig.
660
662
This path is required to load certs from relative paths.
661
-
662
663
A method `save_changes` updates changed kubeconfig's (it compares current
663
664
state of dicts with).
664
665
"""
@@ -776,7 +777,6 @@ def load_kube_config(config_file=None, context=None,
776
777
persist_config = True ):
777
778
"""Loads authentication and cluster information from kube-config file
778
779
and stores them in kubernetes.client.configuration.
779
-
780
780
:param config_file: Name of the kube-config file.
781
781
:param context: set the active context. If is set to None, current_context
782
782
from config file will be used.
@@ -806,7 +806,6 @@ def load_kube_config_from_dict(config_dict, context=None,
806
806
persist_config = True ):
807
807
"""Loads authentication and cluster information from config_dict file
808
808
and stores them in kubernetes.client.configuration.
809
-
810
809
:param config_dict: Takes the config file as a dict.
811
810
:param context: set the active context. If is set to None, current_context
812
811
from config file will be used.
0 commit comments