Skip to main content

Unlock encrypted ZFS datasets on TrueNAS via the API

Project description

TrueNAS Unlock

PyPI Python Tests License

Unlock encrypted ZFS datasets on TrueNAS via the API.

https://github.com/user-attachments/assets/172c8fd7-5b66-4c5b-bae0-32e378e9305a

Why?

TrueNAS supports encrypted ZFS datasets, but:

  1. Storing keys on the NAS defeats the purpose—if it's stolen, the thief has both the encrypted data and the keys
  2. Manual unlocking is tedious—after every reboot, you need to manually decrypt each dataset through the UI

This tool solves both problems with a "poor-man's second-factor" setup:

  1. Run truenas-unlock on a separate device (Raspberry Pi, home server, etc.)
  2. Store encryption keys only on that device
  3. Datasets auto-unlock when both devices are on the network
  4. If the NAS is stolen, data remains encrypted and inaccessible

Think of it as a hardware security key for your storage—hidden somewhere in your house, it automatically unlocks your datasets whenever your TrueNAS boots. No manual intervention required.

Table of Contents

Install

# With uv (recommended)
uv tool install truenas-unlock

# With pip
pip install truenas-unlock

Setup

Create an API key at http://truenas.local/ui/credentials/users/api-keys (replace with your TrueNAS hostname).

Then create ~/.config/truenas-unlock/config.yaml:

host: 192.168.1.214:443
api_key: ~/.secrets/truenas-api-key  # file path or literal
skip_cert_verify: true

# secrets: auto  # auto (default) | files | inline

datasets:
  tank/syncthing: ~/.secrets/syncthing-key  # reads from file
  tank/photos: my-literal-passphrase        # used as-is (no such file)

The secrets mode controls how values are interpreted:

  • auto (default): if file exists, read from it; otherwise use as literal
  • files: always treat values as file paths
  • inline: always treat values as literal secrets

Usage

# Run once
truenas-unlock

# Run as daemon
# (Checks every 1s if TrueNAS is unreachable, otherwise every 30s)
truenas-unlock --daemon

# Custom interval (for the "relaxed" state)
truenas-unlock --daemon --interval 60

# Dry run
truenas-unlock --dry-run

CLI

truenas-unlock --help
 Usage: truenas-unlock [OPTIONS] COMMAND [ARGS]...

 Unlock TrueNAS ZFS datasets

╭─ Options ────────────────────────────────────────────────────────────────────╮
│ --config    -c      PATH     Config file path                                │
│ --dry-run   -n               Show what would be done                         │
│ --daemon    -d               Run continuously                                │
│ --interval  -i      INTEGER  Seconds between checks (1s if unreachable)      │
│                              [default: 30]                                   │
│ --dataset   -D      TEXT     Filter by dataset path                          │
│ --version   -v               Show version and exit                           │
│ --help      -h               Show this message and exit.                     │
╰──────────────────────────────────────────────────────────────────────────────╯
╭─ Commands ───────────────────────────────────────────────────────────────────╮
│ lock      Lock configured datasets.                                          │
│ status    Show lock status of configured datasets.                           │
│ service   Manage system service                                              │
╰──────────────────────────────────────────────────────────────────────────────╯

Running as a Service

Requires uv to be installed. Auto-detects Linux (systemd) or macOS (launchd):

# Install and start
truenas-unlock service install

# Check status
truenas-unlock service status

# View logs (follows by default)
truenas-unlock service logs

# Uninstall
truenas-unlock service uninstall

Development

# Clone and install
git clone https://github.com/basnijholt/truenas-unlock
cd truenas-unlock
uv sync --dev

# Run tests
uv run pytest

# Run lints
uv run ruff check .
uv run mypy truenas_unlock.py

Credits

Inspired by ThorpeJosh/truenas-zfs-unlock.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

truenas_unlock-1.6.0.tar.gz (63.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

truenas_unlock-1.6.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

Details for the file truenas_unlock-1.6.0.tar.gz.

File metadata

  • Download URL: truenas_unlock-1.6.0.tar.gz
  • Upload date:
  • Size: 63.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for truenas_unlock-1.6.0.tar.gz
Algorithm Hash digest
SHA256 dd9c2f4f8389702b78f54247b01f876dd79005f930372cbdeaed851ed19e14b8
MD5 cefd7189148de3e8a42c2c8b04be67a6
BLAKE2b-256 21e29253ed774f8e26baa1621b0423b582b1a28c15732ad69eb9a2df825ea9a2

See more details on using hashes here.

Provenance

The following attestation bundles were made for truenas_unlock-1.6.0.tar.gz:

Publisher: release.yml on basnijholt/truenas-unlock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file truenas_unlock-1.6.0-py3-none-any.whl.

File metadata

  • Download URL: truenas_unlock-1.6.0-py3-none-any.whl
  • Upload date:
  • Size: 10.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for truenas_unlock-1.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 58f441eb4c1c37dbd81beb9176057d0ae46176b498528fded897edb847a71aa7
MD5 d1997abaf9829bb7ffc0b2509c9cada1
BLAKE2b-256 b00f2a9a17e1d4c266feb1859fee8cacc5259be7de7c4942682a33fa61855d6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for truenas_unlock-1.6.0-py3-none-any.whl:

Publisher: release.yml on basnijholt/truenas-unlock

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page