Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f7307a862 |
@@ -222,15 +222,13 @@ rec {
|
|||||||
: Bind mounts, keyed by mount point.
|
: Bind mounts, keyed by mount point.
|
||||||
|
|
||||||
`resources.devices`
|
`resources.devices`
|
||||||
: Host device nodes to expose, as paths. Bound into the container at the
|
: Host device nodes to expose, as paths, added to the unit's
|
||||||
same path and added to the unit's `DeviceAllow=` - the cgroup
|
`DeviceAllow=`. nspawn populates a handful of privileged devices
|
||||||
permission alone doesn't get you a working node (nothing can `mknod` a
|
(`/dev/kvm`, `/dev/net/tun`, ...) into the container's own `/dev` once
|
||||||
device inside a user namespace), and the bind alone leaves the cgroup
|
the cgroup allows it, and silently skips ones the host doesn't have -
|
||||||
denying `open()`, so both are needed. The bind is unconditional, so
|
no `resources.fs` bind mount needed. Nodes keep their host ownership,
|
||||||
the device must actually exist on whatever host runs the container.
|
so a consumer inside needs `isolation.privateUsers = "identity"` for
|
||||||
Nodes keep their host ownership, so a consumer inside needs
|
the owning gid to mean anything.
|
||||||
`isolation.privateUsers = "identity"` for the owning gid to mean
|
|
||||||
anything.
|
|
||||||
|
|
||||||
`isolation.nixDaemon`
|
`isolation.nixDaemon`
|
||||||
: Whether the Nix daemon and CLI are available inside the container.
|
: Whether the Nix daemon and CLI are available inside the container.
|
||||||
@@ -297,10 +295,6 @@ rec {
|
|||||||
+ lib.optionalString useIdmap ":idmap"
|
+ lib.optionalString useIdmap ":idmap"
|
||||||
) allBindMounts;
|
) allBindMounts;
|
||||||
bindMountHostPaths = map (bm: bm.hostPath) (lib.attrValues allBindMounts);
|
bindMountHostPaths = map (bm: bm.hostPath) (lib.attrValues allBindMounts);
|
||||||
# DeviceAllow= alone only grants cgroup permission - nspawn can't
|
|
||||||
# mknod a device node inside a user namespace, so the node still
|
|
||||||
# needs an explicit bind from the host.
|
|
||||||
deviceFlags = map (d: "--bind=${d}") devices;
|
|
||||||
inherit (deriveIdentity ifPrefix.nspawn name)
|
inherit (deriveIdentity ifPrefix.nspawn name)
|
||||||
iface
|
iface
|
||||||
mac
|
mac
|
||||||
@@ -387,7 +381,7 @@ rec {
|
|||||||
nixosContainer = {
|
nixosContainer = {
|
||||||
inherit autoStart privateUsers;
|
inherit autoStart privateUsers;
|
||||||
bindMounts = { };
|
bindMounts = { };
|
||||||
extraFlags = bindMountExtraFlags ++ deviceFlags;
|
extraFlags = bindMountExtraFlags;
|
||||||
privateNetwork = true;
|
privateNetwork = true;
|
||||||
extraVeths = linkVeths;
|
extraVeths = linkVeths;
|
||||||
config =
|
config =
|
||||||
|
|||||||
Generated
+10
-10
@@ -26,11 +26,11 @@
|
|||||||
"spectrum": "spectrum"
|
"spectrum": "spectrum"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1786300091,
|
"lastModified": 1789252264,
|
||||||
"narHash": "sha256-4UFJOVGpaYtHW5yasSv80MaJxTBYdk2zyf3jhKtt0wA=",
|
"narHash": "sha256-IyOsrL64VjSHJKdzvQQcgNJtrSd4/jDa7vhlFa9libM=",
|
||||||
"owner": "microvm-nix",
|
"owner": "microvm-nix",
|
||||||
"repo": "microvm.nix",
|
"repo": "microvm.nix",
|
||||||
"rev": "71beea0076cd46dafcee97a5a2e7d00cbba5bd2f",
|
"rev": "e7e1c7aba5cb04644cfd6afe7e98cb87d76ac64f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -63,11 +63,11 @@
|
|||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1786384358,
|
"lastModified": 1789149629,
|
||||||
"narHash": "sha256-RzPPiWeUtuvymnpuEWsdtzli5w4kjZs49FqEs3/1u+I=",
|
"narHash": "sha256-H6GwaZzZf+4npqv0tph94w9tZddSjFjmQrVsW0z78uk=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "2fcb964de67fcf60b43471c55d5d99e61a9ccb5a",
|
"rev": "eaad089433ca2bb662274377d33df3d0e51ef28b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
@@ -87,11 +87,11 @@
|
|||||||
"spectrum": {
|
"spectrum": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1785761586,
|
"lastModified": 1786032750,
|
||||||
"narHash": "sha256-MWOMVqJJERwjQGgRIv8d6rlEBqbLM3VZWxHkNKIIZNw=",
|
"narHash": "sha256-+Ba/kIn5BjvV7PN8bWOo7RoqgTY/Yv2M7qeMf3wS2Ag=",
|
||||||
"ref": "refs/heads/main",
|
"ref": "refs/heads/main",
|
||||||
"rev": "a7762d6f54b40560dd5255ce902e6e6a5d980fe9",
|
"rev": "77d2389874bb092b8dbf05ecc5b1030372e80e98",
|
||||||
"revCount": 1416,
|
"revCount": 1417,
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://spectrum-os.org/git/spectrum"
|
"url": "https://spectrum-os.org/git/spectrum"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -333,28 +333,9 @@ with subtest("(functional): published ports follow the container's lifetime"):
|
|||||||
with subtest("(functional): declared devices are usable in-container"):
|
with subtest("(functional): declared devices are usable in-container"):
|
||||||
for name, devices in DEVICES.items():
|
for name, devices in DEVICES.items():
|
||||||
for dev in devices:
|
for dev in devices:
|
||||||
# opened, not stat'd: without DeviceAllow= the node is still visible
|
|
||||||
server.succeed(ct_cmd(name, f"exec 3<> {dev}"))
|
server.succeed(ct_cmd(name, f"exec 3<> {dev}"))
|
||||||
|
|
||||||
|
|
||||||
with subtest("(functional): /dev/kvm actually initializes, not just opens"):
|
|
||||||
# a wrong-gid or unmapped node still opens but fails the ioctls qemu
|
|
||||||
# needs, so boot with no disk (never completes) and kill it - the
|
|
||||||
# failure mode this catches is qemu refusing to start at all.
|
|
||||||
for name, devices in DEVICES.items():
|
|
||||||
if "/dev/kvm" not in devices:
|
|
||||||
continue
|
|
||||||
out = server.succeed(
|
|
||||||
ct_cmd(
|
|
||||||
name,
|
|
||||||
f"{TIMEOUT} 3 qemu-system-x86_64 -enable-kvm -m 256 -nographic -no-reboot "
|
|
||||||
">/tmp/qemu.out 2>&1; cat /tmp/qemu.out",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
assert "Permission denied" not in out, f"{name}: qemu couldn't use /dev/kvm:\n{out}"
|
|
||||||
assert "Could not access KVM" not in out, f"{name}: qemu couldn't use /dev/kvm:\n{out}"
|
|
||||||
|
|
||||||
|
|
||||||
with subtest("(isolation): devices reach only the container that declared them"):
|
with subtest("(isolation): devices reach only the container that declared them"):
|
||||||
for name in enterable:
|
for name in enterable:
|
||||||
for dev in {d for ds in DEVICES.values() for d in ds} - set(DEVICES.get(name, [])):
|
for dev in {d for ds in DEVICES.values() for d in ds} - set(DEVICES.get(name, [])):
|
||||||
|
|||||||
Reference in New Issue
Block a user