Skip to content

Configuration.auth_settings() returns empty dict in v36.0.0 - all BearerToken-authed requests go anonymous #2582

Closed

Description

@jmacek

What happened

Upgrading from kubernetes==35.0.0 to kubernetes==36.0.0 causes every API request that relies on a Bearer token (the in-cluster ServiceAccount auth path, or any caller that sets Configuration.api_key['authorization'] directly) to be sent without an Authorization header. The server treats the request as system:anonymous and rejects it (401 on AKS, 403 on minikube).

Minimal reproducer

Direct check of the method the generated API operations call to attach auth headers before sending HTTP requests:

from kubernetes import client

cfg = client.Configuration()
cfg.api_key['authorization'] = 'Bearer fake-token'

api = client.ApiClient(cfg)
headers = {}
api.update_params_for_auth(headers, [], ['BearerToken'])
print('headers:', headers)

Expected output (matches v35.0.0)

headers: {'authorization': 'Bearer fake-token'}

Actual output on v36.0.0

headers: {}

The Bearer-token-aware code path is silently a no-op. The HTTP request goes out with no Authorization header and the server treats it as system:anonymous.

Supporting evidence

Configuration.auth_settings() - which update_params_for_auth reads to find scheme definitions - is also empty on v36:

>>> cfg.auth_settings()                # v35: {'BearerToken': {...}}
{}                                     # v36

So the regression is at the Configuration level: the BearerToken scheme entry that should be present in auth_settings() (and is in v35) is missing in v36, which cascades into update_params_for_auth having nothing to apply.

Impact

Any pod doing in-cluster API calls via this library is broken on v36.0.0 - including (but not limited to) callers of CoordinationV1Api, CoreV1Api, etc. We caught this when our Lease-coordinated workload pods started failing every read_namespaced_lease call with 401 immediately after a rebuild upgraded the lib from v35 to v36.

Environment

  • kubernetes==36.0.0 (uploaded to PyPI 2026-05-20T20:44Z)
  • Python 3.12 / 3.13 (reproduced on both)
  • Linux container (also reproduced on macOS in a clean venv)

Regression window

The bug is present in the entire 36-series:

Version PyPI upload update_params_for_auth result
v35.0.0 2026-01-16 populates {'authorization': 'Bearer ...'}
v36.0.0a3 2026-05-08 empty {} (regression introduced here)
v36.0.0b1 2026-05-13 empty {}
v36.0.0 2026-05-20 empty {}

So the regression was present from the first 36-series prerelease and shipped to stable without a fix. The diff between v35.0.0..v36.0.0a3 should contain the offending change.

Workaround

Pin kubernetes>=29,<36 until a v36 patch ships.

Hypothesis (haven't dug in further)

This looks like the OpenAPI/swagger-driven code generation for Configuration regressed - the dict literal that defines the BearerToken entry under auth_settings() likely got dropped or scoped out. Worth diffing the generated Configuration class between v35.0.0 and v36.0.0.

Activity

  1. added
    kind/bug
    on May 20, 2026
  2. changed the title [-]`Configuration.auth_settings()` returns empty dict in v36.0.0 - all BearerToken-authed requests go anonymous`[/-] [+]`Configuration.auth_settings()` returns empty dict in v36.0.0 - all BearerToken-authed requests go anonymous[/+] on May 20, 2026
  3. jhostetler commented on May 21, 2026

    @jhostetler

    Also experiencing this issue. Requests to create resources succeed using version 35.0.0 but raise a 403 with 36.0.0

  4. MaZderMind commented on May 21, 2026

    @MaZderMind

    Works like this with 36.0.0:

        credentials, _ = google.auth.default(
            scopes=["https://www.googleapis.com/auth/cloud-platform"]
        )
        credentials.refresh(google.auth.transport.requests.Request())
    
        configuration = client.Configuration()
        configuration.host = os.environ["K8S_CLUSTER_ENDPOINT"]
        configuration.ssl_ca_cert = os.environ["K8S_CLUSTER_CA_CERT"]  # type: ignore[assignment]
        configuration.api_key = {"BearerToken": credentials.token}
        configuration.api_key_prefix = {"BearerToken": "Bearer"}
    
  5. jmacek commented on May 21, 2026

    @jmacek
    ContributorAuthor

    Thanks, that workaround is useful - confirmed it works on a clean v36.0.0 venv.

    Worth being clear that it's a workaround, not the intended path. Diffing v35.0.0 vs v36.0.0 makes the mismatch concrete:

    kubernetes/client/configuration.py::auth_settings() was changed to look up the bearer auth under a renamed key:

    - if 'authorization' in self.api_key:
    + if 'BearerToken' in self.api_key:
          ...
    -     'value': self.get_api_key_with_prefix('authorization')
    +     'value': self.get_api_key_with_prefix('BearerToken')

    Manual construction with api_key={"BearerToken": ...} + api_key_prefix={"BearerToken": "Bearer"} (what your snippet does) is the intended new API for that key, and it works.

    What appears to have been missed is updating the loader side to match. kubernetes/base/config/incluster_config.py is byte-identical between v35.0.0 and v36.0.0 and still writes the old key:

    # v36.0.0 incluster_config.py, line 91 - unchanged from v35
    client_configuration.api_key['authorization'] = self.token

    kube_config.py has the same issue at line 542 (only unrelated changes between v35/v36 - the adal removal). So auth_settings() was renamed without the two canonical entry points being updated to write the new key. The result is that any caller using load_incluster_config() or load_kube_config() on v36 gets unauthenticated requests with no error - the Authorization header is silently dropped.

    For folks pinned to v36 who can't change their load_incluster_config() callsites, the equivalent post-load fix is:

    from kubernetes import client, config
    
    config.load_incluster_config()
    cfg = client.Configuration.get_default_copy()
    token = cfg.api_key.pop("authorization", "").removeprefix("bearer ").removeprefix("Bearer ")
    cfg.api_key = {"BearerToken": token}
    cfg.api_key_prefix = {"BearerToken": "Bearer"}
    client.Configuration.set_default(cfg)

    Same idea as yours, adapted to patch the Configuration after load_incluster_config() writes the stale shape. Pinning kubernetes<36 also works if a code change isn't an option - and is probably the safer choice short-term since the workaround becomes dead code once load_incluster_config() is fixed upstream.

    Proper fix would be either updating load_incluster_config() (and load_kube_config for parity) to write the new shape, or making auth_settings() accept the old shape as a fallback. I'll put up a PR with the loader-side fix shortly.

  6. added a commit that references this issue on Jun 2, 2026
  7. anastasiyatolstikenableu commented on Jun 30, 2026

    @anastasiyatolstikenableu

    Pinned kubernetes==35.0.0 to keep the operator image on the last verified working Kubernetes Python client version.

    We compared the images:

    • previous working image: kubernetes==35.0.0
    • rebuilt failing image: kubernetes==36.0.2

    With 36.0.2, Kopf logs authentication as successful, but Kubernetes API requests are handled as system:anonymous. This is similar to the upstream regression described in #2592. Although that issue is marked fixed upstream, we still reproduce the behavior with 36.0.2 in our operator image, so we pin to 35.0.0 until a newer client version is verified in our cluster.

    Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions