Skip to content

fix(storage/kubernetes): only bracket IPv6 literals in in-cluster API host - #78

Merged
mridulgain merged 3 commits into
masterfrom
private/master/mg/fix-kubernetes-inclusterconfig-ipv4-bracket
Sep 3, 2026
Merged

fix(storage/kubernetes): only bracket IPv6 literals in in-cluster API host#78
mridulgain merged 3 commits into
masterfrom
private/master/mg/fix-kubernetes-inclusterconfig-ipv4-bracket

Conversation

@mridulgain

@mridulgain mridulgain commented Sep 2, 2026

Copy link
Copy Markdown

Summary

  • inClusterConfig() unconditionally wrapped KUBERNETES_SERVICE_HOST in [...]. Go's net/url only accepts brackets around a valid IPv6 literal, so any cluster with an IPv4 kubernetes Service ClusterIP (the common case) fails with invalid IP-literal and dex crash-loops on startup (cannot get kubernetes version).
  • Extracted the bracketing logic into formatKubernetesHost(), which brackets only actual IPv6 literals.
  • Found while verifying KAAP-2257 (fix(KAAP-2257): separate public redirect host from internal API host #77) against a QA image built with a newer Go toolchain, which tightened net/url validation and exposed this pre-existing bug (code unchanged since 2020).

Investigation

  1. dex pod is clb
❯ k get po dex-test-du-ciprsmoke-5092765-7d557694dd-t787q  -n test-du-ciprsmoke-5092765
NAME                                             READY   STATUS             RESTARTS         AGE
dex-test-du-ciprsmoke-5092765-7d557694dd-t787q   0/1     CrashLoopBackOff   50 (4m11s ago)   3h55m

kubectl logs ... --previous revealed: invalid IP-literal parse error from failed to initialize storage: cannot get kubernetes version: parse "https://[10.96.0.1]:443/version"

Test plan

  • go test ./storage/kubernetes/...
  • Reproduced and confirmed the fix resolves url.Parse failure for an IPv4 host locally

QA verification

Built image: quay.io/platform9/pf9-dex:v2025.10.0-6-g19e9bf3f from this branch & patched the deploy,ment.

Result: pod came up clean, 1/1 Running, 0 restarts (vs. 50 restarts / CrashLoopBackOff before).

In the logs: (kubectl logs -n test-du-ciprsmoke-5092765 -l app.kubernetes.io/name=dex --tail=100)

  1. Storage init succeeded (past the point where it previously crashed):
time=2026-09-02T12:06:13.569Z level=INFO msg="kubernetes client" api_version=dex.coreos.com/v1
time=2026-09-02T12:06:13.584Z level=INFO msg="creating custom Kubernetes resources"
...
time=2026-09-02T12:06:13.720Z level=INFO msg="config storage" storage_type=kubernetes
  1. keystonefed-idp1 connector loaded:
time=2026-09-02T12:06:13.720Z level=INFO msg="config connector" connector_id=default
time=2026-09-02T12:06:13.720Z level=INFO msg="config connector" connector_id=keystonefed-idp1
  1. Signing keys rotated:
time=2026-09-02T12:06:13.810Z level=INFO msg="keys expired, rotating"
time=2026-09-02T12:06:13.890Z level=INFO msg="keys rotated" next_rotation=2026-09-02T18:06:13.874Z
  1. All servers listening:
time=2026-09-02T12:06:13.890Z level=INFO msg="listening on" server=telemetry address=0.0.0.0:5558
time=2026-09-02T12:06:13.890Z level=INFO msg="listening on" server=http address=0.0.0.0:5556
time=2026-09-02T12:06:13.891Z level=INFO msg="listening on" server=https address=0.0.0.0:5554
time=2026-09-02T12:06:13.891Z level=INFO msg="listening on" server=grpc address=0.0.0.0:5557

… host

inClusterConfig() unconditionally wrapped KUBERNETES_SERVICE_HOST in
square brackets, assuming that was safe for IPv4 too. It isn't: Go's
net/url only accepts brackets around a valid IPv6 literal, so any
cluster with an IPv4 kubernetes Service ClusterIP (the common case)
fails config parsing with "invalid IP-literal" and dex crash-loops on
startup ("cannot get kubernetes version").

Bracket only when the host actually parses as a non-IPv4 IP (i.e.
IPv6); leave IPv4 addresses and hostnames unwrapped.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mridulgain mridulgain self-assigned this Sep 2, 2026
@mridulgain
mridulgain requested review from a team and srm6867 September 2, 2026 12:07
srm6867
srm6867 previously approved these changes Sep 2, 2026
google.golang.org/grpc v1.83.0 has CVE-2026-84304, and
golang.org/x/mod v0.38.0 has CVE-2026-56864/CVE-2026-56865 (a GOSUMDB
transparency-log verification bypass). Bump both across all three
modules (root, api/v2, examples) as flagged by the Trivy Security
Scan on PR #78.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
mridulgain added a commit that referenced this pull request Sep 3, 2026
google.golang.org/grpc v1.83.0 has CVE-2026-84304, and
golang.org/x/mod v0.38.0 has CVE-2026-56864/CVE-2026-56865 (a GOSUMDB
transparency-log verification bypass). Bump both across all three
modules (root, api/v2, examples) as flagged by the Trivy Security
Scan on PR #78.

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
@mridulgain
mridulgain merged commit 72fcced into master Sep 3, 2026
12 checks passed
@mridulgain
mridulgain deleted the private/master/mg/fix-kubernetes-inclusterconfig-ipv4-bracket branch September 3, 2026 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants