A tiny, single-shot container that installs a supplied certificate and private key into the TrueNAS web UI over the REST API.
- Compares the supplied certificate with the certificate currently used by the web UI and does nothing when the active certificate is the same or newer.
- Imports and activates the new certificate when needed.
- Restarts the TrueNAS web service and verifies the HTTPS endpoint.
- Optionally removes old certificates created by this tool, keeping a configurable number for rollback.
- Configured with command-line flags or environment variables.
- No websocket usage and no runtime dependencies.
- Final image is built
FROM scratch, runs as non-root, and is roughly 7 MB uncompressed (about 3 MB compressed).
| TrueNAS version | Support |
|---|---|
| CORE 13.x | Yes, via REST API v2.0 |
| SCALE 24.04 – 25.10 | Yes, via REST API v2.0 |
| SCALE 26+ | No: REST API v2.0 was removed; the new websocket API is required |
The tool intentionally targets the REST API so that TrueNAS CORE remains
supported. TrueNAS 26 and newer can only be supported with a websocket
backend, which is outside this project's current scope.
- Reads and validates the supplied certificate, full chain, and private key.
- Reads
system.general.ui_certificateand the current certificate list. - Compares SHA-256 fingerprints. An identical active certificate is a no-op.
- If the active certificate expires later than the supplied one, it is a no-op
unless
FORCE_UPDATE=true. - Reuses an already-imported copy of the supplied certificate when one exists; otherwise the certificate is imported with a timestamped name.
- Points
system.general.ui_certificateat the certificate and callssystem.general.ui_restart. - Waits for the API to return and compares the certificate served over HTTPS with the supplied certificate (advisory warning on mismatch).
- Deletes old certificates whose names start with
CERT_NAME_PREFIX, keeping the active certificate plusRETAIN_COUNTprevious certs.
The update is idempotent: running the container repeatedly is safe. It is designed to be run from cron, systemd timers, a Kubernetes CronJob, a certbot deploy hook, or a TrueNAS cron job after certificate renewal.
- Create an API key in TrueNAS: System Settings → API Keys.
- Put the certificate and key in a directory with the standard TLS names:
/mnt/tank/certs/tls.crtand/mnt/tank/certs/tls.key. - Run:
docker run --rm \
-v /mnt/tank/certs:/certs:ro \
-e TRUENAS_URL=https://truenas.local \
-e TRUENAS_API_KEY=your-api-key \
-e TRUENAS_INSECURE=true \
ghcr.io/k-web-s/truenas-https-cert-updater:latestTRUENAS_INSECURE=true is needed if TrueNAS still serves a self-signed
certificate. Better: mount a CA bundle and use TRUENAS_CA_FILE instead.
Make sure the container can resolve and reach the TrueNAS hostname. Use an IP address, a DNS entry available inside the container, or host networking if necessary.
Every option is a command-line flag and an environment variable. The environment
name is the uppercase flag name with - replaced by _. Command-line values
take precedence over environment variables.
docker run --rm ghcr.io/k-web-s/truenas-https-cert-updater:latest -hExample excerpt:
Usage: truenas-cert-updater [options]
Every flag can also be set with an environment variable:
uppercase the flag name and replace "-" with "_".
Example: -truenas-url -> TRUENAS_URL
Command-line values take precedence over environment variables.
Options:
-cert-file="/certs/tls.crt": PEM certificate file; a full chain is allowed
-key-file="/certs/tls.key": PEM private key file
-retain-count=2: number of old managed certificates to keep after the active one
-truenas-url="": TrueNAS base URL, for example https://truenas.local
docker run --rm ... ghcr.io/k-web-s/truenas-https-cert-updater:latest -dry-runor set DRY_RUN=true. Dry-run mode still reads the current state and logs what
would happen, but never imports, switches, restarts, or deletes anything.
The default certificate paths match the standard Kubernetes TLS secret naming:
/certs/tls.crt/certs/tls.key
Create the secrets:
kubectl create secret tls truenas-ui-tls \
--cert=fullchain.pem \
--key=privkey.pem
kubectl create secret generic truenas-api-key \
--from-literal=api-key='your-truenas-api-key'Then apply the example CronJob:
kubectl apply -f deploy/kubernetes/cronjob.yamlThe example mounts:
- the TLS secret at
/certs, - the API key secret at
/run/secrets, TRUENAS_API_KEY_FILE=/run/secrets/api-key.
It also runs as UID/GID 65532 with a read-only root filesystem, no privilege
escalation, and all Linux capabilities dropped.
The container runs once and exits, so it is suitable for a Kubernetes
CronJob, a one-off Job, or an external scheduler. concurrencyPolicy: Forbid in the example prevents overlapping runs.
Each row can be supplied as a command-line flag or as the listed environment variable.
| Flag | Environment | Default | Description |
|---|---|---|---|
-truenas-url |
TRUENAS_URL |
required | TrueNAS base URL, e.g. https://truenas.local. https:// is assumed when no scheme is given. |
-truenas-api-key |
TRUENAS_API_KEY |
required* | TrueNAS API key. |
-truenas-api-key-file |
TRUENAS_API_KEY_FILE |
— | Read the API key from a file. Takes precedence over TRUENAS_API_KEY. |
-cert-file |
CERT_FILE |
/certs/tls.crt |
PEM certificate. A full chain is allowed. |
-key-file |
KEY_FILE |
/certs/tls.key |
PEM private key. |
-cert-pem |
CERT_PEM |
— | Inline certificate PEM. Takes precedence over CERT_FILE. |
-key-pem |
KEY_PEM |
— | Inline private key PEM. Takes precedence over KEY_FILE. |
-cert-name-prefix |
CERT_NAME_PREFIX |
truenas-ui |
Prefix used for imported certificate names and pruning. |
-retain-count |
RETAIN_COUNT |
2 |
Number of old managed certificates to keep after the active one. |
-prune-old-certs |
PRUNE_OLD_CERTS |
true |
Delete older certificates created by this tool. |
-force-update |
FORCE_UPDATE |
false |
Update even when the supplied certificate is not newer. |
-dry-run |
DRY_RUN |
false |
Do not modify TrueNAS. |
-truenas-insecure |
TRUENAS_INSECURE |
false |
Skip TrueNAS TLS verification. |
-truenas-ca-file |
TRUENAS_CA_FILE |
— | Extra CA bundle used to verify the TrueNAS endpoint. |
-restart-ui |
RESTART_UI |
true |
Restart the web UI after switching the certificate. |
-restart-delay |
RESTART_DELAY |
1s |
Delay passed to the UI restart API. |
-restart-wait |
RESTART_WAIT |
1m |
How long to wait for the API to become responsive again. |
-verify-served-cert |
VERIFY_SERVED_CERT |
true |
Check the certificate served over HTTPS after the restart. |
-verify-timeout |
VERIFY_TIMEOUT |
15s |
How long to wait for the served certificate to match. |
-http-timeout |
HTTP_TIMEOUT |
30s |
Normal API request timeout. |
-job-timeout |
JOB_TIMEOUT |
2m |
Certificate import/delete job timeout. |
-log-level |
LOG_LEVEL |
info |
debug, info, warn, or error. |
-log-format |
LOG_FORMAT |
text |
text or json. |
-print-version |
PRINT_VERSION |
— | Print the version and exit. |
* Exactly one of TRUENAS_API_KEY or TRUENAS_API_KEY_FILE must be set.
Inline PEM values may use literal \n sequences instead of real newlines, which
is convenient with CI secret stores. Duration values use Go duration syntax,
such as 500ms, 30s, or 2m. For boolean environment variables, use an
explicit true or false.
- The certificate must be valid now (not expired and not not-yet-valid).
- The private key must match the leaf certificate.
- Unencrypted PEM keys are supported. Encrypted private keys are not.
- A full chain (
leaf + intermediates) is accepted. The leaf must come first. - The UI certificate is selected by the supplied certificate's expiration date.
Different certificates with the same expiration date are treated as equally
old; use
FORCE_UPDATE=trueto replace them anyway.
Imported certificates are named like:
truenas-ui-20261123-083000-a1b2c3d4
Only certificates whose names start with CERT_NAME_PREFIX followed by - are
candidates for pruning. Other certificates are never touched.
After a successful switch, the updater keeps:
- the active certificate, plus
- the
RETAIN_COUNTnewest previously managed certificates (default2).
Older managed certificates are deleted. Deletion is never forced: if an old certificate is still attached to another TrueNAS service, deletion fails and a warning is logged. Pruning failures do not fail the certificate update.
Set RETAIN_COUNT=0 to delete all old managed certificates after a successful
update, or PRUNE_OLD_CERTS=false to disable pruning.
The container runs once and exits. Schedule it however you prefer.
Host cron:
15 4 * * * docker run --rm -v /mnt/tank/certs:/certs:ro --env-file /etc/truenas-cert-updater.env ghcr.io/k-web-s/truenas-https-cert-updater:latestKubernetes:
kubectl apply -f deploy/kubernetes/cronjob.yamlA certbot deploy hook can run the same command immediately after renewal:
#!/bin/sh
docker run --rm \
-v /etc/letsencrypt/live/example.com:/certs:ro \
-e CERT_FILE=/certs/fullchain.pem \
-e KEY_FILE=/certs/privkey.pem \
--env-file /etc/truenas-cert-updater.env \
ghcr.io/k-web-s/truenas-https-cert-updater:latestBecause repeated runs are no-ops when the certificate is already active, it is safe to schedule more often than the certificate's renewal interval.
The image runs as UID/GID 65532:65532. Mounted certificate, key, and API-key
files must be readable by that user. Options:
- make the files world-readable (not ideal for a private key),
- change group ownership/permissions on the host,
- override the container user to match the host file owner,
- or use
fsGroup: 65532in Kubernetes with secret file mode0440.
Docker example:
docker run --rm --user "$(id -u):$(id -g)" ...The API key is a privileged secret. Prefer TRUENAS_API_KEY_FILE or a Docker
secret over passing it in the environment, and keep the file mode at 0600.
| Exit code | Meaning |
|---|---|
0 |
Success, including no-op and successful update |
1 |
Runtime/API/certificate error |
2 |
Invalid configuration |
Logs go to stderr. Set LOG_FORMAT=json for structured logs. Secrets are never
logged.
go test ./...
docker build -t truenas-cert-updater .
docker run --rm truenas-cert-updater -print-version
docker run --rm truenas-cert-updater -hThe Dockerfile builds a static binary in golang:1.25-alpine, then copies only
the binary and the CA bundle into a scratch image. There is no shell, package
manager, or temporary tooling in the final image.
Multi-arch images are published to:
ghcr.io/k-web-s/truenas-https-cert-updater
Tags:
lateston the default branch and version tags,edgeonmain,- semantic version tags such as
1.2.3,1.2, and1, - short commit SHA tags,
pr-<number>tags for pull requests (not pushed).
Supported platforms: linux/amd64 and linux/arm64.
- TLS verification of the TrueNAS endpoint is enabled by default.
TRUENAS_INSECURE=truedisables verification and should only be used on a trusted network or with a self-signed appliance.- Restarting the UI briefly interrupts the web UI and API connections.
- Verification of the served certificate is advisory because TrueNAS may sit behind a reverse proxy. The configured certificate ID is always confirmed through the API.
- The final image contains no shell and runs as a non-root user.