python icon indicating copy to clipboard operation
python copied to clipboard

load_kube_config fails when decode a not safe url token

Open uelei opened this issue 4 years ago • 10 comments

What happened (please include outputs or screenshots): load_kube_config fails when decode a not safe url token

config.load_kube_config()
  File "/Users/user/Library/Caches/pypoetry/virtualenvs/dev-helpers-ydB7Fkd--py3.10/lib/python3.10/site-packages/kubernetes/config/kube_config.py", line 820, in load_kube_config
    loader.load_and_set(config)
  File "/Users/user/Library/Caches/pypoetry/virtualenvs/dev-helpers-ydB7Fkd--py3.10/lib/python3.10/site-packages/kubernetes/config/kube_config.py", line 590, in load_and_set
    self._load_authentication()
  File "/Users/user/Library/Caches/pypoetry/virtualenvs/dev-helpers-ydB7Fkd--py3.10/lib/python3.10/site-packages/kubernetes/config/kube_config.py", line 288, in _load_authentication
    if self._load_auth_provider_token():
  File "/Users/user/Library/Caches/pypoetry/virtualenvs/dev-helpers-ydB7Fkd--py3.10/lib/python3.10/site-packages/kubernetes/config/kube_config.py", line 307, in _load_auth_provider_token
    return self._load_oid_token(provider)
  File "/Users/user/Library/Caches/pypoetry/virtualenvs/dev-helpers-ydB7Fkd--py3.10/lib/python3.10/site-packages/kubernetes/config/kube_config.py", line 399, in _load_oid_token
    base64.b64decode(parts[1] + padding).decode('utf-8')
  File "/usr/local/Cellar/[email protected]/3.10.6_2/Frameworks/Python.framework/Versions/3.10/lib/python3.10/base64.py", line 87, in b64decode
    return binascii.a2b_base64(s)
binascii.Error: Invalid base64-encoded string: number of data characters (1509) cannot be 1 more than a multiple of 4

What you expected to happen: load correctly the token

How to reproduce it (as minimally and precisely as possible): change your ~/.kube/config id-token to

eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjB1b3pGdlFxZEJEaFNXSWNGYXFDQyJ9.eyJodXRoYW1lIjoicm5lY2siLCJuYW1lIjoicm5lY2siLCJwaWN0dXJlIjoiaHR0cHM6Ly9zLmdyYXZhdGFyLmNvbS9hdmF0YXIvZWI0MWUwMDQwNDI0NjZlODhhYzQ5MTY5MjQwZWE2N2U_cz00ODAmcj1wZyZkPWh0dHBzJTNBJTJGJTJGY2RuLmF1dGgwLmNvbSUyRmF2YXRhcnMlMkZ3dy5wbmciLCJ1cGRhdGVkX2F0IjoiMjAyMi0xMC0wNlQxMjo1NTo0NC43NjhaIiwiZW1haWwiOiJ3ZXVja0BpbnZvbSIsImlzcyI6Imh0dHBzOi8vaXRhZS1kZXYuYXV0LyIsInN1YiI6InNhbWxwfEluYS1EZXZ8Y2tAZS5jb20iLCJhdWQiOiJHTjQ1UDlzc2tpbzRXTHZTckF6NktQVHM4YWpNRGtrbSIsImlhdCI6MTY2NTA2MzcwMiwiZXhwIjoxNjUwMTAyfQ.p8yypFnPXEr1qbMikqGYWOKwZnUJ-jIQRCiSH24hwuL_SuvaMQ4lntlqMkOxOs7rUkyiDJmPpzM-t7qpMdwquWP08FslgOwNkbRpip43vEenJDsdOePHu9PsJ-mP6SNg6obj_v8o7u5vgp44C2Ov5O-ml06prBcmejCKduvDt3veb_ACgZ6L-w1xigHzfD6nJ5c2CHByXHG1Kkri_Gks2YUVJX8eAOnbZhjeQ9fiwHMJ2sKbP_nJJe1B6VqNTmqFgToKv7BeO2UVcgf-1kJF_-RClfD6ciOf0dFsGvoPgqXiLHfR2zVggTwSZFvT0L3vYTbWkBpTdFzLMJyzcCYNqQ

on python repr

from kubernetes import config
config.load_kube_config()

Anything else we need to know?:

changing this line to

 base64.urlsafe_b64decode(parts[1] + padding).decode('utf-8')

solves the issue

Environment:

  • Kubernetes version v1.25.0
  • OS MacOS 12.12
  • Python version 3.10.6
  • Python client version 23.3.0

uelei avatar Oct 07 '22 18:10 uelei

So only base64.urlsafe_b64decode(parts[1] + padding).decode('utf-8') this had to be added sir

ramvikrams avatar Oct 09 '22 19:10 ramvikrams

Exactly.

uelei avatar Oct 10 '22 16:10 uelei

Sir can I make up the changes then

ramvikrams avatar Oct 10 '22 16:10 ramvikrams

Sure.

uelei avatar Oct 10 '22 16:10 uelei

/assign @ramvikrams Thank you!

roycaihw avatar Oct 10 '22 16:10 roycaihw

thanks sir I will start working on it

ramvikrams avatar Oct 10 '22 16:10 ramvikrams

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-triage-robot avatar Jan 08 '23 17:01 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

k8s-triage-robot avatar Feb 07 '23 18:02 k8s-triage-robot

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

k8s-triage-robot avatar Mar 09 '23 18:03 k8s-triage-robot

@k8s-triage-robot: Closing this issue, marking it as "Not Planned".

In response to this:

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Reopen this issue with /reopen
  • Mark this issue as fresh with /remove-lifecycle rotten
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/close not-planned

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

k8s-ci-robot avatar Mar 09 '23 18:03 k8s-ci-robot