Skip to content
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

add ssl certificate from letsencrypt #16

Closed
hadifarnoud opened this issue Jan 11, 2016 · 13 comments
Closed

add ssl certificate from letsencrypt #16

hadifarnoud opened this issue Jan 11, 2016 · 13 comments

Comments

@hadifarnoud
Copy link

how can I activate letsencrypt.org certificate on modoboa?

would be great to add this into run.py

@tonioo
Copy link
Member

tonioo commented Jan 11, 2016

For now, you can only specify custom SSL certificates within the configuration file:

[general]
tls_key_file = /etc/ssl/private/ssl-cert-snakeoil.key
tls_cert_file = /etc/ssl/certs/ssl-cert-snakeoil.pem

@inkrement
Copy link

How to proceed if it's intended to add certificates after installation? Is there an (easy) way without the need to dig into postfix or dovecot configs?

@tonioo
Copy link
Member

tonioo commented Mar 11, 2016

Modify the default values inside installer.cfg and then copy certificate files at the proper location.

@inkrement
Copy link

The installer.cfg is part of the installer, right? But I have already installed it (and I removed the installation folder). How can I change these settings afterwards?

@tonioo
Copy link
Member

tonioo commented Mar 14, 2016

Then you need to modify each configuration file (postfix, dovecot, etc.).

@dhaupin
Copy link

dhaupin commented Sep 1, 2016

This is the first result for "modoboa letsencrypt". Really, all this needs to work is a pub .well-known folder somewhere to run and update later (via cron or something). Just tried LE and it wanted to work but I gotta pack for camping and dont have much time to probe modoboa this eve beyond brief tries.

@dhaupin
Copy link

dhaupin commented Sep 2, 2016

Ok, I got a min, here is how you do a LE cert:

  1. Create a .well-known folder:
    # mkdir /srv/modoboa/instance/sitestatic/.well-known

  2. Edit the port 80 server block to use this:

server {
    listen 80;
    server_name mail.example.com;

    location / {
        rewrite ^ https://$server_name$request_uri? permanent;
    }

    location /.well-known/ {
        alias /srv/modoboa/instance/sitestatic/.well-known/;
    }
}
  1. Restart nginx then run the LE certonly:
# nginx -t
# service nginx restart
# letsencrypt certonly --webroot -w /srv/modoboa/instance/sitestatic/ -d mail.example.com
  1. Edit the port 443 server block to use new certs:
...
ssl_certificate /etc/letsencrypt/live/mail.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/mail.example.com/privkey.pem;
...
  1. Restart nginx, check the URL. Apply cert to any other services you need such as dovecot. (SNI is possible, but manual and beyond this scope.) Edit /etc/dovecot/conf.d/10-ssl.conf and change the cert + key:
...
ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem
...

Then edit /etc/postfix/main.cf and change the cert + key:

...
smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem
smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem
...
  1. Make a cron to auto-renew (# crontab -e), in this case at 5:43 am daily. You should pick a random time that is not on the hour and def not at midnight (to prevent DDOS'ing LE):
    43 5 * * * /usr/bin/letsencrypt renew 2>&1 | /usr/bin/logger -t letsencrypt

  2. Profit.

@hadifarnoud
Copy link
Author

please send a Pull Request for this feature. would love to try it

@hadifarnoud hadifarnoud reopened this Sep 3, 2016
@dhaupin
Copy link

dhaupin commented Sep 7, 2016

@hadifarnoud Would like to man, not much time lately though. I would have to further explore the installer itself, figure out how to check for a fail state if LE can't generate a cert or times out, and also support SNI based on added domain(s). Maybe it can be a "standalone" plugin or something instead of at install, dunno. Added a few steps for Dovecot/Postfix above.

@tonioo
Copy link
Member

tonioo commented Sep 21, 2016

@dhaupin Thanks you for the feedback. I close this issue since it's a duplicate of #50 .

@tonioo tonioo closed this as completed Sep 21, 2016
@dbryar
Copy link

dbryar commented Aug 15, 2020

since this is the highest ranked page on LE certificate errors on Google, I'll just point out that while @dhaupin instructions are all correct, if you are using LE, you may need to reboot the server/restart the services after the new certificate is loaded each 90 day period.

I was finding it very hard to determine why the mail server (postfix) was still issuing an expired certificate despite the webmail (nginx) certificate being valid, and both pointing to the same file.

Something to note on very stable servers!

@blu-IT
Copy link

blu-IT commented Mar 18, 2021

2. Edit the port 80 server block to use this:
server {
    listen 80;
    server_name mail.example.com;

    location / {
        rewrite ^ https://$server_name$request_uri? permanent;
    }

    location /.well-known/ {
        alias /srv/modoboa/instance/sitestatic/.well-known/;
    }
}

Thanks a lot! Worked perfect for me, after that I had already rolled out the server with a self-signed certificate accidently!
Had only to add these lines also to the already existing config for port 443: Then I could start LE certification process.
Working on Ubuntu 18.04 LTS

location /.well-known/ {
         alias /srv/modoboa/instance/sitestatic/.well-known/;
     }

@QThans
Copy link

QThans commented Apr 6, 2024

5. /etc/dovecot/conf.d/10-ssl.conf

After updating, a restart is required.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants