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

Correctly pad oidc tokens #70

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions config/kube_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,15 @@ def _load_oid_token(self):
if len(parts) != 3: # Not a valid JWT
return None

padding = (4 - len(parts[1]) % 4) * '='

if PY3:
jwt_attributes = json.loads(
base64.b64decode(parts[1]).decode('utf-8')
base64.b64decode(parts[1] + padding).decode('utf-8')
)
else:
jwt_attributes = json.loads(
base64.b64decode(parts[1] + "==")
base64.b64decode(parts[1] + padding)
)

expire = jwt_attributes.get('exp')
Expand Down
4 changes: 2 additions & 2 deletions config/kube_config_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ def _raise_exception(st):

TEST_OIDC_TOKEN = "test-oidc-token"
TEST_OIDC_INFO = "{\"name\": \"test\"}"
TEST_OIDC_BASE = _base64(TEST_OIDC_TOKEN) + "." + _base64(TEST_OIDC_INFO)
TEST_OIDC_BASE = _base64(TEST_OIDC_TOKEN).strip('=') + "." + _base64(TEST_OIDC_INFO).strip('=')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like the length of the changed lines in this file is what makes the travis job complain. I get this output when I test the styleguide locally:

$ pycodestyle config/kube_config*
config/kube_config_test.py:90:80: E501 line too long (95 > 79 characters)
config/kube_config_test.py:94:80: E501 line too long (98 > 79 characters)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TEST_OIDC_BASE = _base64(TEST_OIDC_TOKEN).strip('=') + "." + _base64(TEST_OIDC_INFO).strip('=')
TEST_OIDC_BASE = _base64(TEST_OIDC_TOKEN).strip(
'=') + "." + _base64(TEST_OIDC_INFO).strip('=')

TEST_OIDC_LOGIN = TEST_OIDC_BASE + "." + TEST_CLIENT_CERT_BASE64
TEST_OIDC_TOKEN = "Bearer %s" % TEST_OIDC_LOGIN
TEST_OIDC_EXP = "{\"name\": \"test\",\"exp\": 536457600}"
TEST_OIDC_EXP_BASE = _base64(TEST_OIDC_TOKEN) + "." + _base64(TEST_OIDC_EXP)
TEST_OIDC_EXP_BASE = _base64(TEST_OIDC_TOKEN).strip('=') + "." + _base64(TEST_OIDC_EXP).strip('=')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TEST_OIDC_EXP_BASE = _base64(TEST_OIDC_TOKEN).strip('=') + "." + _base64(TEST_OIDC_EXP).strip('=')
TEST_OIDC_EXP_BASE = _base64(TEST_OIDC_TOKEN).strip(
'=') + "." + _base64(TEST_OIDC_EXP).strip('=')

TEST_OIDC_EXPIRED_LOGIN = TEST_OIDC_EXP_BASE + "." + TEST_CLIENT_CERT_BASE64
TEST_OIDC_CA = _base64(TEST_CERTIFICATE_AUTH)

Expand Down