2020-11-09 04:23:58 +00:00
|
|
|
# SPDX-License-Identifier: LGPL-2.1-or-later
|
2017-11-18 16:35:03 +00:00
|
|
|
#
|
2013-04-30 00:11:37 +00:00
|
|
|
# This file is part of systemd.
|
|
|
|
#
|
|
|
|
# systemd is free software; you can redistribute it and/or modify it
|
|
|
|
# under the terms of the GNU Lesser General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
[Unit]
|
2016-02-26 19:35:09 +00:00
|
|
|
Description=Container %i
|
2013-04-30 00:11:37 +00:00
|
|
|
Documentation=man:systemd-nspawn(1)
|
2022-12-23 16:23:00 +00:00
|
|
|
Wants=modprobe@tun.service modprobe@loop.service modprobe@dm_mod.service
|
2014-12-29 11:38:26 +00:00
|
|
|
PartOf=machines.target
|
|
|
|
Before=machines.target
|
2022-12-15 19:02:25 +00:00
|
|
|
After=network.target modprobe@tun.service modprobe@loop.service modprobe@dm_mod.service
|
2020-02-24 14:54:35 +00:00
|
|
|
RequiresMountsFor=/var/lib/machines/%i
|
2013-04-30 00:11:37 +00:00
|
|
|
|
|
|
|
[Service]
|
2019-07-23 11:11:09 +00:00
|
|
|
# Make sure the DeviceAllow= lines below can properly resolve the 'block-loop' expression (and others)
|
2019-12-18 08:14:57 +00:00
|
|
|
ExecStart=systemd-nspawn --quiet --keep-unit --boot --link-journal=try-guest --network-veth -U --settings=override --machine=%i
|
2014-05-28 15:17:25 +00:00
|
|
|
KillMode=mixed
|
2013-04-30 00:11:37 +00:00
|
|
|
Type=notify
|
2014-07-03 10:50:11 +00:00
|
|
|
RestartForceExitStatus=133
|
|
|
|
SuccessExitStatus=133
|
2015-05-19 17:47:52 +00:00
|
|
|
Slice=machine.slice
|
2014-11-05 16:57:23 +00:00
|
|
|
Delegate=yes
|
2023-04-24 08:19:28 +00:00
|
|
|
DelegateSubgroup=supervisor
|
2023-10-12 17:39:56 +00:00
|
|
|
CoredumpReceive=yes
|
2016-07-14 10:20:29 +00:00
|
|
|
TasksMax=16384
|
2021-05-16 09:55:36 +00:00
|
|
|
{{SERVICE_WATCHDOG}}
|
2013-04-30 00:11:37 +00:00
|
|
|
|
nspawn: enable FUSE in containers
Linux kernel v4.18 (2018-08-12) added user-namespace support to FUSE, and
bumped the FUSE version to 7.27 (see: da315f6e0398 (Merge tag
'fuse-update-4.18' of
git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse, Linus Torvalds,
2018-06-07). This means that on such kernels it is safe to enable FUSE in
nspawn containers.
In outer_child(), before calling copy_devnodes(), check the FUSE version to
decide whether enable (>=7.27) or disable (<7.27) FUSE in the container. We
look at the FUSE version instead of the kernel version in order to enable FUSE
support on older-versioned kernels that may have the mentioned patchset
backported ([as requested by @poettering][1]). However, I am not sure that
this is safe; user-namespace support is not a documented part of the FUSE
protocol, which is what FUSE_KERNEL_VERSION/FUSE_KERNEL_MINOR_VERSION are meant
to capture. While the same patchset
- added FUSE_ABORT_ERROR (which is all that the 7.27 version bump
is documented as including),
- bumped FUSE_KERNEL_MINOR_VERSION from 26 to 27, and
- added user-namespace support
these 3 things are not inseparable; it is conceivable to me that a backport
could include the first 2 of those things and exclude the 3rd; perhaps it would
be safer to check the kernel version.
Do note that our get_fuse_version() function uses the fsopen() family of
syscalls, which were not added until Linux kernel v5.2 (2019-07-07); so if
nothing has been backported, then the minimum kernel version for FUSE-in-nspawn
is actually v5.2, not v4.18.
Pass whether or not to enable FUSE to copy_devnodes(); have copy_devnodes()
copy in /dev/fuse if enabled.
Pass whether or not to enable FUSE back over fd_outer_socket to run_container()
so that it can pass that to append_machine_properties() (via either
register_machine() or allocate_scope()); have append_machine_properties()
append "DeviceAllow=/dev/fuse rw" if enabled.
For testing, simply check that /dev/fuse can be opened for reading and writing,
but that actually reading from it fails with EPERM. The test assumes that if
FUSE is supported (/dev/fuse exists), then the testsuite is running on a kernel
with FUSE >= 7.27; I am unsure how to go about writing a test that validates
that the version check disables FUSE on old kernels.
[1]: https://github.com/systemd/systemd/issues/17607#issuecomment-745418835
Closes #17607
2024-08-21 23:29:10 +00:00
|
|
|
{# Enforce a strict device policy, similar to the one nspawn configures (in
|
|
|
|
# nspawn-register.c:append_machine_properties()) when it allocates its own
|
|
|
|
# scope unit. Make sure to keep these policies in sync if you change them! #}
|
2016-07-22 09:58:03 +00:00
|
|
|
DevicePolicy=closed
|
2015-04-28 18:46:03 +00:00
|
|
|
DeviceAllow=/dev/net/tun rwm
|
|
|
|
DeviceAllow=char-pts rw
|
nspawn: enable FUSE in containers
Linux kernel v4.18 (2018-08-12) added user-namespace support to FUSE, and
bumped the FUSE version to 7.27 (see: da315f6e0398 (Merge tag
'fuse-update-4.18' of
git://git.kernel.org/pub/scm/linux/kernel/git/mszeredi/fuse, Linus Torvalds,
2018-06-07). This means that on such kernels it is safe to enable FUSE in
nspawn containers.
In outer_child(), before calling copy_devnodes(), check the FUSE version to
decide whether enable (>=7.27) or disable (<7.27) FUSE in the container. We
look at the FUSE version instead of the kernel version in order to enable FUSE
support on older-versioned kernels that may have the mentioned patchset
backported ([as requested by @poettering][1]). However, I am not sure that
this is safe; user-namespace support is not a documented part of the FUSE
protocol, which is what FUSE_KERNEL_VERSION/FUSE_KERNEL_MINOR_VERSION are meant
to capture. While the same patchset
- added FUSE_ABORT_ERROR (which is all that the 7.27 version bump
is documented as including),
- bumped FUSE_KERNEL_MINOR_VERSION from 26 to 27, and
- added user-namespace support
these 3 things are not inseparable; it is conceivable to me that a backport
could include the first 2 of those things and exclude the 3rd; perhaps it would
be safer to check the kernel version.
Do note that our get_fuse_version() function uses the fsopen() family of
syscalls, which were not added until Linux kernel v5.2 (2019-07-07); so if
nothing has been backported, then the minimum kernel version for FUSE-in-nspawn
is actually v5.2, not v4.18.
Pass whether or not to enable FUSE to copy_devnodes(); have copy_devnodes()
copy in /dev/fuse if enabled.
Pass whether or not to enable FUSE back over fd_outer_socket to run_container()
so that it can pass that to append_machine_properties() (via either
register_machine() or allocate_scope()); have append_machine_properties()
append "DeviceAllow=/dev/fuse rw" if enabled.
For testing, simply check that /dev/fuse can be opened for reading and writing,
but that actually reading from it fails with EPERM. The test assumes that if
FUSE is supported (/dev/fuse exists), then the testsuite is running on a kernel
with FUSE >= 7.27; I am unsure how to go about writing a test that validates
that the version check disables FUSE on old kernels.
[1]: https://github.com/systemd/systemd/issues/17607#issuecomment-745418835
Closes #17607
2024-08-21 23:29:10 +00:00
|
|
|
DeviceAllow=/dev/fuse rwm
|
2015-04-28 18:46:03 +00:00
|
|
|
|
2017-08-09 16:19:00 +00:00
|
|
|
# nspawn itself needs access to /dev/loop-control and /dev/loop, to implement
|
|
|
|
# the --image= option. Add these here, too.
|
2015-10-03 09:23:52 +00:00
|
|
|
DeviceAllow=/dev/loop-control rw
|
|
|
|
DeviceAllow=block-loop rw
|
2015-10-21 22:39:57 +00:00
|
|
|
DeviceAllow=block-blkext rw
|
2015-10-03 09:23:52 +00:00
|
|
|
|
2017-08-09 16:19:00 +00:00
|
|
|
# nspawn can set up LUKS encrypted loopback files, in which case it needs
|
|
|
|
# access to /dev/mapper/control and the block devices /dev/mapper/*.
|
|
|
|
DeviceAllow=/dev/mapper/control rw
|
|
|
|
DeviceAllow=block-device-mapper rw
|
|
|
|
|
2013-04-30 00:11:37 +00:00
|
|
|
[Install]
|
2014-12-29 11:38:26 +00:00
|
|
|
WantedBy=machines.target
|