Skip to content

docs(examples): add kubernetes-session-teleport-netbird to teleport over NetBird - #1671

Merged
edenreich merged 10 commits into
feat/gateway-client-tlsfrom
docs/kubernetes-session-teleport-netbird
Nov 1, 2026
Merged

edenreich merged 10 commits into
feat/gateway-client-tlsfrom
docs/kubernetes-session-teleport-netbird

Conversation

@edenreich

@edenreich edenreich commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds examples/kubernetes-session-teleport-netbird, a runnable example where a session teleports along a chain of NetBird peers. Every hop is admitted by its own NetBird policy and runs mutual TLS:

infer-local    Docker container beside the cluster, "your machine"
    │          policy infer-local-to-infer-k8s: TCP 52789, mTLS with infer-local's client certificate
    ▼
infer-k8s      pod on agent-1, binding only on its NetBird address
    │          policy infer-k8s-to-gateway: TCP 8443, mTLS with infer-k8s's client certificate
    ▼
gateway        pod on agent-0, only WireGuard on its pod address, one of:
               - tokenless, a mock gateway, so no API key is needed (task up)
               - the Inference Gateway in front of a real provider (task gateway:real)

Stacked on #1673 (gateway.tls in infer), which infer-k8s needs for the second hop. The example builds infer from the checkout, so it needs no release.

Everything is self-hosted on a local k3d cluster:

  • NetBird 0.82.0: the combined netbird-server (management, signal, relay, STUN, embedded IdP) and the dashboard v2.96.0, as plain manifests
  • the NetBird Kubernetes operator 0.9.0 joins the pods through Group, SetupKey and SidecarProfile resources
  • cert-manager v1.21.3 serves the operator webhook and runs peers-ca, which issues the infer-k8s, gateway and infer-local certificates (ECDSA P-256)
  • tokenless v0.11.0 serves as the gateway with --tls-client-ca
  • task gateway:real swaps in the Inference Gateway 0.61.1, run by operator v0.31.0 with spec.server.tls.clientCARef, in front of a real provider. It reads <PROVIDER>_API_KEY from the environment into a Secret, and PROVIDER and MODEL pick the provider and model, and rerunning it switches them
  • the tasks bootstrap the NetBird account through POST /api/setup, set the netbird.internal DNS domain, delete the allow-all Default policy and create the two policies

The demo then shows what an attacker gets:

  • a sniffer in front of the infer-k8s node sees only WireGuard. The sealed forward_env value and the model's reply never appear in the capture, while a plaintext canary does, so the capture provably reads plaintext
  • an attacker peer outside the policies can neither resolve nor reach infer-k8s or the gateway, and infer-local cannot skip a hop to the gateway
  • each hop rejects the peer its policy admits once that peer has no client certificate: tlsv13 alert certificate required from the binding, remote error: tls: certificate required from the gateway
  • the NetBird dashboard's Control Center draws the chain

Changes

  • fix(daemon): expand ~ in the binding and daemon-workspace TLS certificate, key and CA paths. The form docs/daemon.md shows (ca_file: ~/.infer/daemon/workstation-ca.crt) used to fail with a missing file. Table tests cover both the client and the server side.
  • docs(examples):
    • the example and a row in docs/examples.md
    • a NetBird section under "Daemons on other machines" in docs/daemon.md. It covers mTLS on the binding and gateway.tls for the workers, and stops claiming that ca mode keeps forward_env between two daemons. Its certificate names only the workspace, the hostname and localhost, and it requires client certificates nothing issues to a second daemon, so the example uses files TLS

Acceptance criteria, as adapted

The issue asked for compose files under examples/netbird-peers/ with NetBird Cloud as an alternative. On request, the example:

  • runs on Kubernetes under examples/kubernetes-session-teleport-netbird/, named after session-teleport
  • is self-hosted only
  • extends the two daemons to a chain that ends at a gateway

infer-local still runs from a compose file beside the cluster. The binding token became infer-local's client certificate. files TLS with client_auth: true admits a verified certificate in place of the token, so the example has no token. Every other criterion holds:

  • setup keys
  • the binding only on the NetBird address
  • a policy admitting only the source peer
  • kind: daemon by NetBird name with the daemon's own TLS
  • workspaces, teleport, run and teleport back in the README
  • a peer outside the policy that cannot reach the binding
  • a sealed forward_env
  • task cleanup
  • the docs/daemon.md link

Per-connection traffic events are a NetBird Enterprise feature, so the README points at the Control Center, netbird status -d and the capture instead.

Test plan

  • go test ./internal/agent/infrastructure -run 'TestClientForDaemon|TestServerLoads' passes, and the new cases fail without the fix
  • task precommit:run passes
  • From scratch, mock mode: task cleanup, task up, then workspaces, sniff:start, demo, secret:check, sniff:report, attack, netbird:status and teleport:back all pass. The tokenless reply arrives over mTLS, the capture holds 0 packets on 52789 and 8443 and the canary, and both hops reject a missing client certificate
  • Real mode on gateway 0.61.1, with a dummy OPENAI_API_KEY: task gateway:real twice, attack. The Gateway serves mTLS with tcpSocket probes. infer status on infer-k8s reaches it with its certificate and is rejected without it. The gateway's call to OpenAI comes back 401 for the dummy key, and the key never appears in the task output. A real model reply needs a real key and was not run
  • Dashboard login through the embedded IdP (authorization code with PKCE) and an API call with the resulting token

Notes

Closes #1664

daemon.yaml paths under binding.tls and a daemon-kind workspace's tls were
read as written, so ~/.infer/daemon/workstation-ca.crt, the form docs/daemon.md
shows, failed with a missing file. They now go through utils.ExpandHome like
projects_root.
…ver NetBird

A session teleports from infer-local, a daemon in Docker beside a k3d cluster,
to infer-k8s, a daemon in the cluster whose agent calls an Inference Gateway.
Every hop is a peer on a self-hosted NetBird 0.82 network (the combined server
and the dashboard), and each hop has its own one-way policy: TCP 52789 into
infer-k8s and TCP 8080 into the gateway. The NetBird Kubernetes operator 0.9.0
joins the pods with setup keys, groups and sidecar profiles. The infer-k8s
binding listens only on its NetBird address with files TLS from a cert-manager
ECDSA certificate and a token. A NetworkPolicy admits only WireGuard to the
gateway's pod address, and tokenless behind it answers without an API key.

A sniffer in front of the infer-k8s node sees only WireGuard, never the token,
the forwarded secret or the model's reply, while a plaintext canary proves it
reads plaintext. An attacker peer outside the policies can neither resolve nor
reach infer-k8s or the gateway, and infer-local cannot skip a hop to the
gateway. The dashboard's Control Center draws the chain.

docs/daemon.md gains the NetBird setup for daemons on other machines and no
longer claims ca mode keeps forward_env between two daemons.

Refs #1664
…teway

The gateway hop now comes from the Inference Gateway operator v0.29.0: a
Gateway resource named gateway in place of a bare pod, in a namespace
labelled for the operator. Its pods carry app: gateway, which the NetBird
SidecarProfile and the WireGuard-only NetworkPolicy already select. The
Gateway resource sets no pod labels or node placement of its own
(inference-gateway/operator#308), so the peer keeps its pod's name and the
extra DNS label keeps gateway.netbird.internal stable.
….0 spec.pod

The Inference Gateway operator v0.30.0 adds spec.pod to Gateway, Agent and MCP
(inference-gateway/operator#308). The example installs it and pins the gateway
to agent-0 with spec.pod.nodeSelector, away from infer-k8s, so the sniffer in
front of infer-k8s sees the gateway hop cross nodes. The README also covers
the old gateway peer that keeps the gateway DNS label for a few minutes after
a gateway pod is replaced on a running cluster.
Checked in the dashboard: the Control Center draws one hop at a time, the
policies that let the focused peer reach others. infer-local shows the hop to
infer-k8s, infer-k8s the hop to the gateway, and attacker none. The README
said one view showed the whole chain.
The Control Center Group view draws the policies a group is the source of on
its right and the ones it is the destination of on its left. Selecting the
infer-k8s group therefore shows infer-local, infer-k8s and the gateway with
both policies in one view, so the README leads with that and keeps the Peer
view as the per-peer detail.
…rd example's first hop

cert-manager's peers-ca now issues infer-k8s a server certificate and
infer-local a client auth certificate. The infer-k8s binding runs files
TLS with client_auth, so the verified certificate replaces the binding
token and the token Secret is gone. task attack adds a client inside
infer-local's own NetBird network that has no certificate and gets
"certificate required".

The README gains a table of the hops still on plain HTTP inside
WireGuard and the issues that track TLS for them, and docs/daemon.md
shows the mTLS setup for NetBird.

Refs #1664
…kenless or a real model

tokenless v0.11.0 is now the gateway itself, with --tls-client-ca, instead
of a mock provider behind an operator Gateway. infer-k8s reaches it on
gateway.netbird.internal:8443 with gateway.tls, presenting the infer-k8s
certificate, which gains client usage. task attack adds infer on
infer-k8s without its client certificate, which the gateway rejects.

task gateway:real swaps tokenless for the Inference Gateway 0.61.0, run by
operator v0.31.0, in front of a real provider. It reads <PROVIDER>_API_KEY
from the environment into a Secret, keeps the gateway peer, port and
certificate, and points infer-k8s at MODEL. The Gateway requires client
certificates through spec.server.tls.clientCARef. Its provider calls loop
through its own listener on 0.0.0.0:8443, so the gateway certificate also
names 0.0.0.0 and spec.client.tls presents it back.

The README replaces the gap table with how each hop runs TLS, and adds how
to use a real model.

Refs #1664
…d example

Gateway 0.61.1 reaches its own /proxy route in process, so its server
TLS no longer applies to its provider calls. The gateway certificate
loses the 0.0.0.0 address and client usage, and the real Gateway loses
spec.client.tls.

task gateway:real now waits only for the tokenless pods to go, so it can
run again to switch provider or model.

Refs #1664
@edenreich
edenreich merged commit 7c10407 into feat/gateway-client-tls Nov 1, 2026
@edenreich
edenreich deleted the docs/kubernetes-session-teleport-netbird branch November 1, 2026 18:17
edenreich added a commit that referenced this pull request Nov 1, 2026
… the gateway (#1673)

## Summary

infer can now reach a gateway behind a private CA or one that requires
mutual TLS. mTLS is optional: `ca_file` alone gives plain TLS against a
private CA, and the client certificate is presented only when the
gateway asks for one. `gateway` gains a `tls` block:

```yaml
gateway:
  url: https://gateway.example.internal:8443
  tls:
    ca_file: ~/.infer/gateway-ca.crt
    cert_file: ~/.infer/gateway-client.crt
    key_file: ~/.infer/gateway-client.key
```

Each key also has an `INFER_GATEWAY_TLS_*` environment variable.

- `ca_file` is added to the system roots for gateway calls only. Before,
a private CA meant `SSL_CERT_FILE`, which replaces the roots for
everything the agent does.
- `cert_file` and `key_file` are presented when the gateway asks for a
client certificate. Set both or neither.
- Paths may start with `~`.

## Changes

- `internal/gateway/tls.go`: `Transport(config.PeerTLSConfig)` is the
one transport for the gateway. Without settings it is
`http.DefaultTransport`. With them it is a clone that carries the CA and
the key pair. Unusable material, such as a missing file, a PEM holding
no certificate, or half a key pair, fails each gateway call with the
cause and names the setting. Startup is not broken, and no constructor
signature changes.
- Every gateway call uses it:
- the container's SDK clients: agent loop, model listing for chat,
headless and status, titles, summaries, media, insights
- the supervisor's health, audio and version probes. `Version()` asks
external gateways too, so `infer status` reports an mTLS gateway's
version again
- A2A requests to the gateway origin. `UseGatewayCredential` takes the
transport, and other A2A agents keep the default, so they never get the
gateway's client certificate
- `config.GatewayConfig.TLS` reuses `PeerTLSConfig`, the `ca_file`,
`cert_file` and `key_file` a daemon-kind workspace already has. The env
overrides and `infer config get/set` find the new keys through the
existing reflection, and an empty block stays out of `infer init`'s
output.
- `docs/configuration-reference.md`: the settings, the example and the
env vars.

## Scope

- Daemon workers read the same config and environment, so a daemon on
another machine or in a pod reaches its gateway the same way. #1671 uses
this for its `infer-k8s` pod.
- Not covered:
- `judge.gateway_url`, a separate gateway that may have its own CA. Add
a `judge.tls` once someone runs it behind mTLS.
- `kind: kubernetes` workspaces, which reach the in-cluster Gateway that
infer deploys over plain HTTP. TLS there belongs to the operator's
`Gateway` spec.

## Test plan

- [x] `internal/gateway/tls_test.go`, against an `httptest` TLS gateway
whose certificates come from the daemon PKI:
  - without `ca_file` the private CA is unknown
  - with `~/ca.crt` it is trusted
- an mTLS gateway accepts the client certificate and rejects a request
without it (`certificate required`)
- a missing `ca_file` and a `cert_file` without its `key_file` fail and
name the setting
- [x] The same tests fail when `Transport` ignores the settings
- [x] `Version()` reads an mTLS gateway's `/version` with the client
certificate
- [x] A2A reaches the gateway over its transport without an API key, and
another agent stays on the default transport
- [x] `INFER_GATEWAY_TLS_CA_FILE`, `_CERT_FILE` and `_KEY_FILE` reach
`cfg.Gateway.TLS`
- [x] `task test` and `task precommit:run` pass

## Notes

- Impacted repos: `inference-gateway/docs`. The CLI configuration page
gets the new keys in inference-gateway/docs#1072.
- Server-side mTLS shipped in inference-gateway/inference-gateway#818
(v0.61.0), and the operator's `spec.server.tls.clientCARef` shipped in
operator v0.31.0.

Closes #1672
@edenreich edenreich moved this from QA to Done in 2026 Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FEATURE] Add examples/netbird-peers to secure daemon-to-daemon teleports with NetBird

1 participant