Skip to content

fix(k8s): Close the tunnel path from the egress perimeters #6021

Closed

Description

@dan-petty

Problem

The perimeter NetworkPolicies allow egress to public TCP 443 with the private ranges excluded: renovate-perimeter (k8s/devops/renovate/networkpolicy.yaml), devops-default-perimeter, and the policies of crawl4ai and SearXNG. Public 443 also reaches the Cloudflare tunnel hosts of the cluster. When cloudflare.access.public_ip_bypass is set (docs/CONFIGURATION.md, about line 200), a request from the homelab public address skips Cloudflare Access, so a pod in such a perimeter can reach cluster services (for example the LLM gateway) through the tunnel. The comment "no path to the gateway" (renovate-perimeter, about lines 5-6) is then not fully true. Found in the review of PR #6014; the gap is older than that PR.

Expected behavior

  • A pod in a perimeter policy cannot reach a cluster service through its tunnel host: for example Access does not bypass requests from the cluster's own egress address for those hosts, or the bypass is limited to the hosts that need it, or a rule needs a service token for requests that come from the cluster.
  • A check proves it from one pod of each perimeter (a request to the gateway tunnel host gets 403 or no route).
  • The comments of the perimeter policies say what is true.

Related

Proposed design

Problem statement

The perimeter NetworkPolicies of the product base allow egress to public TCP 443 with the private ranges excluded. Public TCP 443 also reaches the Cloudflare tunnel hosts of the cluster. The Access application of the wildcard *.<domain> carries the policy homelab-public-ip-bypass with the workstation's public address, and a pod egresses through that same address. So a pod in a perimeter (renovate-perimeter, devops-default-perimeter, crawl4ai-perimeter, searxng-perimeter) reaches cluster services, such as the LLM gateway, through their tunnel hosts with no Access login. The comment of renovate-perimeter, crawl4ai-perimeter and searxng-perimeter that says the pod gets no path to the gateway is therefore false.

Acceptance criteria

Requirement: Bypass stays off the cluster-service tunnel hosts

devops cloudflare access sync SHALL attach the public-IP bypass policy only to the tunnel hosts that the configuration names as bypass hosts, and SHALL attach no bypass rule to a tunnel host that serves a cluster service.

Scenario: Sync of the gateway tunnel host

  • WHEN a test runs the sync for the gateway tunnel host with cloudflare.access.public_ip_bypass set to the homelab public address
  • THEN the built policy payload for that host holds no bypass decision and no ip include rule for that address.

Requirement: Cluster-service tunnel hosts require a service token

The Access policy of a tunnel host that serves a cluster service MUST require a Cloudflare Access service token, so that a pod that holds no token is refused with 403.

Scenario: Service-token rule of the gateway tunnel host

  • WHEN a test builds the policy payload for the gateway tunnel host
  • THEN the payload holds a rule that names a service token, and no rule admits an anonymous request.

Requirement: Perimeter comment states the tunnel path

Each perimeter NetworkPolicy that this repository ships, and the matching sentences of docs/CLUSTER.md, MUST state the tunnel path and MUST cite issue #6021, and MUST NOT claim that the pod has no path to the gateway.

Scenario: Comment of a shipped perimeter policy

  • WHEN a test walks the NetworkPolicy manifests under k8s/devops/ and the perimeter sentences of docs/CLUSTER.md
  • THEN each policy whose egress allows public TCP 443 names the tunnel path and cites fix(k8s): Close the tunnel path from the egress perimeters #6021, no sentence claims that the pod has no path to the gateway, and the test reads the raw file text so the comments are covered.

Requirement: Perimeter egress rules stay

The perimeter policies MUST keep their CoreDNS, OpenTelemetry and public HTTPS egress rules.

Scenario: Egress rules of renovate-perimeter

  • WHEN a test reads k8s/devops/renovate/networkpolicy.yaml
  • THEN the egress holds the UDP and TCP 53 rule to kube-system, the TCP 4318 rule to otel, and the TCP 443 rule to public addresses.

Existing Tool Considered

No alternatives check has run on this item. Cloudflare Access, the Zero Trust platform the cluster already uses, covers the need: it lets each self-hosted application (one hostname) carry its own policies, so the public-IP bypass can be scoped to the hosts that need it (git, the API) and a cluster-service host can require a service token. It lacks nothing for this, and no open library replaces it. The change does not build a replacement: it extends the project's own devops cloudflare access sync, whose include rules hold only email and IP today (src/devops_cli/cloudflare/client.py:242) and whose sync manages one application per domain (src/devops_cli/cloudflare/client.py:842), to emit a service-token rule and to scope the bypass per host. That code costs about 1,200 tokens to write, about 400 tokens per later fix until it matches the tool, and about half a day of elapsed work. The comment fix needs no tool and no new code.

Key questions

  • Which file holds cloudflare.access.public_ip_bypass, and which code applies the setting to the Cloudflare Access policy?: cloudflare.access.public_ip_bypass is declared in src/devops_cli/config/settings.py:616 (cloudflare.public_ip_bypass at :655) and documented at docs/CONFIGURATION.md:200. _resolve_bypass_ips reads it in src/devops_cli/commands/cloudflare.py:793; _build_policy_include_rules turns each address into an {"ip": {"ip": ...}} include rule at src/devops_cli/cloudflare/client.py:242; and sync_access_application attaches that rule as a bypass-decision policy to the Access application of the synced domain (src/devops_cli/cloudflare/client.py:842, :869). [sources: src/devops_cli/config/settings.py:616, src/devops_cli/commands/cloudflare.py:793, src/devops_cli/cloudflare/client.py:242, src/devops_cli/cloudflare/client.py:842, docs/CONFIGURATION.md:200]
  • Which files hold the perimeter policies that the issue names?: devops-default-perimeter is k8s/devops/networkpolicy.yaml, renovate-perimeter is k8s/devops/renovate/networkpolicy.yaml, crawl4ai-perimeter is k8s/devops/crawl4ai/networkpolicy.yaml, and searxng-perimeter is k8s/devops/searxng/networkpolicy.yaml. Each egress allows public TCP 443 with the private ranges excluded. [sources: k8s/devops/networkpolicy.yaml:5, k8s/devops/renovate/networkpolicy.yaml:10, k8s/devops/crawl4ai/networkpolicy.yaml:9, k8s/devops/searxng/networkpolicy.yaml:8]
  • What does the comment of renovate-perimeter claim today?: k8s/devops/renovate/networkpolicy.yaml:5 says devops-default-perimeter skips the pod, so it gets no path to the gateway, the cache Valkey, Qdrant or the API server. k8s/devops/crawl4ai/networkpolicy.yaml:5 and k8s/devops/searxng/networkpolicy.yaml:3 repeat the claim for their pods, and docs/CLUSTER.md:262 repeats it for Renovate (:215 for Crawl4AI, :238 for SearXNG). The public TCP 443 egress rule of each policy makes the claim false for the tunnel path. [sources: k8s/devops/renovate/networkpolicy.yaml:5, k8s/devops/crawl4ai/networkpolicy.yaml:5, k8s/devops/searxng/networkpolicy.yaml:3, docs/CLUSTER.md:262]
  • How does the cluster close the tunnel path from a pod in a perimeter to a cluster service?: Scope the public-IP bypass to the hosts that need it, and make each tunnel host that serves a cluster service require a Cloudflare Access service token. The wildcard application of the domain covers every host today (k8s/README.md:934), and git relies on the bypass (k8s/README.md:939), so the bypass must move off the wildcard onto the host-specific applications that need it. A pod holds no service token, so Access answers 403 for the cluster-service hosts. (best practice) [sources: k8s/README.md:934, k8s/README.md:939, src/devops_cli/cloudflare/client.py:242, src/devops_cli/cloudflare/client.py:842]
    • Chosen: Scope the bypass per host and require a service token on the cluster service hosts. The wildcard application covers every host (k8s/README.md:934), so the bypass must be scoped; git needs the bypass (k8s/README.md:939); a pod holds no service token, so Access answers 403.
    • Rejected: Remove cloudflare.access.public_ip_bypass. It removes the owner's direct access to every host, including the git and API hosts that need it (k8s/README.md:939), more than the issue needs.
    • Rejected: Restrict the perimeter NetworkPolicy egress to named destinations. The perimeters need public TCP 443 to hosts that share Cloudflare anycast addresses, such as the npm registry. An ipBlock cannot separate the tunnel host.
    • Rejected: Give the perimeter pods a separate egress address. It needs a CNI egress gateway and keeps the bypass. It costs more and gives the same result.
  • How does the repository guard the perimeter comments offline?: Extend the per-policy invariant tests under tests/invariants/ with a test that reads the raw text of each shipped NetworkPolicy and asserts that every manifest whose egress allows public TCP 443 names the tunnel path and cites fix(k8s): Close the tunnel path from the egress perimeters #6021, and that none claims the pod has no path to the gateway. tests/invariants/test_k8s_renovate.py:475 already asserts the egress of renovate-perimeter and :507 reads raw lines for the license check, so the pattern exists and the test runs offline. The proposal's cited path tests/test_architectural_invariants.py does not exist; the module is tests/invariants/test_architectural_invariants.py, and its docstring shows it holds Python source invariants, not manifest text. (best practice) [sources: tests/invariants/test_k8s_renovate.py:475, tests/invariants/test_k8s_renovate.py:507, tests/invariants/test_architectural_invariants.py:1, tests/support/k8s_tree.py:147]
    • Chosen: A pytest in the per-policy invariant tests that reads the manifest text. tests/invariants/test_k8s_renovate.py:475 already asserts the egress of renovate-perimeter, :507 reads raw lines, and the tests run offline.
    • Rejected: A pytest in tests/invariants/test_architectural_invariants.py. That module holds Python source invariants (tests/invariants/test_architectural_invariants.py:1), not manifest text.
    • Rejected: A kube-linter custom check. kube-linter checks schemas and objects. It has no rule for comment text.
    • Rejected: No guard. The false claim can return with the next edit.
  • Who creates the Cloudflare Access service token that the cluster-service tunnel hosts require?: The owner creates one service token in the Cloudflare Zero Trust dashboard and names it in the policy of each cluster-service tunnel host. No client in this repository holds or sends it, so it stays unused and no Secret reaches the cluster. Recommendation: create it as homelab-cluster-service when the change lands, then re-run devops cloudflare access sync for those hosts. (a person decides)

Open questions

  • Who creates the Cloudflare Access service token that the cluster-service tunnel hosts require? (a person decides)

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Alternatives check of 2026-11-17: none.
Tool: none found.
Reason: Searches found no open, maintained tool that scopes the Cloudflare Access public-IP bypass per host or adds a service-token rule; the fix belongs to the project's own access sync code and the manifest comments.

Lacks:

  • No open tool scopes an Access bypass rule to named hosts
  • No tool emits a service-token Access policy from project settings
  • No tool checks NetworkPolicy comment text for a false claim
  • Cloudflare Access is a hosted platform, not an open library

Activity

  1. added
    type/bug
    scope/k8s
    source/agent
    on Nov 16, 2026
  2. dan-petty commented on Nov 16, 2026

    @dan-petty
    OwnerAuthor
    • Priority: P1-High. A live security gap lets pods bypass Cloudflare Access to reach cluster services.
    • Related: dan-petty/homelab#346, which asks for a different change. Both address NetworkPolicies in the cluster, but dan-petty/homelab#346 adds missing policies to uncovered namespaces while the candidate closes the tunnel bypass in existing perimeter policies.
  3. added
    status/new
    effort/medium
    value/high
    priority/p1-high
    on Nov 16, 2026
  4. devops-cli-service commented on Nov 16, 2026

    @devops-cli-service
    Contributor

    Owner question: Who creates the Cloudflare Access service token that the cluster-service tunnel hosts require? (a person decides)

    Options

    1. Decide the question: The job refines the item with your answer.
    2. Leave it to the job: The job records the best-practice answer and goes on.

    Recommendation: Decide the question: only a person can answer it.

    Evidence

  5. devops-cli-service commented on Nov 17, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (5)

    Searches run:

    • open source alternative to Cloudflare Access zero trust per-route policy service account token, results: 5
    • Cloudflare Access policy as code service token per-hostname bypass policy open source tool, results: 5
    • Pomerium per-route authorization policy service account identity proxy, results: 5
    • cloudflare terraform provider access application policy service token, results: 5
    • cloudflared cloudflare zero trust access service token documentation, results: 5
  6. dan-petty commented on Nov 18, 2026

    @dan-petty
    OwnerAuthor

    This is stupid. Cloudflare is to protect external parties from requesting my services. I'm not trying to protect my project from accessing itself.

  7. removed
    status/new
    on Nov 18, 2026
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

    effort/mediumpriority/p1-highscope/k8ssource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions