Skip to content

Connection diagnostics: Kubernetes API or backend failure behind port-forward is reported as missing password or TLS/firewall #1069

Closed

Description

Found while testing the #1066 VSIX (CI run 42252782123, ab9ce33) on Windows 11 / VS Code 1.143.1 against the kind lab from scripts/k8s-test-setup.sh (DKO 1.0.0, ClusterIP service, port-forward).

When the Kubernetes side fails behind the port-forward tunnel, Diagnose Connection… blames the wrong layer. The manual says an unreachable Kubernetes API is reported in Connection settings and the check stops there (diagnose-connection.md).

API server unreachable (podman stop documentdb-dev-control-plane, then Diagnose on the discovered my-documentdb). Same result in a fresh session and with an existing tunnel:

  • Connection settings: warning, "Port forward ready", "Stored password unavailable"
  • TLS: failed, "Secure handshake closed … A firewall or IP allowlist may be blocking this connection"
  • Result: Connection not tested, "Connect to the cluster and enter the password, then run the diagnosis again"

No ready pods behind the service (selector patched to match nothing):

  • Result: Connection failed at Secure connection (TLS), "Secure handshake closed", plus the firewall hint

In both cases the real cause is only in the DocumentDB output channel, not in the panel or the report:

Port-forward backend resolution failed for documentdb-ns/documentdb-service-my-documentdb: request to https://127.0.0.1:<api-port>/api/v1/namespaces/documentdb-ns/endpoints/documentdb-service-my-documentdb failed, reason: connect ECONNREFUSED
Port-forward backend resolution failed for documentdb-ns/documentdb-service-my-documentdb: No ready pods found backing service "documentdb-service-my-documentdb" in namespace "documentdb-ns".

These lines carry no run= tag, so filtering the log by the report's run ID hides them. In the no-pods case, Authentication also runs after TLS has failed and waits out the driver's 30 s server-selection timeout.

A second tester reproduced all three runs (API down with a fresh tunnel, API down with an existing tunnel, no ready pods) in a separate VS Code profile.

Likely cause. The tunnel binds locally and resolves its backend pod on each incoming connection, so prepare reports success without contacting the API. The diagnostic credential read (KubernetesResourceItem → resolveDocumentDBCredentials, kubernetesClient.ts) catches every Secret/API error and returns undefined, so an API failure turns into "Stored password unavailable".

Expected. In diagnostic mode, prepare checks the backend (ready pod, through the API) before reporting the tunnel as ready, and fails Connection settings with the Kubernetes error. The credential read tells "API unreachable / forbidden" apart from "Secret has no password".

Recovery works: once the API or the selector is restored, a re-run passes.

Activity

  1. tnaum-ms commented on Nov 9, 2026

    @tnaum-ms
    Collaborator

    Status: addressed in #1066. The PR is open and ready for review, not merged yet.

    Root causes

    1. prepare reported Port forward ready as soon as it bound a local listener. The tunnel resolves its Kubernetes backend only when a connection arrives, so prepare never contacted the Kubernetes API or the service's endpoints.
    2. The diagnostic credential read turned every Kubernetes API error into "no credentials", so an unreachable API showed up as Stored password unavailable.
    3. The TCP and TLS probes then reached a local listener that accepted the connection and closed it. Those transport failures were worded as a server closing the handshake, with firewall advice, even for 127.0.0.1.

    What changed, by reported case

    API server unreachable (fresh or existing tunnel)

    • 0168783a (WI-K2): in diagnostic mode, prepare checks the Kubernetes backend (a ready pod on the service port, through the API) before it starts or reuses the tunnel. If the check fails, no new tunnel is started and an existing shared tunnel is left open.
    • b1c184a9 (WI-K3, l10n 60ccb72a): new prepare.failed finding with a bounded reason (sourceUnreachable, accessDenied, targetNotFound, noReadyBackend, sourceMissing, other) and Kubernetes wording, reported under Connection settings. The probes and Authentication that depend on it are skipped. No raw messages or names enter the results, and the finding code appears in the run's Output trace.
    • bc124a25 (WI-K1): strict diagnostic credential read, so Kubernetes API failures are no longer shown as a missing password. A Secret that can't be read (403/404) gives a specific Authentication skip instead of "enter the password". Ordinary connect, copy and save keep their best-effort behavior. Operator-approved exception: for generic services only, a 403 on the DKO resource list is ignored and the read continues to the annotated Secret. Network failures still propagate, and DKO services stay strict.

    No ready pods behind the service

    • Covered by the same prepare check: reported as no ready backend under Connection settings. TLS and Authentication no longer run, so the 30 s server-selection wait is gone too.

    TLS / firewall wording

    • 1cd90a0f (WI-G1): transport findings now record the address class. The TLS-closed title and explanation are neutral for every address. When every failing target is loopback, there is no firewall hint and the next steps are loopback-specific. This also fixes direct loopback connections, such as a stopped DocumentDB Local container. Public, mixed and unknown addresses keep the previous advice.

    Tests and docs

    • e9a8ae9e (WI-K4): TDD: Kubernetes diagnosis regression tests for the three cases (API down with a fresh tunnel, API down with an existing tunnel, no ready pods). They use the real runner, provider, tunnel manager and loopback sockets, and assert that no TLS, firewall or missing-password headline appears.
    • 99a34497 (WI-D1): user manual, feature design, reachability-provider contract and decision record.
    • Follow-ups: 2fd30d49 (type-only lint fix) and 0c54e890 (localization and formatting).

    Follow-up from manual testing today

    3d5e18e6, ba52502f, 6df3937f, 13753953:

    • The Connection settings summary says Using port forward.
    • An info finding, Kubernetes port forward stays open, says whether the port forward was started or reused and why it stays open. It also says the port forward closes when the VS Code window is closed or reloaded.
    • Connection settings details show the Kubernetes context, namespace, service:port, local port, started or reused, and that a ready pod was found at check time. The Host is marked as the local end of the port forward.
    • With Hide identifiers, the report redacts the kube context (new kubeContext identifier kind), the namespace and the service.

    Not done / limitations

    • WI-K5 (the tunnel remembers its last backend failure): excluded by operator decision.
    • WI-K6 (provider sub-steps in the report): deferred, not part of the accepted path.
    • WI-V1 (manual outage verification): still open. Only read-only feasibility checks were run on the kind lab: control plane running, /readyz ok, pod and EndpointSlice ready. Actual Diagnose runs under the outage cases are unverified, because inducing outages on the shared lab was judged unsafe. The fixed behavior is covered by automated tests, which are not a substitute for the manual outage experiment.
    • Pre-existing, unchanged: a reused port forward is matched without the service port.

    How to verify

    On the kind lab from scripts/k8s-test-setup.sh, diagnose the discovered my-documentdb:

    1. API down: docker stop documentdb-dev-control-plane (or podman). Run Diagnose with and without an existing tunnel. Expected: the run fails at Connection settings with the Kubernetes API reason, and there is no TLS, firewall or missing-password headline. Start the container again afterwards.
    2. No ready pods: save the selector first (kubectl -n documentdb-ns get svc documentdb-service-my-documentdb -o jsonpath='{.spec.selector}'), patch it to match nothing, then run Diagnose. Expected: a no-ready-pods reason under Connection settings and no 30 s Authentication wait. Restore the selector afterwards; the operator may reconcile it back, so check before diagnosing.
    3. Healthy: run Diagnose again. Expected: it passes, Connection settings shows Using port forward with the port-forward details, and the "stays open" info finding appears.
    4. Optional: stop a DocumentDB Local container and diagnose its saved connection (loopback wording, no firewall hint). Then diagnose a direct Azure connection to confirm the direct path is unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions