lxd should avoid spurious mounting of ZFS datasets on existing pools
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxd (Ubuntu) |
Won't Fix
|
Wishlist
|
Unassigned |
Bug Description
lxd should ensure that, when using an existing pool, its datasets are not spuriously mounted.
--- Original Description:
Currently, lxd is not explicitly creating the intermediate "containers" and "images" datasets. It is allowing them to be created implicitly by calling "zfs create -p".
I would like to see lxd always (regardless of whether lxd is creating the pool) create these datasets explicitly (e.g. in lxd/main.go) and set "canmount=off" or "mountpoint=none" on both. Otherwise, regardless of which existing dataset I choose, I end up with "/something/
I think it would be wise to also set "exec=on" and "setuid=on" on the "containers" dataset. If the children of the "containers" dataset are mounted with noexec ("exec=off"), the container fails to start, for obvious reasons. Likewise, "setuid=on" is necessary for proper operation of setuid executables inside the container. If lxd doesn't set these options itself, it is at the mercy of whatever options might be inherited. This was a problem for me; see below.
Since "devices=off" is not a problem, I don't see any other options to be concerned with. The other options are either irrelevant, or might be something the admin actually wants to control. It's just these two that break the container.
Setting the options as described above would fix the following scenario, plus many other scenarios:
# Simulate a root pool setup that matches the upstream ZFS root HOWTO (which I maintain):
truncate -s 10G /var/lib/rpool.img
zfs create rpool /var/lib/rpool.img
zfs set -o devices=off rpool
zfs create -o canmount=off -o setuid=off -o exec=off rpool/var
# Try to use lxd, following the same dataset convention:
zfs create -o canmount=off rpool/var/lib
zfs create rpool/var/lib/lxd
apt install lxd
lxd init
# Specify "no" to creating a pool, and "rpool/var/lib/lxd" as the existing dataset.
# Accept the rest of the defaults.
lxd launch ubuntu:
The "containers" and "images" datasets are created too late, after data has already been written to /var/lib/
We may consider doing some of that when reworking the way we handle storage in a few months.
For now, users will typically use "lxd init" which will create a LXD pool for them that's marked with mounts disabled from the start (and a clean config for everything else).
If you opt into using a subset of an existing pool, we assume you know what you're doing and that you will properly configure it prior to giving it to LXD (LXD won't create it for you so you kinda have to).
The fact that LXD doesn't put /var/lib/lxd itself in the ZFS pool is intentional. LXD will eventually support multiple pools and storage backends being used in parallel, which would directly conflict with this approach.