# source directory which would mean we'd be mounting the container root directory as a subdirectory in
# itself which tends to lead to all kinds of weird issues, which we avoid by not doing a recursive mount
# which means the container root directory mounts will be skipped.
- cmdline += ["--bind", f"{tree.source}:{target}:norbind,rootidmap"]
+ uidmap = "rootidmap" if tree.source.stat().st_uid == INVOKING_USER.uid else "noidmap"
+ cmdline += ["--bind", f"{tree.source}:{target}:norbind,{uidmap}"]
if config.runtime_scratch == ConfigFeature.enabled or (
config.runtime_scratch == ConfigFeature.auto and
@contextlib.contextmanager
-def start_virtiofsd(config: Config, directory: Path, *, uidmap: bool) -> Iterator[Path]:
+def start_virtiofsd(config: Config, directory: Path, *, name: str, selinux: bool = False) -> Iterator[Path]:
+ uidmap = directory.stat().st_uid == INVOKING_USER.uid
+
virtiofsd = find_virtiofsd(tools=config.tools())
if virtiofsd is None:
die("virtiofsd must be installed to boot directory images or use RuntimeTrees= with mkosi qemu")
f"--inode-file-handles={'prefer' if os.getuid() == 0 and not uidmap else 'never'}",
]
- if not uidmap and want_selinux_relabel(config, directory, fatal=False):
+ if selinux:
cmdline += ["--security-label"]
# We create the socket ourselves and pass the fd to virtiofsd to avoid race conditions where we start qemu
) as proc:
allocate_scope(
config,
- name=f"mkosi-virtiofsd-{directory}" if uidmap else f"mkosi-virtiofsd-{config.machine_or_name()}",
+ name=f"mkosi-virtiofsd-{name}",
pid=proc.pid,
description=f"virtiofsd for {directory}",
)
kcl += [root]
elif config.output_format == OutputFormat.directory:
- sock = stack.enter_context(start_virtiofsd(config, fname, uidmap=False))
+ sock = stack.enter_context(
+ start_virtiofsd(
+ config,
+ fname,
+ name=config.machine_or_name(),
+ selinux=bool(want_selinux_relabel(config, fname, fatal=False))),
+ )
cmdline += [
"-chardev", f"socket,id={sock.name},path={sock}",
"-device", f"vhost-user-fs-pci,queue-size=1024,chardev={sock.name},tag=root",
kcl += ["root=root", "rootfstype=virtiofs", "rw"]
for tree in config.runtime_trees:
- sock = stack.enter_context(start_virtiofsd(config, tree.source, uidmap=True))
+ sock = stack.enter_context(start_virtiofsd(config, tree.source, name=os.fspath(tree.source)))
tag = tree.target.name if tree.target else tree.source.name
cmdline += [
"-chardev", f"socket,id={sock.name},path={sock}",