Different SSL Certificate for each Domain with TLS SNI#2509
Different SSL Certificate for each Domain with TLS SNI#2509andryyy merged 5 commits intomailcow:masterfrom
Conversation
|
Why do Postfix and Dovecot even need certificates for host names other than $MAILCOW_HOSTNAME? Proxying Postfix will likely break fail2ban because it won't pass through source IP addresses. Proxying port 25 would be really dangerous for that reason too (DNSBLs and trusted networks need the correct IP). |
|
Thanks for your feedback.
Postfix does not get any other certificates.
It does not break it, as dovecot will do the authentication in place of postfix, see this log from dovecot: which is the same format that f2b already recognized from imap / pop3. Port 25 is not proxied for the reason you mentioned - still directly mapped to postfix and not using SNI, only the server certificate. Is there any other reason why postfix might cause issues when mails from authenticated users are proxied? Any spam checks or similar stuff on outgoing mails? |
|
What is Does TLS (via STARTTLS) on port 587 still work?
Interesting. I did not know that that is how it works.
I don't think we do rate-limiting per IP, so that would be fine. |
That is correct and probably an issue atm. Thanks for pointing it out. I have researched this and think the XCLIENT commands from dovecot should solve this, which are already enabled by
Yes, STARTTLS on port 587 and direct SSL on 465 work with no issues in my tests. |
|
After some changes, postfix now gets the correct sasl_sender as authenticated in dovecot. However it's not applying the sender restrictions, still have to figure out how to apply them when relaying via dovecot. |
|
I have now figured out the correct XCLIENT config, turned out i had to whitelist the dovecot IP instead of hostname. Please let me know if you have further questions or concerns - or how I can improve this PR. |
|
I’m not sure I want Dovecot to do the submission. How does that limit our possibilities to configure the service in Postfix? You relay over port 25 back to postfix. You are always using an unencrypted connection. I know SOGo does the same, but one can avoid SOGo, while this would be active for all submissions. While I’m fine with this over sockets, we should avoid it for submission. How about failed certificate requests for a single domain? What’s the fall back? Where are additional SANs appended to? How do additional SAN migrate (or where to)? What if someone decided previously to add an additional SAN to connect to his mail server? This name is put into the general certificate of the server, I guess? I’m on mobile and haven’t checked yet, so I’m not sure if/how that’s added: What is the default host of each individual FQDN? Like “mail” in “mail.example.org”. Can people change that? If customer A asks for “mymx” and the other asks for “mail01”, it will probably fall back to the general certificate and they will see each other’s name in the certificate, right? I cannot add additional SANs per domain. Wouldn’t it be easier and less hassle to just place a HAProxy in front of mailcow? :/ |
I don't think it limits the possibilities with Postfix. The only thing i can think of that Postfix does not know about is the client connection encryption. Are there any rules regarding incoming connection encryption?
Yes, I am using Port 25 to avoid an additional tls overhead for each connection. We could change it to SSL or STARTTLS, but why do you think it is important in a container to container connection?
The same as before: The container will retry after 30 minutes instead of 1 day. Other certificates that were successful will still be activated immediately.
Yes. I am still using the same config value and domain variables: The only difference is that ADDITIONAL_WC_ARR will be used to create individual certificates, while ADDITIONAL_SAN_ARR will be appended to the default server certificate.
The default host will be the first domain.* available, in the order defined in the existing ADDITIONAL_SAN config. To change it one has to change the order in the ADDITIONAL_SAN config and it will be applied to all domains.
Yes this is true for this implementation, except if you apply the subdomain to every domain with mymx.* and mail01.*
The point of this PR was to make this work out of the box, without needing to configure and maintain an additional reverse proxy / loadbalancer, since all required tools are already included. Thank you for your feedback! |
Yes, you can require incoming TLS per user. It's not a commonly used feature of Mailcow because some mail servers still don't deliver over TLS, but in theory it's a nice frature that shouldn't be broken. |
|
Does this apply for submission by users or only incoming mail by other providers? If it's only the latter it should not be broken as port 25 is still directly mapped to postfix. |
|
TBH: I've no clue about the real advantages and if this is really necessary. In general I don't like the idea that Postfix is now depending on Dovecot to work. However. I'm not a fan of the migration over to certbot:
|
|
The reason i choose certbot is because it simplifies renewal and cert management, is well documentend, is the recommended acme client and offers a useful plugin and hooks system. The image size difference with certbot is 19MB and I personally prefer a long term reliable solution over a few megabytes. I'd like to know more about the reservations regarding the Dovecot submission proxy.
For me the Dovecot proxy is the natural choice in favor of additional software. Personally I'd require this feature for a seamless migration off cPanel and the confidence I don't need to create new instances or manage additional proxies when reaching a certain amount of domains. Looking at the previous issues I'd say there are also other people who would benefit from this. |
I'm actually not too concerned about it. It just needs extensive testing etc. and we need to check whether it breaks any Postfix feature we use or might use in the future. As @andryyy said,
If |
|
One thing I just thought of: you need to make sure that the same peivate key is used for the certificates as before. Otherwise existing TLSA records become invalid. Does your pull request generate a new key for each domain? Does it continue to use the key generated by the old acme client? |
|
OK this is a really good point. My PR will create a new private key for each domain and certbot will create a new one on each renewal (but that can be changed). If all the existing TLSA records must be re-used, we'd have to use the same private key for each domain and keep it forever. This definitely requires some additional changes for this PR. I'm thinking about some compatibility mode which is enabled on upgrades but disabled on new installations, because I don't think it is a good practice to re-use the private key for multiple certs (or even for a longer duration). I'll try to solve that as soon as I can. |
|
Thanks for all your work on this @mhofer117, I hope your changes are able to be merged at some point, I'm one of those people running a virtual server just for hosting For what it is worth I generally use acme.sh rather than certbot, it is written in Bash and does support ECC certs. |
e72f214 to
cd37435
Compare
|
I have reverted to use acme-tiny and using the existing private key for all certificates, so existing TLSA will still be valid for all domains. I also changed the PR description to match the changes. Let me know if you see any other possible issues, for exemple (as already mentioned) regarding Postfix features we use or might use in the future that could be affected by the dovecort proxy. |
|
This won't break |
|
Yes it still works as before |
|
Because the ECDSA PR #2443 looks complete and will probably be merged I have merged it into this PR too and made all required changes for SNI with both RSA and ECDSA certificates. Let me know if something is unclear or needs to be changed. |
|
I don't know if this is a merger tbh. I use custom submission configs quite often. That's to much of a hassle for the benefit in return. |
|
What type of custom submission configs? What would prevent you from still using them? |
|
Any updates on this? I would love to have these features added. |
|
I will not use Dovecot submission. |
|
It looks like this is a fix for the issue of "DNS setup issues for individual domains-> breaking many maildomains". |
Yes adding an FQDN only for one domain will always include it in the default certificate, the autogenerated certificates only contain entries for all domains (autoconfig.*, autodiscover.*, mail.*, ...). It would be quite complex to check every ADDITIONAL_SAN for matches against the DB and include them in the respective certificate (which could still be different than what the user actually wants). |
|
I have added the suggested check / fix. |
|
Ok, looks good to me. @andryyy, you can merge if you agree. We just need to remember that we cannot easily revert this pull request. Files would need to be moved back to their original location etc. So we will need to fix any bugs that may arise. I don‘t expect anything major to come up though (I‘ve tested it and @mhofer117 has done a solid job) and it‘s definitely a worthwhile improvement. |
|
Yes, looks good. I'm fine with it. |
|
I think you also need to rebuild postfix. 0efa5e5 only updates acme and dovecot. |
|
Thanks |
|
Thanks everyone for the feedback and recommendations! I'll follow the telegram chat and github to assist on any issues. |
|
Awesome, thanks guys! I'll update my installation next weekend. |
|
Looks good! Only thing I noticed is that this configuration does no longer work. Also tried commenting out the lines in listen_plain.active, but it gets reverted when restarting nginx. |
|
Did you pull the latest changes? There was a fix for this some hours ago. I also recommend not changing the site.conf but instead create a new file for this, for example: This prevents git conflicts |
|
Well, if that's broken and everyone needs to apply a change to site.conf to keep the redirect, that's not good. Your recent change should not break it, right? :) We should change the docs to redir.conf anyway, no matter if it works now, that's true. |
|
@mhofer117 Yes I did. The redirect.conf file doesn't work either :( |
No should not. I think that documentation page is misleading anyway. That config would also redirect acme challenges? And it includes the same domain names as the integrated server directive, so nginx will complain about duplicates. I think all of that was the case also before this PR. I have updated the docs here: mailcow/mailcow-dockerized-docs#175
Can you try the config from the documentation PR I linked? |
|
@mhofer117 Just tested it, doesn't work. Pretty sure it worked before the TLS-SNI update, at least a couple of weeks ago it did. |
|
Hmm I think i know why, let me test and provide a fix. |
|
I think the following PR fixes this: There is no reason why the TLS-SNI servers should also listen on http-80. Andre merged already, can you retest @Geitenijs |
|
@mhofer117 Great! It seems to work only for the mail. subdomains etc, but not for the server hostname (mx.example.com) @andryyy Shouldn't we just disable HTTP altogether by default? Always redirect to HTTPS, unless the server admin prefers to have HTTP support |
|
Check the latest change from andre: (server_name directive) |
|
@mhofer117 Sorry, missed that one. Works perfectly now, thanks! |
|
Has someone tested if the SNI extension works with wilcard domains (external acme client)? |
|
SNI is unrelated to wildcard certificates.
Please elaborate some more if you have a specific setup / question? |
|
Under data/assets/ssl/ a folder is created for each domain (e.g. mail.example.net), in this folder you will find cert.pem, key.pem and a domains file (e.g. mail.example.net). What I currently don't understand is how to name the domain folder and what I write to the domains file when I use a wildcard domain. According to Postfix instructions you should use .example.net, so I would name the folder "example.net" and write ".example.net" into the domains file. |
|
You are right, ENABLE_SSL_SNI is not relevant. |
|
so my test results: Postfix
Dovecot
Nginx (test port 8443)
so an adjustment in Dovecot script (Dockerfiles/dovecot/docker-entrypoint.sh) would be necessary (rewrite .example.net -> *.example.net) or you use *.example.net and adapt nginx and Postfix. |
|
Whatever you change. Make sure it does not break anything that works now. |
This addresses #461 and most of the related issues:
ENABLE_SSL_SNIwhich is disabled by default. It has to be specifically enabled or there will still be only one certificate (the same as before).data/assets/ssl/{certificate-name}/. The main server certificate will additionally be copied to the existing location directly atdata/assets/ssl/ENABLE_SSL_SNIis enabled.ADDITIONAL_SANconfigured in this format (subdomain.*)All existing config parameters and the default certificate location were unchanged. The user can also still place a custom default certificate which will disable acme.
Main benefit:
Drawbacks
In my test setup with a few domains, everything is working as expected, but further testing is probably a good idea.
If you see any problems with this PR or have major concerns let me know and i'll try to solve them.