-
Notifications
You must be signed in to change notification settings - Fork 66
Added how to use Caddy Certificate for Postal #80
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,6 +21,107 @@ You can use the command below to generate a self-signed certificate. | |
| openssl req -x509 -newkey rsa:4096 -keyout /opt/postal/config/smtp.key -out /opt/postal/config/smtp.cert -sha256 -days 365 -nodes | ||
| ``` | ||
|
|
||
| ### Using Caddy certificate for TLS | ||
|
|
||
| #### Setup automatic copying from Caddy to Postal | ||
|
|
||
| To remove the need of the manual maintenance task to copy the certificate from Caddy to Postal, we can automate this. The original discussion and author can be found [here](https://github.com/orgs/postalserver/discussions/2673). | ||
|
|
||
| ##### Install inotify-tools | ||
|
|
||
| Install the toolset which provides `inotifywait`, used to monitor certificate changes. | ||
|
|
||
| ```bash | ||
| sudo apt-get update | ||
| sudo apt-get install inotify-tools | ||
| ``` | ||
|
|
||
| ##### Create Monitoring Script | ||
|
|
||
| Create a script named `monitor_certs.sh`: | ||
|
|
||
| ```bash | ||
| nano /opt/postal/monitor_certs.sh | ||
| ``` | ||
|
|
||
| Add following code to the script file: | ||
willpower232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| #!/bin/bash | ||
|
|
||
| CERT_DIR="/opt/postal/caddy-data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/YOURDOMAIN/" | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this only work if you have caddy installed directly on the server or are you mapping a docker volume to get this out of the container?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes this is for a direct install on the server, if it is in a docker volume, you'd probably have to adjust the paths
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. having just re-familiarised myself with the docs https://docs.postalserver.io/getting-started/installation#caddy looks like you have used the docker paths right?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As yes, of course, wherever possible i used the docker installation path and information |
||
| CERT_FILE="${CERT_DIR}YOURDOMAIN.crt" | ||
| KEY_FILE="${CERT_DIR}YOURDOMAIN.key" | ||
|
|
||
| while true; do | ||
| inotifywait -e modify "$CERT_FILE" "$KEY_FILE" | ||
|
|
||
| # Copy the certificates to Postal's configuration directory | ||
| cp "$CERT_FILE" /opt/postal/config/smtp.cert | ||
| cp "$KEY_FILE" /opt/postal/config/smtp.key | ||
|
|
||
| # Adjust permissions to ensure Postal can read the certificates | ||
| chmod o+r /opt/postal/config/smtp.* | ||
|
|
||
| # Restart Postal to use the new certificates | ||
| postal restart | ||
| done | ||
| ``` | ||
|
|
||
| Make the script executable: | ||
| ```bash | ||
| chmod +x /opt/postal/monitor_certs.sh | ||
| ``` | ||
|
|
||
| ##### Create a systemd Service | ||
|
|
||
| Make a systemd service file: | ||
willpower232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| sudo nano /etc/systemd/system/monitor_certs.service | ||
| ``` | ||
|
|
||
| Insert the following content: | ||
willpower232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```yaml | ||
| [Unit] | ||
| Description=Monitor Caddy Certificates for Postal | ||
|
|
||
| [Service] | ||
| ExecStart=/opt/postal/monitor_certs.sh | ||
| Restart=always | ||
| User=your_username | ||
| Group=your_groupname | ||
|
|
||
| [Install] | ||
| WantedBy=multi-user.target | ||
| ``` | ||
|
|
||
| ##### Activate the Service | ||
|
|
||
| Reload the systemd daemons: | ||
|
|
||
| ```bash | ||
| sudo systemctl daemon-reload | ||
| ``` | ||
|
|
||
| Enable and start the service: | ||
willpower232 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ```bash | ||
| sudo systemctl enable monitor_certs.service | ||
| sudo systemctl start monitor_certs.service | ||
| ``` | ||
|
|
||
| ##### Initial Manual Certificate Copy | ||
|
|
||
| Before the monitoring script takes over, you should manually copy the certificates for the first time: | ||
|
|
||
| ```bash | ||
| cp /opt/postal/caddy-data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/YOURDOMAIN/YOURDOMAIN.crt /opt/postal/config/smtp.cert | ||
| cp /opt/postal/caddy-data/caddy/certificates/acme-v02.api.letsencrypt.org-directory/YOURDOMAIN/YOURDOMAIN.key /opt/postal/config/smtp.key | ||
| chmod o+r /opt/postal/config/smtp.* | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| Once you have a key and certificate you will need to enable TLS in the configuration file (`/opt/postal/config/postal.yml`). Additional options are available too. | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.