This repository has been archived by the owner on Mar 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 185
Fix base64 padding for kube config #79
Merged
roycaihw
merged 5 commits into
kubernetes-client:master
from
bpicolo:fix_base64_padding_for_kconfig
Jun 19, 2019
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
529a72a
Fix base64 padding for kube config
bpicolo d54efa7
Merge branch 'master' into fix_base64_padding_for_kconfig
bpicolo 4750aa9
Add additional checks + test case fixes
bpicolo b3ddbd9
Add tests for updated pieces
bpicolo 72a02cc
Merge remote-tracking branch 'upstream/master' into fix_base64_paddin…
bpicolo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -276,18 +276,31 @@ def _load_oid_token(self, provider): | |
if 'config' not in provider: | ||
return | ||
|
||
parts = provider['config']['id-token'].split('.') | ||
reserved_characters = frozenset(["=", "+", "/"]) | ||
token = provider['config']['id-token'] | ||
|
||
if any(char in token for char in reserved_characters): | ||
# Invalid jwt, as it contains url-unsafe chars | ||
return | ||
|
||
parts = token.split('.') | ||
if len(parts) != 3: # Not a valid JWT | ||
return None | ||
return | ||
|
||
padding = (4 - len(parts[1]) % 4) * '=' | ||
if len(padding) == 3: | ||
# According to spec, 3 padding characters cannot occur | ||
# in a valid jwt | ||
# https://tools.ietf.org/html/rfc7515#appendix-C | ||
return | ||
|
||
if PY3: | ||
jwt_attributes = json.loads( | ||
base64.b64decode(parts[1]).decode('utf-8') | ||
base64.b64decode(parts[1] + padding).decode('utf-8') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. JWT requires There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be still worthwhile to do safe decode here? |
||
) | ||
else: | ||
jwt_attributes = json.loads( | ||
base64.b64decode(parts[1] + "==") | ||
base64.b64decode(parts[1] + padding) | ||
) | ||
|
||
expire = jwt_attributes.get('exp') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a check to make sure the JWT doesn't contain url reserved characters (
=
,+
and/
)?