This will configure an Asustor NAS running ADM 5 to use a letsencrypt issued certificate without exposing the NAS to the internet (by using DNS Challenge instead of using port forwarding). To accomplish this, we need to use certbot with DNS-01 challenge to Cloudflare. To perform this task, you must SSH into the NAS.
- Elevate the terminal to root
sudo su
- Setup the required directories
mkdir -p /volume1/system/letsencrypt
chown root:root /volume1/system/letsencrypt
chmod 700 /volume1/system/letsencrypt
mkdir -p /volume0/usr/builtin/etc/certificate/letsencrypt/renewal-hooks/deploy
chown root:root /volume0/usr/builtin/etc/certificate/letsencrypt -R
chmod 700 /volume0/usr/builtin/etc/certificate/letsencrypt/ -R
- Set up the Cloudflare credentials
touch /volume1/system/letsencrypt/cloudflare.ini
chmod 600 /volume1/system/letsencrypt/cloudflare.ini
Add the Cloudflare API key based on the instructions found at the link below: https://certbot-dns-cloudflare.readthedocs.io/en/stable/#credentials
-
Copy the other scripts in this gist (install.sh and adm-deploy.sh) to the
/volume1/system/letsencrypt
directory, you can use thevi
text editor. -
Run install.sh to setup pip and certbot-dns-cloudflare.
cd /volume1/system/letsencrypt
sh install.sh
- Link the adm-deploy script to function as a letsencrypt deploy hook so that once a renewal occurs, the system will automatically replace the existing certificate and restart the lighttpd web server.
ln -s /volume1/system/letsencrypt/adm-deploy.sh /volume0/usr/builtin/etc/certificate/letsencrypt/renewal-hooks/deploy/
- Generate the host certificate, ensure that you replace the
nas.mydomain.com
with the actual hostname for your NAS!
certbot certonly --config-dir=/volume0/usr/builtin/etc/letsencrypt \
--dns-cloudflare --dns-cloudflare-credentials /volume1/system/letsencrypt/cloudflare.ini \
--preferred-challenges dns-01 \
-d nas.mydomain.com
- Add renewal tasks to crontab (you can find them here:
/var/spool/cron/crontabs/root
or execute the commandcrontab -e
)
@reboot /volume1/system/letsencrypt/install.sh && /usr/bin/certbot --config-dir=/volume0/usr/builtin/etc/certificate/letsencrypt renew
0 6 * * * /usr/bin/certbot --config-dir=/volume0/usr/builtin/etc/certificate/letsencrypt renew