Skip to content
This repository was archived by the owner on Mar 13, 2022. It is now read-only.

Commit 8bee2f8

Browse files
bpicoloroycaihw
authored andcommitted
Fix base64 padding for kube config
1 parent 5c242ea commit 8bee2f8

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

config/kube_config.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,15 @@ def _load_oid_token(self, provider):
264264
if len(parts) != 3: # Not a valid JWT
265265
return None
266266

267+
padding = (4 - len(parts[1]) % 4) * '='
268+
267269
if PY3:
268270
jwt_attributes = json.loads(
269-
base64.b64decode(parts[1]).decode('utf-8')
271+
base64.b64decode(parts[1] + padding).decode('utf-8')
270272
)
271273
else:
272274
jwt_attributes = json.loads(
273-
base64.b64decode(parts[1] + "==")
275+
base64.b64decode(parts[1] + padding)
274276
)
275277

276278
expire = jwt_attributes.get('exp')

config/kube_config_test.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def _base64(string):
4747
return base64.standard_b64encode(string.encode()).decode()
4848

4949

50+
def _unpadded_base64(string):
51+
return base64.b64encode(string.encode()).decode().rstrip('=')
52+
53+
5054
def _format_expiry_datetime(dt):
5155
return dt.strftime(EXPIRY_DATETIME_FORMAT)
5256

@@ -94,11 +98,13 @@ def _raise_exception(st):
9498

9599
TEST_OIDC_TOKEN = "test-oidc-token"
96100
TEST_OIDC_INFO = "{\"name\": \"test\"}"
97-
TEST_OIDC_BASE = _base64(TEST_OIDC_TOKEN) + "." + _base64(TEST_OIDC_INFO)
101+
TEST_OIDC_BASE = _unpadded_base64(
102+
TEST_OIDC_TOKEN) + "." + _unpadded_base64(TEST_OIDC_INFO)
98103
TEST_OIDC_LOGIN = TEST_OIDC_BASE + "." + TEST_CLIENT_CERT_BASE64
99104
TEST_OIDC_TOKEN = "Bearer %s" % TEST_OIDC_LOGIN
100105
TEST_OIDC_EXP = "{\"name\": \"test\",\"exp\": 536457600}"
101-
TEST_OIDC_EXP_BASE = _base64(TEST_OIDC_TOKEN) + "." + _base64(TEST_OIDC_EXP)
106+
TEST_OIDC_EXP_BASE = _unpadded_base64(
107+
TEST_OIDC_TOKEN) + "." + _unpadded_base64(TEST_OIDC_EXP)
102108
TEST_OIDC_EXPIRED_LOGIN = TEST_OIDC_EXP_BASE + "." + TEST_CLIENT_CERT_BASE64
103109
TEST_OIDC_CA = _base64(TEST_CERTIFICATE_AUTH)
104110

0 commit comments

Comments
 (0)