There are some services that I expose to the internet (using Apache reverse proxy) that really should be accessed by only a small set of devices. Requiring client certificates seems like a great way to reduce the attack surface and prevent brute force attacks (since the attacker doesn’t even get a chance to attempt a login).
I wonder about the difficulty on the client side as well as other practical implications. The clients are smartphones of various makes.


It’s very easy to make a custom CA and issue certs. Here’s a good tutorial.
Unfortunately in practice It depends greatly on what’s on the other side (the client app). Some examples:
Oh did I mention how you get a mTLS client cert to an app on an iOS device? You send it over email to an account that the device has access to through the Mail app, then share the attachment. Yep.
It’s also not exactly straightforward to use mTLS with reverse proxies.
Let’s take for example Caddy and say you want unconditional mTLS for all reverse proxy hosts. Easy enough:
tls /path/to/domain-cert/fullchain.pem /path/to/domain-cert/privkey.pem { client_auth { mode required trust_pool file /path/to/custom/ca.pem } }But suppose you don’t want unconditional mTLS, you’d like to let clients in if they have mTLS or a custom header, or do different things depending if the client has valid mTLS or not. Does Caddy offer a built-in conditional to act on mTLS status? Nope!
As a workaround I’m setting the client_auth mode to
verify_if_givenand then using a DIY conditional that checks if the variablehttp.request.tls.client.certificate_der_base64is empty or not. But it’s undocumented so who knows if it may break at any point.For reference, how you handle both custom headers and mTLS at once (after setting the mode as I’ve mentioned):
@immich host "whatever.example.com" handle @immich { @not_authorized { not header X-Custom-Pass "LONGRANDOMKEY01" # jim not header X-Custom-Pass "LONGRANDOMKEY02" # bob vars_regexp {http.request.tls.client.certificate_der_base64} ^$ } error @not_authorized 403 reverse_proxy http://immich.lan:port }The nested “not not” is required because Caddy can only do logical AND in group conditionals, so to do logical OR you basically have to do NOT (NOT a AND NOT b).
In caddy, isn’t an OR is just two separate blocks?
@authorized { header X-Custom-Pass “LONGRANDOMKEY01” # jim } @authorized { header X-Custom-Pass “LONGRANDOMKEY02” # Bob }
I could be wrong. Caddy config is a dark art.
Lol I don’t know, I’ll have to try. I would’ve never thought of it. If it works it’s definitely not intuitive. Dark art indeed.