2024-12-12 16:50:13 +00:00
|
|
|
{
|
|
|
|
system ? builtins.currentSystem,
|
|
|
|
config ? { },
|
|
|
|
pkgs ? import ../.. { inherit system config; },
|
|
|
|
lib ? pkgs.lib,
|
2020-04-20 11:31:07 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
inherit (import ../lib/testing-python.nix { inherit system pkgs; }) makeTest;
|
|
|
|
|
2024-12-12 16:50:13 +00:00
|
|
|
mkOCITest =
|
|
|
|
backend:
|
|
|
|
makeTest {
|
|
|
|
name = "oci-containers-${backend}";
|
2020-04-20 11:31:07 +00:00
|
|
|
|
2024-12-12 16:50:13 +00:00
|
|
|
meta.maintainers = lib.teams.serokell.members ++ (with lib.maintainers; [ benley ]);
|
2020-04-20 11:31:07 +00:00
|
|
|
|
2024-12-12 16:50:13 +00:00
|
|
|
nodes = {
|
|
|
|
${backend} =
|
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
|
|
|
virtualisation.oci-containers = {
|
|
|
|
inherit backend;
|
|
|
|
containers.nginx = {
|
|
|
|
image = "nginx-container";
|
|
|
|
imageStream = pkgs.dockerTools.examples.nginxStream;
|
|
|
|
ports = [ "8181:80" ];
|
|
|
|
capabilities = {
|
|
|
|
CAP_AUDIT_READ = true;
|
|
|
|
CAP_AUDIT_WRITE = false;
|
|
|
|
};
|
|
|
|
privileged = false;
|
|
|
|
devices = [
|
|
|
|
"/dev/random:/dev/random"
|
|
|
|
];
|
|
|
|
};
|
2024-12-05 17:48:41 +00:00
|
|
|
};
|
2023-08-10 08:24:26 +00:00
|
|
|
|
2024-12-12 16:50:13 +00:00
|
|
|
# Stop systemd from killing remaining processes if ExecStop script
|
|
|
|
# doesn't work, so that proper stopping can be tested.
|
|
|
|
systemd.services."${backend}-nginx".serviceConfig.KillSignal = "SIGCONT";
|
|
|
|
};
|
2020-04-20 11:31:07 +00:00
|
|
|
};
|
|
|
|
|
2024-12-12 16:50:13 +00:00
|
|
|
testScript = ''
|
|
|
|
import json
|
2024-12-05 17:48:41 +00:00
|
|
|
|
2024-12-12 16:50:13 +00:00
|
|
|
start_all()
|
|
|
|
${backend}.wait_for_unit("${backend}-nginx.service")
|
|
|
|
${backend}.wait_for_open_port(8181)
|
|
|
|
${backend}.wait_until_succeeds("curl -f http://localhost:8181 | grep Hello")
|
|
|
|
output = json.loads(${backend}.succeed("${backend} inspect nginx --format json").strip())[0]
|
|
|
|
${backend}.succeed("systemctl stop ${backend}-nginx.service", timeout=10)
|
|
|
|
assert output['HostConfig']['CapAdd'] == ["CAP_AUDIT_READ"]
|
|
|
|
assert output['HostConfig']['CapDrop'] == ${
|
|
|
|
if backend == "docker" then "[\"CAP_AUDIT_WRITE\"]" else "[]"
|
|
|
|
} # Rootless podman runs with no capabilities so it cannot drop them
|
|
|
|
assert output['HostConfig']['Privileged'] == False
|
|
|
|
assert output['HostConfig']['Devices'] == [{'PathOnHost': '/dev/random', 'PathInContainer': '/dev/random', 'CgroupPermissions': '${
|
|
|
|
if backend == "docker" then "rwm" else ""
|
|
|
|
}'}]
|
|
|
|
'';
|
|
|
|
};
|
2020-04-20 11:31:07 +00:00
|
|
|
|
|
|
|
in
|
2024-12-12 16:50:13 +00:00
|
|
|
lib.foldl' (attrs: backend: attrs // { ${backend} = mkOCITest backend; }) { } [
|
2020-04-20 11:31:07 +00:00
|
|
|
"docker"
|
|
|
|
"podman"
|
|
|
|
]
|