Saturday, December 5, 2026

Automating Let’s Encrypt Wildcard Certificates with OPNsense and TrueNAS

The cryptic post quantum notification made me realize I did not post this when I developed it last year. Enjoy!

Overview

Like many of you, I use Let’s Encrypt (LE) certificates to secure web services across my systems whenever possible. Because these certificates expire every 90 days—and are heading down to 45 days—I looked for a way to automate the renewal process. I didn't find an existing solution I liked, so I built my own. My goal was to manage all of my certificates centrally and push them out to the relevant systems. Generally, I use wildcard certificates for the subdomains in each of my environments, alongside a few specific host certificates.

My physical infrastructure has become fairly streamlined: I run a two-node compute cluster on Proxmox VE (migrated from a single VMware ESXi) paired with TrueNAS SCALE (formally CORE) for storage, linked over a dedicated 40Gbit DAC network. My firewall runs on its own dedicated hardware, and I also maintain other, simplified environments where storage is virtualized on a single PVE host.

To centralize certificate management, I chose to handle renewals directly on OPNsense. Its ACME client is feature-rich and natively supports DNS-01 verification with Cloudflare, where my domains are hosted. Since the firewall is already the most locked-down device on my network, keeping my Cloudflare API keys isolated there made the most sense. (I won't cover the initial ACME setup here, as Dustin over at Home Network Guy already has a great guide on it.)

The next step was distributing the renewed certificates and updating the downstream systems. Rather than running custom deployment scripts directly on my firewall, I configured OPNsense to push the certificates via SFTP to my TrueNAS SCALE box, which handles the heavy lifting of distributing them. (I may offload this job to a dedicated, general-purpose VM or container down the road.) Authentication between these systems is handled via SSH keys which I touch on briefly here;  though plenty of in-depth guides already exist out there.

Configuring the SFTP automation in OPNsense isn't entirely intuitive, so it took a bit of trial and error to get right. Once configured, you just attach the SFTP automation action directly to your Let's Encrypt certificate. I had the the renewal job set to run weekly but have changed it to daily, ensuring it easily catches the standard 2/3 lifetime renewal window. To setup:

On your OPNSense go to Services | ACME Client | Automation

Create a new automation and select Upload certificate via SFTP and configure as you see fit.


For the Host Key, via terminal on the OPNSense run this and paste the entire string returned

 #ssh-keyscan -t ecdsa mytruenas.mydomain.com

For Username, use root unless you create separate accounts for tasks. Be sure to give this account relevant write permissions to the Remote Path.

Put the OPNSense public key into /root/.ssh/authorized_keys (or the user) on your TrueNAS. Or via its GUI at Credentials | Backup Credentials | SSH Key Pairs. You can click Show Identity to get this. Note the entire string as its limited to SFTP use. 

Once complete, click Test Connection to validate, then Save.  

Finally, go to Services | ACME Client | Certificates | Certificates and add it to Automations for the certificate(s).


The main wrapper script compares fingerprints between two hosts—in my setup, it checks OPNsense against TrueNAS, though you can also configure it to check against a local file or another host. If the fingerprints match, the script exits gracefully. If they don't, it runs the update commands you’ve defined at the end of the wrapper script to push changes to your systems. I intentionally kept error handling and notifications to a minimum since I'm constantly swapping out the services I run.

I'll put all my scripts in my GitHub for this article and will add more there as I develop new ones. With the Qualcomm shenanigans around VMWARE, I have moved to ProxMox since starting this, along with Unifi and hardware changes. These scripts were done to be adaptable across environments and versions. If I engaged any AI, I noted it.  

Some systems of Note

Ubiquiti Unifi Controllers

Hands down Glenn R script to do the heavy lifting. I initially ran the VM controller on a VM using his install script which I discuss here, however I tinkered with a CloudKey controller for a while since I was trying out some of their cameras but have centralized on a different brand so am back at a container now for the network controller. You can find his cert update script here which updates all the different Unifi controllers since its done in the middleware. I do have a tiny wrapper that I use to scp the certs and call his script located on the controller.

TrueNAS CORE/SCALE

For this I use danb35 script locally on the TrueNAS as like the Unifi, its done in the middleware and not part of the OS. 

HPE iLO 

Not a fan of HPE so I sold these servers off. Doesn't appear to support import via CLI, only GUI but this option is promising. 

Dell iDrac

Still working on this one as I do not have a Dell PE at the moment. iDRAC7 and up support wildcards. Best I can find is that you have to use the GUI or racadm which is not available on FreeBSD that TrueNAS CORE is built on but TRUENAS SCALE will probably work since its LINUX based. Step 3 in this Dell doc shows how to do it with racadm. Along with another guide. 

VMWare ESXi

Since I formally had one compute host at each site I saw no reason to use Vcenter. This one is really easy and I have a script for it on GitHub.

Windows Server

You really should use Active Directory Certificate Services (ADCS) if you have a domain going as it will faciliate certs for all hosts in your domain and then some. However to see if it works with LE I have the firewall requesting host specific certs for my Windows Servers and have some scripts in GitHub that also sets RDP to use the LE cert. On any DC's a cert will light up secure communication from member computers, even if the cert expires later.

You can’t import an LE key.pem and fullchain.pem directly into the Windows Certificate Store as‑is, because Windows requires certificates with private keys to be in a single, combined container format. I use a simple OpenSSL command to generate this but I do want to wrap it.

 #openssl pkcs12 -export -inkey /path/to/certs/hostname/key.pem -in /path/to/certs/hostname/fullchain.pem -out /path/to/certs/saved/hostname.pfx -password pass:yourpasswordhere
 #chmod 644 /path/to/certs/saved/hostname.pfx

Then two other scripts to import and set SDP to it along with clearing out expired LE certs. I keep the Windows scripts in DFS and the pfx is on TrueNAS as its joined to the domain and I gave perms to the systems to access their cert. 

While I did this on my own more as an experiment, it has worked well, there is a fantastic option in POSHACME.

Mikrotik

I have a script but here are various sources on it.

  • https://github.com/dualmi/letsencrypt-routeros_acme.sh
  • https://github.com/smoix/letsencrypt-mikrotik-cert
  • https://me.sdnix.com/mikrotik-lets-encrypt-wildcard-ssl-certificate/


-Kevin Fason



No comments:

Post a Comment