Repository navigation
feat(gateway): trust a private CA and present a client certificate to the gateway - #1673
Merged
Merged
Conversation
… 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
This was referenced Nov 1, 2026
…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
9 tasks
Contributor
|
🎉 This PR is included in version 0.240.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
infer can now reach a gateway behind a private CA or one that requires mutual TLS. mTLS is optional:
ca_filealone gives plain TLS against a private CA, and the client certificate is presented only when the gateway asks for one.gatewaygains atlsblock:Each key also has an
INFER_GATEWAY_TLS_*environment variable.ca_fileis added to the system roots for gateway calls only. Before, a private CA meantSSL_CERT_FILE, which replaces the roots for everything the agent does.cert_fileandkey_fileare presented when the gateway asks for a client certificate. Set both or neither.~.Changes
internal/gateway/tls.go:Transport(config.PeerTLSConfig)is the one transport for the gateway. Without settings it ishttp.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.Version()asks external gateways too, soinfer statusreports an mTLS gateway's version againUseGatewayCredentialtakes the transport, and other A2A agents keep the default, so they never get the gateway's client certificateconfig.GatewayConfig.TLSreusesPeerTLSConfig, theca_file,cert_fileandkey_filea daemon-kind workspace already has. The env overrides andinfer config get/setfind the new keys through the existing reflection, and an empty block stays out ofinfer init's output.docs/configuration-reference.md: the settings, the example and the env vars.Scope
infer-k8spod.judge.gateway_url, a separate gateway that may have its own CA. Add ajudge.tlsonce someone runs it behind mTLS.kind: kubernetesworkspaces, which reach the in-cluster Gateway that infer deploys over plain HTTP. TLS there belongs to the operator'sGatewayspec.Test plan
internal/gateway/tls_test.go, against anhttptestTLS gateway whose certificates come from the daemon PKI:ca_filethe private CA is unknown~/ca.crtit is trustedcertificate required)ca_fileand acert_filewithout itskey_filefail and name the settingTransportignores the settingsVersion()reads an mTLS gateway's/versionwith the client certificateINFER_GATEWAY_TLS_CA_FILE,_CERT_FILEand_KEY_FILEreachcfg.Gateway.TLStask testandtask precommit:runpassNotes
inference-gateway/docs. The CLI configuration page gets the new keys in [DOCS] Gateway TLS settings in the CLI configuration docs#1072.spec.server.tls.clientCARefshipped in operator v0.31.0.Closes #1672