- https://stackoverflow.com/questions/55690321/mutual-tls-based-on-specific-ip
- Type: qa
- Source: Stack Overflow · asked Apr 2019
TL;DR
Requiring mTLS only for some source IPs is not possible with the NGINX ingress auth-tls-* annotations inside a configuration snippet, and the answer argues it defeats the purpose of mTLS anyway.
Summary
The asker wanted client-certificate verification only for a specific remote address and tried to put auth-tls-* settings inside an if ($remote_addr = ...) block in configuration-snippet, but those annotation names are not NGINX directives, so the snippet fails. The accepted answer says that if everyone else can reach the service without a certificate, mTLS adds no real protection (and IPs can be spoofed), and proposes either plain TLS or mTLS for the whole service. A comment adds a legitimate case: machines from known IPs use mTLS while humans are redirected to an OIDC provider.
Key takeaways
- Annotation names are not directives:
auth-tls-verify-clientworks as an annotation but not insideconfiguration-snippet. - Selective mTLS by IP is weak security because source addresses can be spoofed and others stay unauthenticated.
- Option A: use regular TLS.
- Option B: require mTLS on the service itself and pass the client certificate through with
backend-protocol: "https"andauth-tls-pass-certificate-to-upstream: "true". - Mixed audiences (machines and humans) need a different design, such as separate hosts or paths.
Tools and concepts
| Item | Role in the page |
|---|---|
| Kubernetes | Ingress resource and annotations |
| NGINX ingress | configuration-snippet, auth-tls-* annotations |
| Security | Spoofable IP-based trust |
When to use
- When someone asks for IP-conditional client certificates on NGINX ingress.
- When explaining why partial mTLS is a weak control.
- When you need the pass-through annotations for a backend that terminates mTLS.
Caveats
- 2019 answers use the old
extensions/v1beta1Ingress API; the limitation itself still illustrates the design problem.
Kubernetes Security mTLS setup using self-signed cert in Kubernetes and NGINX Configuring Certificate-Based Mutual Authentication with Kubernetes Ingress-Nginx