$RodHat_/search
Console Tips

zfs allow, so the backup user never needs root

Published by

This article may contain Amazon affiliate links. I may earn a commission if you buy through them. Disclosure.

Terminal showing zfs allow output listing delegated snapshot, send and hold permissions for a backup user
AI illustration: RodHat
On this page · 7 sections
  1. The basic grant
  2. Scope: local, descendant, or both
  3. Permission sets
  4. Create-time permissions
  5. Taking it back
  6. Where delegation stops
  7. Why bother

The usual replication setup is a cron job on the primary that SSHes to a backup host as root, or a backup host that SSHes to the primary as root. Either way a box whose only job is “copy snapshots” holds the keys to the whole machine. ZFS has had a fix for this for ages. zfs allow hands out individual dataset operations to individual users. Almost nobody uses it.

The basic grant

zfs allow backup snapshot,hold,send tank/data

User backup can now snapshot, place holds on, and send tank/data and, because the grant is both local and descendant by default, everything under it. Check what you did:

zfs allow tank/data

The listing separates local grants, descendant grants and permission sets. Read it after every change. A delegation you cannot read back is a delegation you do not understand.

Now the cron job runs as backup:

zfs snapshot tank/data@$(date +%Y%m%d-%H%M)
zfs send -i tank/data@prev tank/data@now | ssh replica zfs receive -u pool/data

No sudo, no root login. If that account’s key walks out the door, the damage is bounded by what zfs allow said. It is not “the whole box.”

Scope: local, descendant, or both

By default a grant applies to the dataset and its descendants. Narrow it:

  • -l local only: the named dataset itself, not children.
  • -d descendants only: children, not the dataset.
  • -u user, -g group, -e everyone: say which kind of principal you mean. If a user and a group share a name, the bare form is ambiguous, so be explicit.

Example: let a developer destroy and clone scratch datasets under tank/scratch without letting them touch the parent:

zfs allow -d dev create,mount,destroy,clone,snapshot tank/scratch

Permission sets

Once the list gets long, name it. Set names start with @:

zfs allow -s @snapper snapshot,hold,release,destroy tank/data
zfs allow backup @snapper tank/data

Now changing what “snapper” means is one edit, not a hunt through every grant. Treat sets like groups in /etc/group: cheap, and you will be glad of them in a year.

Create-time permissions

-c grants rights that the creator of a new child dataset receives on it:

zfs allow -c snapshot,send,destroy tank/home

This is how you let users make their own datasets under a parent and then administer only the ones they made. Without it they can create but then have no rights on what they just created, which is a confusing afternoon.

Taking it back

zfs unallow backup tank/data
zfs unallow backup snapshot tank/data

First form removes everything for that user on that dataset. Second removes one permission. -r recurses to children.

Where delegation stops

This is the part that bites.

  • Mounting. Operations that mount or unmount, such as create, clone, rollback, rename and destroy on a filesystem, need the mount permission too, and mounting as a non-root user is controlled by the OS, not by ZFS. On FreeBSD that means sysctl vfs.usermount=1, which is a global knob with its own consequences. On Linux, check the “Delegated Administration” section of your zfs-allow(8) before assuming unprivileged mount works. It has had restrictions. send and snapshot need no mount, which is why they are the safe place to start.
  • Destroy. The destroy permission is as scary as it sounds. A backup account that can send does not need it. Do not hand it out because the error message was annoying.
  • Properties. Property changes are delegable one at a time (compression, quota, userprop). Do not grant quota to someone you do not want resizing their own limit.
  • Receiving. receive on the target needs create and mount as well on most setups, so the replica side is where you will hit the mount wall first. A receive with -u skips mounting, which is why I use it above.

Test every grant as the actual user, not as root. Root succeeding tells you nothing.

su -m backup -c 'zfs snapshot tank/data@test'

The first time you run that and get cannot create snapshot ... permission denied, you will know the system is doing its job.

Why bother

Because a compromised replication account should cost you a dataset’s snapshots, not your host. I came to this late, after years of passwordless root SSH between boxes I called “backup infrastructure.” Pair it with a hold on the snapshots you care about, as in bookmarks and holds for incremental send, and with the plain mechanics in zfs send and recv replication. If you run jails, the delegation story gets stranger; start at ZFS and jails as poor man’s containers. More in the ZFS and storage hub.