Zero-Trust Networking with OpenZiti

Overview

OpenZiti is an open-source, programmable zero-trust overlay network. In the Dark K3s architecture, OpenZiti replaces traditional ingress controllers, bastion jump hosts, and VPN concentrators.

Instead of exposing port 6443 publicly or managing IP-based firewalls, the Kubernetes control plane is published as an OpenZiti Service. Authorized operators connect seamlessly from their workstations using the ziti-edge-tunnel client, intercepting traffic targeted at the virtual domain https://k3s.ziti:6443.


Architecture of the In-Cluster Overlay

Dark K3s Zero-Trust Network Topology

The stack is packaged as a reusable Kustomize Component in kubernetes/infra-addons/components/openziti/ and deployed via Flux.


Automated Router Enrollment

In traditional OpenZiti setups, registering an edge router requires manual administrative CLI intervention to generate an enrollment token, download the one-time JWT, and feed it into the router daemon.

infra-bootstrap-tools fully automates this lifecycle using a Kubernetes Job (router-enrollment-job.yaml):

  1. The job mounts a service account with permissions to interact with the Ziti Controller’s REST API.
  2. It generates an administrative API session token using cluster credentials.
  3. It creates or re-creates the router identity and writes the resulting enrollment JWT into a temporary secret.
  4. The OpenZiti router container mounts the secret, enrolls with the controller, generates its cryptographic identity certificates, and enters active routing status.

Handling Enrollment Idempotency

Because Kubernetes jobs may run repeatedly during cluster upgrades or redeployments, the enrollment script (enroll-router.sh) implements strict idempotency:

  • If a router already exists with a consumed enrollment JWT (enrollmentJwt: null), the script deletes the stale router entry.
  • It polls the controller API until deletion has propagated cleanly.
  • It provisions a fresh router identity, preventing name must be unique conflict errors.

Critical Networking Lessons & Gotchas

1. advertisedHost Must Match Kubernetes In-Cluster Service Names

The clientApi.advertisedHost setting in the ziti-controller Helm values is embedded into all router enrollment JWTs as the token issuer (iss).

When the router pod initializes, it parses this JWT and immediately connects to the controller’s advertised host to complete enrollment. If this host is configured as an external DNS name that doesn’t resolve inside the pod, or does not match the actual Kubernetes service name, enrollment will fail with:

failed to parse JWT: could not contact remote server [https://<hostname>:<port>]

The Solution: Configure advertisedHost to the exact cluster-local service FQDN:

# default-ziti-controller.values.yaml
clientApi:
  advertisedHost: "openziti-ziti-controller-client.openziti.svc.cluster.local"
  advertisedPort: 1280
ctrlPlane:
  advertisedHost: "openziti-ziti-controller-client.openziti.svc.cluster.local"
  advertisedPort: 1280

2. ALPN Port Sharing (No Separate Control-Plane Service)

By default, the OpenZiti Helm chart disables ctrlPlane.service.enabled. Instead of listening on a dedicated port, control-plane traffic shares port 1280 alongside clientApi using ALPN protocol negotiation.

Do not attempt to reference a non-existent *-ctrl service in router configuration. The router points directly to the client endpoint:

# default-ziti-router.values.yaml
ctrl:
  endpoint: "openziti-ziti-controller-client.openziti.svc.cluster.local:1280"

3. Container Python Executable Naming

The official openziti/ziti-controller container image ships with python3.11, but does not create a generic python3 symlink in $PATH. Helper scripts in enrollment jobs must invoke python3.11 directly:

python3.11 -c "import sys, json; ..."

Connecting as an Administrator

Once the OpenZiti controller and router are running:

  1. Install the Client: Install ziti-edge-tunnel (or the Ziti Desktop Edge client) on your workstation.
  2. Enroll Your Identity:
    ziti-edge-tunnel enroll --jwt admin.jwt --identity /opt/openziti/identities/admin.json
    
  3. Transparent DNS Interception: The local tunnel daemon intercepts DNS queries for k3s.ziti and transparently routes the traffic through the encrypted mesh to the in-cluster router pod.
  4. Run kubectl:
    kubectl --kubeconfig ~/.kube/dark-k3s.yaml get nodes
    
    Traffic travels securely across the zero-trust overlay directly to 127.0.0.1:6443 on the server!