Skip to content

fix(k8s): k8s:// service requests authenticate with the Kubernetes client's own auth settings, and the pod informer watches through the typed list call #1432

Closed

Description

@dan-petty

Problem

Lines cited at 05e9388 (release/v0.2.29).

  • Token clusters get anonymous requests.
    • _auth_headers (k8s/service_proxy.py:223-234) turns each configuration.api_key entry into a header of the same name. Only a key literally named authorization is mapped.
    • kubernetes 36.0.3 stores the token under BearerToken (kubernetes/config/kube_config.py:530, kubernetes/config/incluster_config.py:91).
    • So the proxied request carries a BearerToken: Bearer … header, and the API server treats it as anonymous.
    • Only client-certificate kubeconfigs work. In-cluster service accounts, OIDC, exec plugins and static tokens do not.
    • The client's own Configuration.auth_settings() (kubernetes/client/configuration.py:401-421) maps the key to Authorization, and it is not used.
  • The token is read once.
    • _kube_configuration caches the configuration on the context and the kubeconfig's mtime (service_proxy.py:171). It loads in-cluster configuration first (:177-185).
    • The client's refresh_api_key_hook is never called.
    • Inside a pod there is no kubeconfig, so the mtime key never changes.
  • The informer gets untyped objects.
    • PodInformer.stream_events passes a lambda to Watch.stream (k8s/informer.py:109-116). Watch reads the return type from the list function's docstring, so for a namespaced watch it finds none and yields raw dicts.
    • The status projection then falls back to the phase (:43), which the docstring at :33-34 rules out.
    • The reconnect loop (:156-168) has no backoff and does not resume from the last resourceVersion.
  • The docs overstate the check.
    • AGENTS.md:468 lists the Kubernetes API among the connectors checked at the connect.
    • The k8s:// proxy is checked (factory, private level). The in-process kubernetes client is not: it dials through urllib3.

Proposed remedy

  • Proxy auth. Build the proxy's headers per request from configuration.auth_settings(), after calling configuration.refresh_api_key_hook when one is set.
  • Informer.
    • Call w.stream(core_v1.list_namespaced_pod, namespace=..., **kwargs), or list_pod_for_all_namespaces, without a wrapper.
    • Reconnect with tenacity's exponential backoff (tenacity is already a dependency), resuming from the last seen resourceVersion.
    • Relist on 410 Gone.
  • AGENTS.md:468. Correct it to say the k8s:// proxy and the cluster-service clients are checked at the connect. The in-process kubernetes client (urllib3) is not. It is trusted because its address comes from the operator's kubeconfig or the in-cluster environment.

Acceptance criteria

  • With a token kubeconfig and with an in-cluster token, the request recorded at the HTTP fake carries Authorization: Bearer <token> and no BearerToken header.
  • A client-certificate kubeconfig still works.
  • A refresh hook that rotates the token is called before each request, and the new token is sent.
  • Namespaced and all-namespace watches yield V1Pod objects from refactor(k8s): KubernetesService is the Kubernetes API seam, with a shared fake cluster and its contract suite #1315's fake cluster.
  • A persistent watch error backs off instead of looping, and a reconnect passes the last resourceVersion.
  • AGENTS.md:468 says which Kubernetes clients are checked at the connect and which are not.
  • Tests run offline with fakes only at process and HTTP edges; each new test runs under 1 s.
  • uv run devops ci passes.

Related: #1315, #1314, #1322, #898.

Found by the 2026-10-08 client-library audit.

Opened as a borrow (#1153, budget/borrowed): the agent filing quota is spent for this cycle, and this is a defect or security finding of the owner-requested 2026-10-08 client-library audit.

Activity

  1. added
    type/bug
    scope/k8s
    source/agent
    on Oct 8, 2026
  2. dan-petty-bot commented on Oct 8, 2026

    @dan-petty-bot
    Collaborator

    Intake placed this item to the backlog: at intake only a critical fix goes into a release; a release start pulls Ready items in, P0 features first.

    • Priority: P1-High. The k8s:// proxy is non-functional for in-cluster service accounts, OIDC, exec plugins, and static tokens—i.e. the majority of real-world cluster configurations—making it a core-functionality break.
    • Value: High. Without the fix the proxy is unusable for any token-based cluster, which is the dominant authentication model in production Kubernetes.
    • Effort: Medium. Requires rewriting header construction from auth_settings(), wiring the refresh hook, switching the informer to typed list calls, adding tenacity backoff with resourceVersion resume, and a one-line docs correction across a handful of files.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope/k8ssource/agenttype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions