Replacing a Raspberry Pi with a FreeBSD Jail for a ZFS Key Server
Replacing a Raspberry Pi with a FreeBSD Jail
An ESP32 or Raspberry Pi works well for serving a ZFS encryption key, but if you already have a FreeBSD server, an isolated jail is often simpler to manage. You gain snapshots, package management, backups, and native service management without adding another device to your network.
This guide creates a dedicated keyserver jail running nginx that serves a single key file over HTTPS with mutual TLS (mTLS).
Create the Jail
Using Bastille:
pkg install -y bastille
sysrc bastille_enable=YES
bastille bootstrap 15.1-RELEASE
bastille create keyserver 15.1-RELEASE 192.168.1.50
Enter the jail:
bastille console keyserver
Install nginx:
pkg install -y nginx
sysrc nginx_enable=YES
Create the Directory
mkdir -p /usr/local/www/keyserver
cp /root/zfs.key /usr/local/www/keyserver/
chmod 0400 /usr/local/www/keyserver/zfs.key
chown root:wheel /usr/local/www/keyserver/zfs.key
Install Certificates
Place these in /usr/local/etc/nginx/:
server.crt
server.key
ca.crt
server.crt— server certificateserver.key— private keyca.crt— CA that issued client certificates
nginx Configuration
/usr/local/etc/nginx/nginx.conf
events {}
http {
server {
listen 443 ssl;
server_name keyserver;
ssl_certificate server.crt;
ssl_certificate_key server.key;
ssl_client_certificate ca.crt;
ssl_verify_client on;
ssl_protocols TLSv1.3 TLSv1.2;
root /usr/local/www/keyserver;
location = /zfs.key {
default_type application/octet-stream;
try_files /zfs.key =404;
}
location / {
return 404;
}
}
}
Validate and start nginx:
nginx -t
service nginx start
Test
Without a client certificate:
curl https://192.168.1.50/zfs.key
Expected:
400 No required SSL certificate
With a client certificate:
curl \
--cert client.crt \
--key client.key \
--cacert ca.crt \
https://192.168.1.50/zfs.key
The raw key should be returned.
ZFS Boot Script
Set the dataset's keylocation to the keyserver URL, then ZFS can fetch and load the key natively over mTLS — no separate fetch step needed:
zfs set keylocation=https://192.168.1.50/zfs.key tank/encrypted
When the key is loaded, ZFS authenticates against the server with a client certificate configured via environment variables:
export SSL_CA_CERT_FILE=/etc/ssl/ca.crt # trust the server's CA
export SSL_CLIENT_CERT_FILE=/etc/ssl/client.crt # present to the server
export SSL_CLIENT_KEY_FILE=/etc/ssl/client.key
zfs load-key tank/encrypted
zfs mount tank/encrypted
zfs load-key fetches the key from the HTTPS URL (using fetch(3)/libcurl) and loads it; zfs mount then mounts the now-decrypted dataset. The CA and client certificate/CA file paths come from the SSL_CA_CERT_FILE, SSL_CLIENT_CERT_FILE, and SSL_CLIENT_KEY_FILE environment variables (use SSL_CA_CERT_PATH for a directory bundle).
Fallback: explicit fetch
If your ZFS build lacks HTTPS key fetching support, fetch the key yourself and pipe it in:
KEY=$(fetch -qo - \
--ca-cert=/etc/ssl/ca.crt \
--client-cert=/etc/ssl/client.crt \
--client-key=/etc/ssl/client.key \
https://192.168.1.50/zfs.key)
echo "$KEY" | zfs load-key tank
zfs mount tank
Run whichever variant you use during boot before importing encrypted datasets.
Hardening
- Serve exactly one file.
- Disable directory listings.
- Require mTLS for every request.
- Keep the jail dedicated to this single service.
- Store the key on its own ZFS dataset.
- Snapshot the jail before configuration changes.
- Allow inbound TCP/443 only from trusted hosts using PF.
- Consider running the jail on a management VLAN inaccessible from user devices.
Why a Jail?
Compared to a Raspberry Pi, a FreeBSD jail offers:
| Raspberry Pi | FreeBSD Jail |
|---|---|
| Additional hardware | No extra hardware |
| SD card storage | ZFS storage |
| Separate updates | Managed with the host |
| Manual backups | ZFS snapshots and replication |
| Low power | Slightly higher power, but no additional device |
If the host is already trusted and always online, a jail is usually the simplest solution. If your threat model requires the key to live on physically separate hardware, a Raspberry Pi or ESP32 remains the stronger design. FreeBSD’s Jail Handbook and ZFS documentation also recommend combining jails with delegated ZFS datasets and snapshots for isolated services.