Repository navigation
fix(k8s): pin kubernetes client below 36 and self-heal on 401 - #74
Merged
Merged
Conversation
kubernetes-client 36.0.0 breaks in-cluster auth outright: the regenerated
Configuration.auth_settings() reads api_key['BearerToken'] while
load_incluster_config's loader still writes api_key['authorization'], so
auth_settings() returns {} and every API request is sent with no
Authorization header. The API server answers 401 forever (observed on AKS
as continuous 401s that survive pod restarts). Verified empirically:
34.1.0 and 35.0.0 emit the bearer header and pick up kubelet-rotated
tokens; 36.0.0 emits no auth settings at all.
- Pin kubernetes>=34.1.0,<36 (resolves to 35.0.0, verified good).
- Add tests that fail if a future bump reintroduces this class of
regression (auth_settings empty, or rotated token not refreshed).
- Add throttled reset-on-401 recovery: ApiException handlers now call
handle_unauthorized(e.status), which drops the cached CoreV1Api/
BatchV1Api so the next call reloads config and re-reads the on-disk
ServiceAccount token instead of failing until restart.
Fixes #72
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
🎉 This PR is included in version 3.6.2 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Background: #72 reported continuous 401s from the Kubernetes API after upgrading to 3.6.0 on AKS, surviving pod restarts, with the only auth-relevant change being the kubernetes client bump 34.1.0 -> 36.0.0. I went looking for the actual regression instead of just pinning blind, and it turned out to be worse than a stale-token bug - client 36.0.0 can't authenticate in-cluster at all. The regenerated
Configuration.auth_settings()gates onapi_key['BearerToken'], whileload_incluster_config's loader (byte-identical across 34/35/36) still writesapi_key['authorization']- soauth_settings()returns{}and every request goes out with no Authorization header. The reported "ran fine for ~3.5 days then broke" was likely the old ReplicaSet still serving until something forced the new image to actually take over.kubernetes>=34.1.0,<36(resolves to 35.0.0, which I verified behaves like 34.1.0)auth_settings()must be non-empty for in-cluster config, and a kubelet-rotated token must be served after the cached one expires. these fail on 36.0.0, so a future lockfile bump can't silently reintroduce this class of breakageApiExceptionhandlers in pool.py/job_executor.py now callhandle_unauthorized(e.status), which drops the cachedCoreV1Api/BatchV1Apiso the next call reloads config and re-reads the on-disk SA token instead of failing until restart. throttled to once per 30s so a persistent RBAC problem doesn't turn into config-reload thrashTesting
I reproduced the regression directly against all 3 client versions with fake in-cluster token files (rewrite token, expire the cache, re-read auth settings):
Full unit suite passes with the pin in place:
1529 passed. The newtests/unit/test_kubernetes_client_auth.pycovers the loader regression plus the 401 reset/throttle behavior.Review Strategy
The pin is the actual fix; the 401 recovery is belt-and-braces for future stale-token failures - if you'd rather ship the pin alone, the recovery commit is separable.
Fixes #72
🤖 Generated with Claude Code