Internal certificate automation
A scheduled pipeline that issues a two-week certificate from my own certificate authority in HashiCorp Vault, checks it and installs it on the nginx reverse proxy that sits in front of my services.
The problem
The services I run at home have private names that no public certificate authority will sign for. I still want my browsers to trust them, and renewing certificates by hand is how they expire on a weekend.
In the middle: one nginx reverse proxy
On my main server, one nginx sits in front of the admin and infrastructure web interfaces I use. It holds the certificate, decides from the requested name and path where a request belongs, and passes it on. The services behind it can speak plain HTTP or bring their own self-signed certificate; my browser deals only with the proxy.
The proxy in the middle. The dashed line is what the rest of this page is about.
Two ways in
- At home: my router answers every name under my private domain with the proxy’s address, using one wildcard DNS record. A new service needs no DNS change.
- From outside: one public domain goes through Cloudflare Access and a Cloudflare Tunnel to the same proxy. A request for the public name that tries to skip the tunnel and arrive from my network is refused. Visitors on that route see Cloudflare’s certificate; mine is the one devices at home see.
What happens to a request
- Plain HTTP on a private name is redirected to HTTPS.
- TLS ends at the proxy, with versions 1.2 and 1.3 only.
- The name picks the service. One catch-all server block looks the name up in a table. A name that is not in the table gets the connection closed, with no page at all.
- A few services get their own block, where they need different handling, such as the WebSockets behind a virtual machine console.
- On the console’s own name, the path picks the service. My console answers there, and some admin interfaces live under paths of it. Before forwarding to one of those, nginx asks the console whether this browser is signed in. If it is not, the browser goes to the sign-in page and comes back afterwards. The console’s session cookie is not passed on to the application.
Simplified, with example names, the catch-all looks like this:
map $host $upstream {
default "";
"grafana.home.example" "http://grafana:3000";
"wiki.home.example" "http://wiki:80";
}
server {
listen 443 ssl;
server_name *.home.example;
ssl_certificate /etc/nginx/certs/fullchain.pem;
ssl_certificate_key /etc/nginx/certs/server.key;
resolver 127.0.0.11 valid=30s; # Docker's DNS
if ($upstream = "") { return 444; }
location / {
proxy_pass $upstream;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
How it is run
- A container with limits: nginx runs from a Compose file with memory, CPU and process limits. Its configuration and certificates are mounted read-only.
- Configuration in git, one file per concern or special server.
- No service addresses typed into those files. A script builds the lookup tables from values kept in Cloudflare Workers KV. It validates each value, writes the new file, runs
nginx -t, and puts the old file back if the test fails. Only then does it reload. If a value is missing or invalid, the last good one is kept, and a dry run shows the difference first. - One certificate for all of it, which is why renewing it has to be boring.
The trade-off is plain: one proxy is also one thing whose failure takes all those web pages with it.
The chain of trust
I run my own certificate authority in Vault: a root CA, and an intermediate CA that does the day-to-day signing. My host setup scripts install the root certificate, so each machine trusts whatever the intermediate issues.
One server certificate covers every internal service. The names live in a file in the repository, one per line, for example:
grafana.home.example
wiki.home.example
Adding a name to the certificate means adding a line, and the next run includes it.
How a renewal runs

One renewal: five jobs, all passed.
A GitLab pipeline runs every Sunday morning on my own runner. I can also start it by hand, or from a button in Backoffice that holds a token able to do nothing except start that project’s pipeline.
| Job | What it does |
|---|---|
| Unseal | Makes sure Vault is unsealed and able to sign |
| Authenticate | Logs in with an AppRole and gets a token |
| Issue | Requests the certificate, splits the answer into key, certificate and chain, and verifies the chain with openssl |
| Deploy | Copies the files to the proxy host, installs them owned by root with the key readable only by root, tests the nginx configuration and reloads it |
| Clean up | Removes working files and posts a message with the new expiry date to Discord |
Two checks stand between Vault and the running proxy. A chain that does not verify stops the pipeline before anything is copied. A configuration that nginx rejects stops it before the reload, so the running proxy keeps serving what it already had.
The reload is a reload, not a restart: nginx picks up the new certificate without dropping the service.
Why two weeks
Certificates last 14 days and are renewed weekly.
They used to last 7 days. With a weekly run, that left no slack at all: when a scheduled run failed on a runner timeout, I had only a few days to notice and run it again. At 14 days, a missed run leaves about a week to fix it.
Short lifetimes also limit the damage of a leaked key, and let me rely on expiry instead of on every client checking revocation.
Seeing what was issued

The certificate view in my console. The authorities are good for years. Server certificates last days, and old ones simply age out.
The console reads the list from Vault, so I can see every certificate with the time it has left. Its attention page also warns when the newest certificate for a name gets close to expiry, with thresholds that scale down for short-lived ones.
Without the pipeline
I keep a standalone Bash version of the same steps that can be run by hand on the proxy host. It is a second copy of the logic, so I have to keep the two in step.
What I would change
- Watch the certificate that is actually served, from outside the pipeline. The Discord message comes from the pipeline itself, and on the day the runner failed, no message arrived at all. The console shows what Vault issued, which is not proof of what the proxy serves.
- Make the install reversible. The new files replace the old ones before nginx tests them. Installing them alongside and switching over only after the test would leave a good copy on disk.