Client Authentication with mTLS
Use mutual TLS (mTLS) for services, agents, and client applications that have certificates from your PKI. The ingress verifies each certificate and forwards its identity to LiteLLM for usage tracking and access policies.
These examples use a client certificate and a LiteLLM virtual key. The certificate identifies the workload. The key controls its user, team, models, and budget. For clients that send only a certificate, map each workload to its own key at the ingress.
Use a dedicated API hostname in private DNS, such as llm-api.example.com. Clients connect through your corporate network, VPN, or private interconnect. Allow only the ingress to reach LiteLLM. Keep Admin UI access separate.
LiteLLM configuration
Add this mapping to config.yaml:
general_settings:
user_header_mappings:
- header_name: x-mtls-client-id
litellm_user_role: customer
This mapping stores the workload identity in LiteLLM's customer ID field for usage tracking and access policies. The field can identify a service, agent, or application. The virtual key selects the LiteLLM user and team.
Each ingress overwrites X-MTLS-Client-ID and removes X-LiteLLM-Customer-ID and X-LiteLLM-End-User-ID. Those standard headers take precedence over this mapping. AWS, NGINX, HAProxy, and Kong map approved certificates to workload aliases. Azure and GCP forward IDs from certificates that pass CA validation.
Close alternate listeners, node ports, and default service URLs that bypass the ingress. Apply the policy to every route on the API hostname. These examples expose /v1/ and preserve Authorization.
Configure backend HTTPS separately from frontend mTLS. LiteLLM's --ssl_certfile_path and --ssl_keyfile_path options supply its server certificate and key. These flags do not configure client-certificate validation.
AWS Application Load Balancer
Use an internal ALB with an HTTPS listener and a private NGINX target group. ALB validates the client certificate. NGINX maps the verified certificate fields to a workload alias before it forwards to LiteLLM.
X-MTLS-Client-ID + LiteLLM keyDetails
NGINX maps the ALB certificate headers to an approved workload. LiteLLM uses the key for permissions and the workload ID for usage tracking and access policies. A failed check stops the request. LiteLLM accepts requests only through the private ingress.
Configuration
Upload your PEM client CA bundle to S3, then create the trust store:
TRUST_STORE_ARN=$(aws elbv2 create-trust-store \
--name litellm-clients \
--ca-certificates-bundle-s3-bucket "$CA_BUCKET" \
--ca-certificates-bundle-s3-key certificates/client-ca-bundle.pem \
--query 'TrustStores[0].TrustStoreArn' --output text)
After the trust store is active, attach it to your HTTPS listener:
aws elbv2 modify-listener \
--listener-arn "$LISTENER_ARN" \
--mutual-authentication "Mode=verify,TrustStoreArn=$TRUST_STORE_ARN,IgnoreClientCertificateExpiry=false"
verify makes ALB validate client certificates. Passthrough mode forwards certificate information without this validation. See AWS's mTLS setup.
Identity forwarding
Place this configuration inside NGINX's http block. Replace the issuer and serial with an approved certificate's ALB header values. Replace the example subnet with the ALB subnets. The security group must also allow only the ALB security group.
map "$http_x_amzn_mtls_clientcert_issuer|$http_x_amzn_mtls_clientcert_serial_number" $mtls_client_id {
default "";
"CN=WorkloadCA,O=Example|01" billing-worker;
}
server {
listen 443 ssl;
server_name mtls-mapper.internal;
ssl_certificate /etc/nginx/tls/server-chain.pem;
ssl_certificate_key /etc/nginx/tls/server-key.pem;
allow 10.20.0.0/24;
deny all;
location /v1/ {
if ($mtls_client_id = "") { return 403; }
proxy_pass https://litellm.internal:4000;
proxy_ssl_server_name on;
proxy_ssl_name litellm.internal;
proxy_ssl_trusted_certificate /etc/nginx/tls/origin-ca.pem;
proxy_ssl_verify on;
proxy_ssl_verify_depth 3;
proxy_set_header Host litellm.internal;
proxy_set_header Authorization $http_authorization;
proxy_set_header X-MTLS-Client-ID $mtls_client_id;
proxy_set_header X-LiteLLM-Customer-ID "";
proxy_set_header X-LiteLLM-End-User-ID "";
proxy_http_version 1.1;
proxy_set_header Connection "";
proxy_buffering off;
proxy_read_timeout 300s;
proxy_next_upstream off;
}
location = /ingress-health { return 200; }
location / { return 404; }
}
Keep NGINX's source IP check on the direct connection. Do not configure real_ip_header on this mapper. Empty, duplicate, or unlisted issuer/serial pairs fail the map. LiteLLM records billing-worker as the workload ID.
Set the target group's health-check path to /ingress-health. Keep the ALB listener rule limited to /v1/*. This probe checks NGINX. Monitor LiteLLM readiness separately.
ALB encrypts HTTPS backend traffic but does not validate the backend certificate. If your policy requires origin identity checks, choose an ingress that validates origin certificates. See ALB target group protocols.
Azure Application Gateway
Use Application Gateway Standard_v2 or WAF_v2 with a private frontend IP, an HTTPS listener, and a private LiteLLM backend.
X-MTLS-Client-ID + LiteLLM keyDetails
Application Gateway overwrites the identity header with the verified issuer and serial. LiteLLM uses them as the workload ID. A failed check stops the request. LiteLLM accepts requests only through the private ingress.
Configuration
Configure strict mTLS:
- Open SSL settings, add an SSL profile, and select Client Authentication.
- Upload each trusted client CA chain in one PEM or CER file. Include its root and intermediates.
- Open the API's HTTPS listener, enable SSL Profile, and select this profile.
- Route
/v1/*to your private backend. In Backend settings, select HTTPS. Use a hostname that matches its certificate. Upload the private root CA if needed. Keep certificate chain, expiry, and SNI validation enabled.
See the portal setup and backend TLS settings. Restrict origin access to the Application Gateway subnet. Configure its health probe separately for the private backend.