ZFS Delegation¶
This guide explains how to configure ZFS delegation to run backups without sudo.
Overview¶
By default, ZFS operations require root privileges. ZFS delegation allows you to grant specific permissions to non-root users.
Limitations
Even with delegation, some operations (like pool import/export) may still require root. For most users, running with sudo is simpler.
Configuring Delegation¶
Step 1: Enable Delegation on Pools¶
Step 2: Grant Permissions on Source Pool¶
Step 3: Grant Permissions on Backup Pool¶
Permission Reference¶
Required for Backup¶
| Permission | Purpose |
|---|---|
| snapshot | Create snapshots |
| send | Send snapshot streams |
| hold | Hold snapshots during send |
| release | Release snapshot holds |
Required for Restore¶
| Permission | Purpose |
|---|---|
| receive | Receive snapshot streams |
| create | Create datasets |
| mount | Mount filesystems |
Required for Encryption¶
| Permission | Purpose |
|---|---|
| load-key | Load encryption key |
| change-key | Change encryption key |
Checking Current Permissions¶
View current delegations:
Removing Delegation¶
To revoke permissions:
# Remove all permissions for user
sudo zfs unallow -u $USER NIXROOT
sudo zfs unallow -u $USER NIXBACKUPS
Limitations¶
Even with full delegation, these operations typically require root:
zpool import- Importing poolszpool export- Exporting poolsudisksctl power-off- Powering off USB drives
Workaround: Sudoers Rules¶
You can create specific sudoers rules for these commands:
# /etc/sudoers.d/zfs-backup
youruser ALL=(root) NOPASSWD: /sbin/zpool import *
youruser ALL=(root) NOPASSWD: /sbin/zpool export *
youruser ALL=(root) NOPASSWD: /usr/bin/udisksctl power-off *
Security Warning
Be careful with NOPASSWD rules. They allow the specified commands without authentication.
Testing Delegation¶
After configuring, test without sudo:
# Should work with delegation
zfs list
zfs snapshot NIXROOT/home@test
zfs destroy NIXROOT/home@test
# May still require sudo
zpool import NIXBACKUPS # Usually needs sudo
Recommended Approach¶
For most users, we recommend:
- Use sudo for the backup tool itself
- Configure delegation only if you have specific security requirements
- Use the TUI which handles permissions gracefully