Skip to content

feat(k8s): the kube api is reachable off the home network at k8s.<domain> through the cloudflare tunnel, behind access, with kubectl over cloudflared access tcp #1595

Closed

Description

@dan-petty

Friction

Off the home network, a workstation cannot reach the cluster's API server: the kubeconfig points at the node's LAN address, so kubectl and every devops k8s command fail with "connection refused". The Cloudflare Tunnel already serves the cluster's web services at *.<domain>, but nothing serves the API.

Evidence

  • The tunnel's ingress (devops cloudflare tunnel routes) holds *.<domain> and <domain> → Traefik, then the 404 catch-all. k8s.<domain> matches the wildcard, and Traefik has no route for it.
  • The Access application "Homelab Wildcard Ingress" already gates *.<domain> (devops cloudflare access status), so k8s.<domain> needs no new application.
  • An HTTP hostname cannot carry the API: Cloudflare terminates TLS at its edge, which drops kubectl's client certificate. Cloudflare's documented pattern for kubectl is a tcp:// origin reached with cloudflared access tcp on the client, which keeps TLS end to end between kubectl and the API server.
  • k8s/cloudflared/networkpolicy.yaml allows cloudflared egress on 443, 7844 and to Traefik, not 6443. kubernetes.default.svc:443 is rewritten to the API server's endpoint on port 6443 before kube-router checks egress, so the policy most likely drops the traffic. k8s/argocd/networkpolicy.yaml (rule 3) shows how other namespaces allow the API server, and lines 43-48 of the cloudflared policy record kube-router's trouble with rules that combine to: and ports:.
  • devops cloudflare tunnel sync adds new hostnames after the existing rules, just before the catch-all (src/devops_cli/cloudflare/client.py:145-149). Because cloudflared takes the first matching rule, a host added with it under an existing wildcard is never reached.
  • cloudflared is not a managed binary: it is absent from src/devops_cli/tools_lock/tools.lock and the devcontainer.

Remedy

  1. Allow cloudflared egress to the API server on 6443 in k8s/cloudflared/networkpolicy.yaml, written in the form kube-router enforces, with a test next to the existing network policy tests.
  2. Route k8s.<domain> to tcp://kubernetes.default.svc.cluster.local:443. Fix tunnel sync so that a specific hostname is placed before any wildcard rule that would match it, with a test of the merged order, and record the route in k8s/README.md.
  3. Add cloudflared to tools.lock with sha256-pinned downloads per platform, so devops install-tools installs it.
  4. Document the workstation side in k8s/README.md: cloudflared access tcp --hostname k8s.<domain> --url 127.0.0.1:<port>, and a kubeconfig context whose server is https://127.0.0.1:<port> with tls-server-name: kubernetes.default.svc, reusing the cluster's credentials. A command that keeps the forward running can follow as its own item.

Pending a person: after the release reaches main, kubectl --context <tunnel-context> get nodes from off the home network returns the nodes after the Access login.

Proposed design

Problem statement

Users cannot access the Kubernetes API server from off the home network because the kubeconfig points to a LAN address, and the Cloudflare Tunnel does not route k8s. to the API server. The tunnel already serves web services at *., but kubectl requires TCP routing through cloudflared access tcp with end-to-end TLS.

Acceptance criteria

  • Criterion 1: The network policy allows cloudflared egress to the Kubernetes API server on port 6443
    Verification: Run kubectl -n cloudflared get networkpolicy cloudflared-isolation -o yaml and verify that a rule exists allowing egress to the API server on port 6443
  • Criterion 2: The Cloudflare tunnel routes k8s. to the API server via TCP
    Verification: Run devops cloudflare tunnel routes and verify that a route exists for k8s. pointing to tcp://kubernetes.default.svc.cluster.local:443
  • Criterion 3: The tunnel sync command correctly places specific hostnames before wildcard rules
    Verification: Run devops cloudflare tunnel sync --subdomains k8s --service tcp://kubernetes.default.svc.cluster.local:443 --dry-run and verify the hostname is placed before wildcard rules
  • Criterion 4: cloudflared is available in the devops tools lock
    Verification: Check that src/devops_cli/tools_lock/tools.lock contains a [binary.cloudflared] section with platform-specific entries for all supported platforms
  • Criterion 5: kubectl can connect to the cluster through the tunnel from off-network
    Verification: Run kubectl --context get nodes using a configured context that uses cloudflared access tcp, and verify it returns the list of nodes after successful Access login

Key questions

  • What specific network policy changes are needed to allow cloudflared egress to the API server?: The network policy in k8s/cloudflared/networkpolicy.yaml needs to include a rule allowing egress to the API server on port 6443, following the same pattern as existing rules. The rule should use ipBlock with cloud metadata address excluded. [sources: k8s/cloudflared/networkpolicy.yaml]
  • How does the tunnel sync command currently handle hostname placement?: The tunnel sync command adds new hostnames after existing rules, just before the catch-all, which causes specific hostnames under a wildcard rule to never be reached because cloudflared takes the first matching rule. [sources: src/devops_cli/cloudflare/client.py:145-149]
  • Should cloudflared be added to tools.lock?: Yes, cloudflared should be added to tools.lock with sha256-pinned downloads per platform so that devops install-tools installs it. (proposed)

Open questions

  • What is the recommended approach for kubectl access through Cloudflare Tunnel? (missing verified source)

Fit

Needs splitting into 4 items:

  1. Allow cloudflared egress to the API server in network policy
  2. Route k8s. to API server through Cloudflare tunnel with proper hostname placement
  3. Add cloudflared to tools.lock with platform-specific binaries
  4. Document workstation-side configuration for kubectl access

Suspected block

None.

Dependencies

None.

Activity

  1. added
    source/agent
    type/feature
    on Oct 16, 2026
  2. dan-petty commented on Oct 16, 2026

    @dan-petty
    OwnerAuthor

    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.

    • Type: type/feature. The candidate adds a new capability to reach the kube API off the home network.
    • Priority: P2-Medium. This improves access convenience but does not block functionality or introduce critical issues.
    • Value: High. It enables kubectl usage from outside the home network, which is a common need for remote cluster management.
    • Effort: Medium. Requires changes to network policies, tunnel configuration, tool installation, and documentation.
  3. added a commit that references this issue on Oct 16, 2026
    2221e86
  4. added this to the v0.2.36 milestone on Oct 16, 2026
  5. added a commit that references this issue on Oct 16, 2026
    e7f032f
  6. dan-petty commented on Oct 16, 2026

    @dan-petty
    OwnerAuthor

    Proposal needs splitting into 4 items at 76dd52a (see proposed design in issue body).

  7. dan-petty commented on Oct 16, 2026

    @dan-petty
    OwnerAuthor

    What changed

    #1597, merged into release/v0.2.36 as e7f032f.

    Closes #1595

    Off the home network a workstation cannot reach the cluster's API server: the kubeconfig names the node's LAN address. This makes the API reachable at k8s.<domain> through the existing Cloudflare Tunnel, behind the Access application that already covers the domain, with kubectl over cloudflared access tcp. An HTTP hostname cannot carry the API, because Cloudflare ends TLS at its edge and drops kubectl's client certificate; a tcp:// route keeps TLS end to end.

    13 file(s) changed.

    How it was verified

    Check runs at 2221e86:

    • Prune PR DevContainer Images: pass
    • Audit Defect PR Hardening: skipping
    • devops-cli: pass
    • bandit: pass
    • CodeQL: pass
    • Changed-Test Independence: pass
    • Analyze (actions): pass
    • Tests & Coverage: pass
    • Analyze (python): pass
    • Static Analysis: pass
    • Service Image: skipping
    • Dependency Freshness: skipping
    • DevContainer Image: skipping

    No task file.

  8. added a commit that references this issue on Oct 17, 2026
    3dd7fa6
  9. dan-petty commented on Oct 17, 2026

    @dan-petty
    OwnerAuthor

    Verified on 2026-10-17, after v0.2.36 reached main (3dd7fa6) and Argo CD synced the base Application to it at 12:27 UTC.

    • The live cloudflared-isolation NetworkPolicy now allows cloudflared egress to the API server on 6443. On 2026-10-16 the same connection was refused at this hop.
    • With cloudflared access tcp --hostname k8s.<domain> --url 127.0.0.1:16443 running, GET /version through the tunnel reaches the API server. It returns 401, because k3s refuses anonymous requests.
    • The tunnel context was added with the three kubectl config commands in k8s/README.md, exactly as written. Through it, kubectl --context <cluster>-tunnel get nodes lists the cluster's nodes, and auth can-i list pods -A answers yes.
    • These checks ran from the home network, where Access asks for no login, so the Access login path has not been exercised yet.

    Pending a person: from off the home network, run the listener and get nodes after the Access login.

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

    source/agenttype/feature

    Type

    No type

    Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions