opyeb mtlslab

mtlslab · Compare

Envoy and HAProxy mTLS configuration side by side

All three proxies do the same job, but the directive names and the enforcement point differ. The same purpose in three syntaxes.

One purpose, three syntaxes

An mTLS configuration has four purposes: request a client certificate, verify it against a trusted CA, check revocation and pass the verified identity to the application. All three proxies support them, with different wording and enforcement points.

PurposeNginxEnvoyHAProxy
Request and verifyssl_verify_client onrequire_client_certificate: trueverify required
Trusted CAssl_client_certificatevalidation_context.trusted_caca-file
Revocationssl_crl, ssl_ocspvalidation_context.crl, ocsp_policycrl-file
SAN matchingvariable comparison via if or mapmatch_typed_subject_alt_namesssl_c_san ACL

How Envoy is shaped

Envoy puts a DownstreamTlsContext in the listener's transport_socket, and inside its common_tls_context it holds the certificate and the validation_context. The validation_context carries the trusted CA, the CRL and the SAN matching rules.

transport_socket:
name: envoy.transport_sockets.tls
typed_config:
"@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.DownstreamTlsContext
require_client_certificate: true
common_tls_context:
validation_context:
trusted_ca: { filename: /etc/envoy/tls/ca.pem }

require_client_certificate true without a validation_context is rejected, and so is a validation_context without trusted_ca. Those two are the most common start-up failures in Envoy.

SAN matching goes in match_typed_subject_alt_names as a san_type (DNS, URI, IP_ADDRESS) and a matcher. Without it, any client certificate that CA issued passes. Where every service gets its own certificate, narrow it.

How HAProxy is shaped

HAProxy puts everything on the bind line: crt for the server certificate, ca-file for the trusted CA, verify for the enforcement level and crl-file for revocation. The minimum TLS version is ssl-min-ver.

bind :443 ssl crt /etc/haproxy/tls/server.pem \
ca-file /etc/haproxy/tls/ca.pem verify required \
crl-file /etc/haproxy/tls/ca.crl ssl-min-ver TLSv1.2

Without verify no certificate is requested. With verify but no ca-file there is nothing to verify against and every certificate is refused. The two look alike in a log, which is where a lint earns its place.

Identity forwarding and the enforcement point

Nginx and HAProxy expose the result as variables and Envoy forwards it in XFCC. Either way the application learns that the proxy verified only from a header, so the proxy has to overwrite it and refuse failed requests.

The enforcement point differs by product. Nginx and HAProxy naturally cut the connection at TLS; Envoy is more flexible with a rule in the filter chain. In every case, a path that still admits requests without a certificate leaves mTLS in name only.

The generator builds all three products from one mode and path input, and leaves a comment where each product enforces differently.

Questions

Is Envoy still doing mTLS when require_client_certificate is false?

Yes. It requests a certificate and verifies one that is presented, but the connection succeeds without one, so unless a filter or XFCC rule refuses it, authentication is not enforced.

How do HAProxy verify required and optional differ?

required refuses a connection without a certificate; optional lets it through and verifies one that is presented. To refuse certificate-less requests under optional, combine the ssl_c_used and ssl_c_verify ACLs.

Where does SAN matching go?

In Envoy it is match_typed_subject_alt_names inside validation_context; in HAProxy it is an ssl_c_san or ssl_c_s_dn ACL; in Nginx it is a variable comparison with if or map.

Paste Envoy YAML or HAProxy configuration and defects are reported by line.

Open the tool

This article follows RFC 5280 (X.509), RFC 8446 (TLS 1.3), RFC 5246 (TLS 1.2), RFC 6125 (host name verification), RFC 6960 (OCSP), the CRL distribution points of RFC 5280 4.2.1.13, the SPIFFE ID specification and the Nginx, Envoy and HAProxy documentation. Every example certificate is synthetic, made for this site, and uses only the reserved example.com and example.net domains.