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

Commit 4e5e565

Browse files
bpicoloroycaihw
authored andcommitted
Fix base64 padding for kube config
1 parent 2d69e89 commit 4e5e565

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
@@ -273,13 +273,15 @@ def _load_oid_token(self, provider):
273273
if len(parts) != 3: # Not a valid JWT
274274
return None
275275

276+
padding = (4 - len(parts[1]) % 4) * '='
277+
276278
if PY3:
277279
jwt_attributes = json.loads(
278-
base64.b64decode(parts[1]).decode('utf-8')
280+
base64.b64decode(parts[1] + padding).decode('utf-8')
279281
)
280282
else:
281283
jwt_attributes = json.loads(
282-
base64.b64decode(parts[1] + "==")
284+
base64.b64decode(parts[1] + padding)
283285
)
284286

285287
expire = jwt_attributes.get('exp')

config/kube_config_test.py

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

5151

52+
def _unpadded_base64(string):
53+
return base64.b64encode(string.encode()).decode().rstrip('=')
54+
55+
5256
def _format_expiry_datetime(dt):
5357
return dt.strftime(EXPIRY_DATETIME_FORMAT)
5458

@@ -96,11 +100,13 @@ def _raise_exception(st):
96100

97101
TEST_OIDC_TOKEN = "test-oidc-token"
98102
TEST_OIDC_INFO = "{\"name\": \"test\"}"
99-
TEST_OIDC_BASE = _base64(TEST_OIDC_TOKEN) + "." + _base64(TEST_OIDC_INFO)
103+
TEST_OIDC_BASE = _unpadded_base64(
104+
TEST_OIDC_TOKEN) + "." + _unpadded_base64(TEST_OIDC_INFO)
100105
TEST_OIDC_LOGIN = TEST_OIDC_BASE + "." + TEST_CLIENT_CERT_BASE64
101106
TEST_OIDC_TOKEN = "Bearer %s" % TEST_OIDC_LOGIN
102107
TEST_OIDC_EXP = "{\"name\": \"test\",\"exp\": 536457600}"
103-
TEST_OIDC_EXP_BASE = _base64(TEST_OIDC_TOKEN) + "." + _base64(TEST_OIDC_EXP)
108+
TEST_OIDC_EXP_BASE = _unpadded_base64(
109+
TEST_OIDC_TOKEN) + "." + _unpadded_base64(TEST_OIDC_EXP)
104110
TEST_OIDC_EXPIRED_LOGIN = TEST_OIDC_EXP_BASE + "." + TEST_CLIENT_CERT_BASE64
105111
TEST_OIDC_CA = _base64(TEST_CERTIFICATE_AUTH)
106112

0 commit comments

Comments
 (0)