-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An equivalent of Apache's +ExportCertData in Caddy #6713
Comments
Thanks -- to clarify, it looks like, based on the forum topic, the request is actually for placeholders containing server cert info. |
Yes. it is. Meanwhile, I was able to use the placeholder for the client certificate, but with some unexpected behavior, which may warrant its own issue... Namely, when I enter the following into my Caddyfile:
the request header gets added even if there is no client cert provided, and populated with the literal "{http.request.tls.client.certificate_der_base64}" That is unexpected for me. I would expect the header either to be absent, or empty in that case. (If HTTP allows empty headers; IDK). Should I start another topic over that purpose? |
Ah, that's because in the header directive(s) only known placeholders are replaced. If there is no client certificate, the placeholder is not set. We can change this in one of two ways:
I'm leaning towards the second though, if we do make a change. |
The second variant feels more natural to me, too. |
Can you try this: @hasClientCert {
not vars {http.request.tls.client.certificate_der_base64} ""
}
request_header @hasClientCert +X-Tls-Client-Cert-Der-Base64 {http.request.tls.client.certificate_der_base64} |
Thanks for the workaround @steffenbusch ! I suppose we could still change the placeholders behavior in the case of client auth missing. |
@mholt is this issue still open? because i would like to take a try on this. |
As far as I know, it is not being worked on by anyone yet. |
@mholt got it, so i would start working on this. Could you give any advice on from where I should start? |
I would start in here: caddy/modules/caddyhttp/replacer.go Lines 399 to 492 in 1bd567d
|
@mholt So i did some research and found that apache mod_ssl env variables list is huge so do you want me to work on most common use env variables or each of those that mod_ssl provides in apache. I am pasting the screenshot for reference. |
If I may comment on this situation as a bystander with Apache experience: you can relatively easily parse the certificate details such as validity start by invoking openssl_x509_parse() on the certificate string SSL_CLIENT_CERT or SSL_SERVER_CERT, so the "details"-related variables such as SSL_CLIENT_V_START are somewhat less important to have. |
I think it's best to stay conservative in what we add, and only add what's needed. |
Yeah, already have some of those; I would stick to just the few that this issue is requesting, but even before that, if you want, we can make this adjustment: #6713 (comment) |
I agree that the second approach makes sense. By still parsing the placeholder and returning a value like "No Client cert provided" when no .ClientCert is available during runtime, we can gracefully handle scenarios where the user is not doing mTLS. |
Apache Webserver's mod_ssl has an optional configuration flag +ExportCertData, which is turned off by default (for performance reasons), but when turned on, it populates the superglobals with variables containing the current server and client certificate. To cite from the docs:
When this option is enabled, additional CGI/SSI environment variables are created: SSL_SERVER_CERT, SSL_CLIENT_CERT and SSL_CLIENT_CERT_CHAIN_n (with n = 0,1,2,..). These contain the PEM-encoded X.509 Certificates of server and client for the current HTTPS connection and can be used by CGI scripts for deeper Certificate checking. Additionally all other certificates of the client certificate chain are provided, too. This bloats up the environment a little bit which is why you have to use this option to enable it on demand.
This would be useful in Caddy too, as it would make migration of Apache-optimized apps to Caddy more straightforward. We had a debate with @francislavoie about the functionality here and I made case that it makes sense to have access to the server-side cert as well.
https://caddy.community/t/populating-server-server-cert-and-server-client-cert/26521
He recommended me to start an Issue on GitHub, so here I am. I know next to nothing about Caddy code, so I dare not submit a Pull request for that functionality.
The text was updated successfully, but these errors were encountered: