Skip to content

feat(gateway): trust a private CA and present a client certificate to the gateway - #1673

Merged
edenreich merged 2 commits into
mainfrom
feat/gateway-client-tls
Nov 1, 2026
Merged

edenreich merged 2 commits into
mainfrom
feat/gateway-client-tls

Conversation

@edenreich

@edenreich edenreich commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

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:

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. docs(examples): add kubernetes-session-teleport-netbird to teleport over NetBird #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

  • 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
  • The same tests fail when Transport ignores the settings
  • Version() reads an mTLS gateway's /version with the client certificate
  • A2A reaches the gateway over its transport without an API key, and another agent stays on the default transport
  • INFER_GATEWAY_TLS_CA_FILE, _CERT_FILE and _KEY_FILE reach cfg.Gateway.TLS
  • task test and task precommit:run pass

Notes

Closes #1672

… the gateway

gateway.tls.ca_file, cert_file and key_file (INFER_GATEWAY_TLS_*) give
infer what a gateway behind a private CA or mutual TLS needs. The CA is
added to the system roots for gateway calls only, so every other HTTPS
call keeps its trust, and the key pair is presented when the gateway asks
for a client certificate. Paths may start with ~.

One transport from internal/gateway carries the settings, and every
gateway call uses it: the SDK clients of the container (agent loop, model
listing, titles, summaries, media, insights), the supervisor's health and
version probes, and A2A requests to the gateway origin. Other A2A agents
keep the default transport. Unusable TLS material fails each gateway call
with the reason and names the setting.

Daemon workers read the same config and environment, so a daemon on
another machine or in a pod reaches its gateway the same way.

Closes #1672
…ver NetBird (#1671)

## 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:

```text
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

- [x] `go test ./internal/agent/infrastructure -run
'TestClientForDaemon|TestServerLoads'` passes, and the new cases fail
without the fix
- [x] `task precommit:run` passes
- [x] 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
- [x] 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
- [x] Dashboard login through the embedded IdP (authorization code with
PKCE) and an API call with the resulting token

## Notes

- Impacted repos: none beyond #1673's docs ticket
(inference-gateway/docs#1072).
- Gap issues filed while building this, all shipped:
inference-gateway/operator#308 (`spec.pod`, v0.30.0),
inference-gateway/operator#310 (TLS probes, v0.31.0),
inference-gateway/inference-gateway#817 (mTLS, v0.61.0),
inference-gateway/tokenless#90 (TLS, v0.11.0). #1672 is #1673.
- Before 0.61.1, the Inference Gateway sent its provider calls through
its own TLS listener, so server TLS also needed an IP SAN for `0.0.0.0`
and a client certificate presented back to itself. Filed as
inference-gateway/inference-gateway#822 and fixed in
inference-gateway/inference-gateway#823 (v0.61.1), so the example pins
0.61.1 and needs neither.
- Unrelated and left alone: `examples/kubernetes`'s `mockgateway:image`
task still builds from `tests/mockgateway`, which moved to
`inference-gateway/tokenless`.

Closes #1664
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.240.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[FEATURE] Gateway client TLS settings: a private CA and a client certificate

1 participant