For the complete documentation index, see llms.txt. Markdown versions of all docs pages are available by appending .md to any docs URL.
Backend TLS
Configure TLS for secure connections to backend services.
Attaches to:
Note
Agentgateway supports more than one configuration style. Where a feature can also be configured in the simplified llm or mcp modes, the examples on this page show each option in tabs. For more information, see Routing-based configuration.
By default, requests to backends use HTTP. To use HTTPS, configure a backend TLSTLS (Transport Layer Security)A cryptographic protocol that provides secure communication over a network. Agentgateway supports TLS for both incoming connections (listeners) and outgoing connections (backends). policy.
# yaml-language-server: $schema=https://agentgateway.dev/schema/config
mcp:
port: 3000
policies:
backendTLS:
# A file containing the root certificate to verify.
# If unset, the system trust bundle will be used.
root: ./certs/root-cert.pem
# For mutual TLS, the client certificate to use
cert: ./certs/cert.pem
# For mutual TLS, the client certificate key to use.
key: ./certs/key.pem
# The server name to use for SNI and certificate verification.
# hostname: backend.internal.example.com
# If set, hostname verification is disabled
# insecureHost: true
# If set, all TLS verification is disabled
# insecure: true
targets:
- name: everything
stdio:
cmd: npx
args: ["@modelcontextprotocol/server-everything"]The backendTLS policy supports the following fields.
| Field | Description |
|---|---|
root | The path to a file with the root certificate that verifies the backend certificate. If unset, agentgateway uses the system trust bundle. |
cert | The path to the client certificate for mutual TLS. |
key | The path to the private key of the client certificate for mutual TLS. |
hostname | The server name that agentgateway sends as Server Name Indication (SNI) and verifies the backend certificate against. If unset, agentgateway uses the host that it connects to. |
insecureHost | If set to true, agentgateway disables hostname verification. |
insecure | If set to true, agentgateway disables all TLS verification. |
By default, agentgateway verifies the backend certificate against the host that it connects to. Set hostname when the certificate is issued for a different name.
Note
To use TLS for a custom prompt guard webhook, set target.policies.backendTLS on the webhook target instead. For more information, see Configure webhook backend policies.
Mutual TLS and certificate rotation
To originate mutual TLS (mTLS) to a backend, set the cert and key fields of the backendTLS policy to the client certificate and private key files. Set root to the CA bundle that verifies the backend server certificate.
# yaml-language-server: $schema=https://agentgateway.dev/schema/config
gateways:
default:
port: 3000
routes:
- backends:
- host: backend.example.com:443
policies:
backendTLS:
root: /etc/agentgateway/certs/ca.crt
cert: /etc/agentgateway/certs/tls.crt
key: /etc/agentgateway/certs/tls.keyAgentgateway reads these files at startup and watches them. When a file changes, agentgateway reloads the configuration and uses the new certificate for new connections to the backend. You do not need to restart agentgateway. This behavior is useful when another process, such as a certificate manager or a SPIFFE helper, renews the certificate on disk.
When agentgateway reloads, it logs the changed file.
info state_manager resource changed, reloading resource="file:/etc/agentgateway/certs/tls.crt"
info state_manager loaded config from File("/etc/agentgateway/config.yaml")If the new files are not valid, such as when the certificate is not PEM or does not match the key, agentgateway logs an error and keeps using the previous configuration.
error state_manager Failed to reload config: keys may not be consistent: KeyMismatchIf you replace the certificate and the key with two separate writes, agentgateway might log this error after the first write, because the new certificate does not match the old key. The reload succeeds after the second write.
Note
The config.fileAccess setting does not apply to the files that your configuration file references, such as the root, cert, and key files. Agentgateway loads these files at startup and when they change.