Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 77 additions & 2 deletions docs/containers/zrepl.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,91 @@ container:
docker_run:
- --rm
- --name zrepl
- --privileged
- --device /dev/zfs:/dev/zfs
- --cap-drop ALL
- --security-opt no-new-privileges=true
- '--mount "type=bind,src=$PWD/zrepl.yml,dst=/etc/zrepl/zrepl.yml,readonly"'
- ghcr.io/tuxcrate/zrepl:latest
compose:
services:
zrepl:
image: ghcr.io/tuxcrate/zrepl:latest
privileged: true
devices:
- /dev/zfs:/dev/zfs
cap_drop:
- ALL
security_opt:
- no-new-privileges:true
volumes:
- ./zrepl.yml:/etc/zrepl/zrepl.yml:ro
---

{% extends "container.md.jinja" %}

{% block prerequisites %}
## Host setup

The image runs as `tuxcrate`, UID/GID `1000:1000`. The host must have the ZFS
kernel module loaded and the relevant pools imported. The container uses the
host's `/dev/zfs`; it does not load modules or import pools.

Before starting the container:

- Make `zrepl.yml` and any mounted credentials readable by UID 1000. Keep secrets
restricted to that user rather than making them world-readable.
- Allow the container user to open `/dev/zfs` for reading and writing. If the
device is restricted to a host group, add its numeric GID with `--group-add`
or Compose `group_add`. Do not make the device world-writable just for this
container.
- Delegate ZFS permissions to the host UID corresponding to container UID 1000.
Without user-namespace remapping, this is host UID 1000. Check which host
account owns that UID before granting access.

For a snapshot/send/prune job, the following is a starting permission set.
Run it as a host administrator, replacing `tank/source` with a dataset selected
by your zrepl configuration:

```sh
sudo zfs allow -u 1000 snapshot,send,destroy,hold,release,bookmark tank/source
```

By default, these permissions apply to the dataset and its descendants.
`destroy` allows destructive operations, so delegate only on datasets this
instance should manage. Jobs that set ZFS properties need the corresponding
property permissions as well. Review the daemon logs for permission failures.

Ensure the host ZFS kernel module includes the fix for
[CVE-2026-79619](https://github.com/openzfs/zfs/security/advisories/GHSA-mhf5-q8gw-qg9v)
before exposing `/dev/zfs` to a user-namespace container. Updating the utilities
inside the image does not fix the host kernel module.

## Non-root operation and limitations

The examples expose only `/dev/zfs`, drop Linux capabilities, and do not use
`--privileged`. ZFS access is controlled by host device permissions and
[`zfs allow`](https://openzfs.github.io/openzfs-docs/man/master/8/zfs-allow.8.html)
delegation. Configuration may also require network ports, credentials, or mounts
for hooks; add these according to your jobs.

Receiving needs additional dataset-creation, receive, and property permissions.
Linux does not support delegation of mounting and certain related operations.
An unmounted backup target may avoid mounting, but receive and pruning behavior
must be tested on a disposable dataset before using this setup for backups.

Running as a non-root user is not the same as running a rootless Docker or Podman
engine. Rootless engines introduce UID/GID mapping, device-access, and ZFS
namespace constraints. Full rootless-engine support has not been verified.

`/var/run/zrepl` and `/home/tuxcrate` are writable by the image's default user.
If you override the user or mount over those directories, provide suitable
ownership yourself. To revert delegation granted by the example above:

```sh
sudo zfs unallow -u 1000 snapshot,send,destroy,hold,release,bookmark tank/source
```

For workloads that still require root, overriding the image user with
`--user 0:0` (Compose `user: "0:0"`) is a compatibility option. Device access and any
required capabilities must be configured separately; changing the user alone
does not provide them.
{% endblock %}
37 changes: 29 additions & 8 deletions macros/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,14 +769,35 @@ def test_container_pages_use_shared_layout(self) -> None:
)
self.assertNotIn("| Image Tags | Track |", text)
self.assertNotIn("No image has been published yet", text)
if name == "zrepl":
self.assertIn("--privileged", metadata["container"]["docker_run"])
privileged = metadata["container"]["compose"]["services"]["zrepl"][
"privileged"
]
self.assertIs(privileged, True) # noqa: FBT003 -- Verify the boolean type too.
self.assertIn("--privileged", text)
self.assertIn("privileged: true", text)

def test_zrepl_non_root_setup(self) -> None:
"""Document delegated ZFS access without a privileged container."""
root = Path(__file__).resolve().parents[2]
source = (root / "docs/containers/zrepl.md").read_text()
_, front_matter, body = source.split("---", 2)
metadata = yaml.safe_load(front_matter)
env = template_environment()
env.globals["gh_image_versions_data"] = Mock(
return_value={
"image": "ghcr.io/tuxcrate/zrepl",
"releases": [],
"preview": False,
}
)
text = env.from_string(body).render(page={"meta": metadata})
cli = metadata["container"]["docker_run"]
service = metadata["container"]["compose"]["services"]["zrepl"]
self.assertNotIn("--privileged", cli)
self.assertNotIn("privileged", service)
self.assertIn("--device /dev/zfs:/dev/zfs", cli)
self.assertIn("--cap-drop ALL", cli)
self.assertIn("--security-opt no-new-privileges=true", cli)
self.assertEqual(service["devices"], ["/dev/zfs:/dev/zfs"])
self.assertEqual(service["cap_drop"], ["ALL"])
self.assertEqual(service["security_opt"], ["no-new-privileges:true"])
self.assertIn("UID/GID `1000:1000`", text)
self.assertIn("sudo zfs allow -u 1000", text)
self.assertIn("Full rootless-engine support has not been verified", text)

def test_pull_counter_zero_and_unavailable(self) -> None:
"""Show a genuine zero but omit unavailable counts instead of inventing one."""
Expand Down