2021-12-09 02:10:44 +00:00
|
|
|
import ../make-test-python.nix (
|
2020-04-20 11:35:36 +00:00
|
|
|
{ pkgs, lib, ... }: {
|
2020-04-20 08:37:53 +00:00
|
|
|
name = "podman";
|
2020-04-20 11:35:36 +00:00
|
|
|
meta = {
|
|
|
|
maintainers = lib.teams.podman.members;
|
2020-04-20 08:37:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
nodes = {
|
2023-02-18 10:15:20 +00:00
|
|
|
rootful = { pkgs, ... }: {
|
|
|
|
virtualisation.podman.enable = true;
|
2023-02-26 01:18:43 +00:00
|
|
|
|
|
|
|
# hack to ensure that podman built with and without zfs in extraPackages is cached
|
|
|
|
boot.supportedFilesystems = [ "zfs" ];
|
|
|
|
networking.hostId = "00000000";
|
2023-02-18 10:15:20 +00:00
|
|
|
};
|
|
|
|
rootless = { pkgs, ... }: {
|
2022-11-06 00:28:37 +00:00
|
|
|
virtualisation.podman.enable = true;
|
|
|
|
|
|
|
|
users.users.alice = {
|
|
|
|
isNormalUser = true;
|
|
|
|
};
|
|
|
|
};
|
2022-08-18 03:58:03 +00:00
|
|
|
dns = { pkgs, ... }: {
|
|
|
|
virtualisation.podman.enable = true;
|
|
|
|
|
|
|
|
virtualisation.podman.defaultNetwork.settings.dns_enabled = true;
|
|
|
|
|
|
|
|
networking.firewall.allowedUDPPorts = [ 53 ];
|
|
|
|
};
|
2022-11-06 00:28:37 +00:00
|
|
|
docker = { pkgs, ... }: {
|
|
|
|
virtualisation.podman.enable = true;
|
|
|
|
|
|
|
|
virtualisation.podman.dockerSocket.enable = true;
|
|
|
|
|
|
|
|
environment.systemPackages = [
|
|
|
|
pkgs.docker-client
|
|
|
|
];
|
2020-04-24 09:49:36 +00:00
|
|
|
|
2022-11-06 00:28:37 +00:00
|
|
|
users.users.alice = {
|
|
|
|
isNormalUser = true;
|
|
|
|
extraGroups = [ "podman" ];
|
2020-04-24 09:49:36 +00:00
|
|
|
};
|
2022-11-06 00:28:37 +00:00
|
|
|
|
|
|
|
users.users.mallory = {
|
|
|
|
isNormalUser = true;
|
|
|
|
};
|
|
|
|
};
|
2020-04-20 08:37:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
testScript = ''
|
2020-04-24 09:49:36 +00:00
|
|
|
import shlex
|
|
|
|
|
|
|
|
|
2021-05-25 08:26:28 +00:00
|
|
|
def su_cmd(cmd, user = "alice"):
|
2020-04-24 09:49:36 +00:00
|
|
|
cmd = shlex.quote(cmd)
|
2021-05-25 08:26:28 +00:00
|
|
|
return f"su {user} -l -c {cmd}"
|
2020-04-24 09:49:36 +00:00
|
|
|
|
2020-04-20 08:37:53 +00:00
|
|
|
|
2023-02-18 10:15:20 +00:00
|
|
|
rootful.wait_for_unit("sockets.target")
|
|
|
|
rootless.wait_for_unit("sockets.target")
|
2022-08-18 03:58:03 +00:00
|
|
|
dns.wait_for_unit("sockets.target")
|
2022-11-06 00:28:37 +00:00
|
|
|
docker.wait_for_unit("sockets.target")
|
2020-04-24 09:49:36 +00:00
|
|
|
start_all()
|
|
|
|
|
2020-05-13 05:12:59 +00:00
|
|
|
with subtest("Run container as root with runc"):
|
2023-02-18 10:15:20 +00:00
|
|
|
rootful.succeed("tar cv --files-from /dev/null | podman import - scratchimg")
|
|
|
|
rootful.succeed(
|
2020-05-13 05:12:59 +00:00
|
|
|
"podman run --runtime=runc -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
2020-04-24 09:49:36 +00:00
|
|
|
)
|
2023-02-18 10:15:20 +00:00
|
|
|
rootful.succeed("podman ps | grep sleeping")
|
|
|
|
rootful.succeed("podman stop sleeping")
|
|
|
|
rootful.succeed("podman rm sleeping")
|
2020-04-24 09:49:36 +00:00
|
|
|
|
2020-05-13 05:12:59 +00:00
|
|
|
with subtest("Run container as root with crun"):
|
2023-02-18 10:15:20 +00:00
|
|
|
rootful.succeed("tar cv --files-from /dev/null | podman import - scratchimg")
|
|
|
|
rootful.succeed(
|
2020-05-13 05:12:59 +00:00
|
|
|
"podman run --runtime=crun -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
|
|
|
)
|
2023-02-18 10:15:20 +00:00
|
|
|
rootful.succeed("podman ps | grep sleeping")
|
|
|
|
rootful.succeed("podman stop sleeping")
|
|
|
|
rootful.succeed("podman rm sleeping")
|
2020-05-13 05:12:59 +00:00
|
|
|
|
2020-11-19 23:15:31 +00:00
|
|
|
with subtest("Run container as root with the default backend"):
|
2023-02-18 10:15:20 +00:00
|
|
|
rootful.succeed("tar cv --files-from /dev/null | podman import - scratchimg")
|
|
|
|
rootful.succeed(
|
2020-11-19 23:15:31 +00:00
|
|
|
"podman run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
|
|
|
)
|
2023-02-18 10:15:20 +00:00
|
|
|
rootful.succeed("podman ps | grep sleeping")
|
|
|
|
rootful.succeed("podman stop sleeping")
|
|
|
|
rootful.succeed("podman rm sleeping")
|
2020-11-19 23:15:31 +00:00
|
|
|
|
2022-11-06 06:31:16 +00:00
|
|
|
# start systemd session for rootless
|
2023-02-18 10:15:20 +00:00
|
|
|
rootless.succeed("loginctl enable-linger alice")
|
|
|
|
rootless.succeed(su_cmd("whoami"))
|
|
|
|
rootless.sleep(1)
|
2021-01-18 23:16:13 +00:00
|
|
|
|
|
|
|
with subtest("Run container rootless with runc"):
|
2023-02-18 10:15:20 +00:00
|
|
|
rootless.succeed(su_cmd("tar cv --files-from /dev/null | podman import - scratchimg"))
|
|
|
|
rootless.succeed(
|
2021-01-18 23:16:13 +00:00
|
|
|
su_cmd(
|
|
|
|
"podman run --runtime=runc -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
|
|
|
)
|
|
|
|
)
|
2023-02-18 10:15:20 +00:00
|
|
|
rootless.succeed(su_cmd("podman ps | grep sleeping"))
|
|
|
|
rootless.succeed(su_cmd("podman stop sleeping"))
|
|
|
|
rootless.succeed(su_cmd("podman rm sleeping"))
|
2021-01-18 23:16:13 +00:00
|
|
|
|
2020-11-19 23:15:31 +00:00
|
|
|
with subtest("Run container rootless with crun"):
|
2023-02-18 10:15:20 +00:00
|
|
|
rootless.succeed(su_cmd("tar cv --files-from /dev/null | podman import - scratchimg"))
|
|
|
|
rootless.succeed(
|
2020-05-13 05:12:59 +00:00
|
|
|
su_cmd(
|
2020-11-19 23:15:31 +00:00
|
|
|
"podman run --runtime=crun -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
2020-05-13 05:12:59 +00:00
|
|
|
)
|
|
|
|
)
|
2023-02-18 10:15:20 +00:00
|
|
|
rootless.succeed(su_cmd("podman ps | grep sleeping"))
|
|
|
|
rootless.succeed(su_cmd("podman stop sleeping"))
|
|
|
|
rootless.succeed(su_cmd("podman rm sleeping"))
|
2020-05-13 05:12:59 +00:00
|
|
|
|
2020-11-19 23:15:31 +00:00
|
|
|
with subtest("Run container rootless with the default backend"):
|
2023-02-18 10:15:20 +00:00
|
|
|
rootless.succeed(su_cmd("tar cv --files-from /dev/null | podman import - scratchimg"))
|
|
|
|
rootless.succeed(
|
2020-04-24 09:49:36 +00:00
|
|
|
su_cmd(
|
2020-11-19 23:15:31 +00:00
|
|
|
"podman run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg /bin/sleep 10"
|
2020-04-24 09:49:36 +00:00
|
|
|
)
|
|
|
|
)
|
2023-02-18 10:15:20 +00:00
|
|
|
rootless.succeed(su_cmd("podman ps | grep sleeping"))
|
|
|
|
rootless.succeed(su_cmd("podman stop sleeping"))
|
|
|
|
rootless.succeed(su_cmd("podman rm sleeping"))
|
2021-03-21 20:12:32 +00:00
|
|
|
|
2023-02-18 10:52:04 +00:00
|
|
|
with subtest("rootlessport"):
|
|
|
|
rootless.succeed(su_cmd("tar cv --files-from /dev/null | podman import - scratchimg"))
|
|
|
|
rootless.succeed(
|
|
|
|
su_cmd(
|
|
|
|
"podman run -d -p 9000:8888 --name=rootlessport -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin -w ${pkgs.writeTextDir "index.html" "<h1>Testing</h1>"} scratchimg ${pkgs.python3}/bin/python -m http.server 8888"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
rootless.succeed(su_cmd("podman ps | grep rootlessport"))
|
|
|
|
rootless.wait_until_succeeds(su_cmd("${pkgs.curl}/bin/curl localhost:9000 | grep Testing"))
|
|
|
|
rootless.succeed(su_cmd("podman stop rootlessport"))
|
|
|
|
rootless.succeed(su_cmd("podman rm rootlessport"))
|
|
|
|
|
2021-03-21 20:12:32 +00:00
|
|
|
with subtest("Run container with init"):
|
2023-02-18 10:15:20 +00:00
|
|
|
rootful.succeed(
|
2021-12-08 22:32:24 +00:00
|
|
|
"tar cv -C ${pkgs.pkgsStatic.busybox} . | podman import - busybox"
|
2021-03-21 20:12:32 +00:00
|
|
|
)
|
2023-02-18 10:15:20 +00:00
|
|
|
pid = rootful.succeed("podman run --rm busybox readlink /proc/self").strip()
|
2021-03-21 20:12:32 +00:00
|
|
|
assert pid == "1"
|
2023-02-18 10:15:20 +00:00
|
|
|
pid = rootful.succeed("podman run --rm --init busybox readlink /proc/self").strip()
|
2021-03-21 20:12:32 +00:00
|
|
|
assert pid == "2"
|
2021-05-25 08:26:28 +00:00
|
|
|
|
2022-08-18 03:58:03 +00:00
|
|
|
with subtest("aardvark-dns"):
|
2023-02-18 10:51:36 +00:00
|
|
|
dns.succeed("tar cv --files-from /dev/null | podman import - scratchimg")
|
|
|
|
dns.succeed(
|
|
|
|
"podman run -d --name=webserver -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin -w ${pkgs.writeTextDir "index.html" "<h1>Testing</h1>"} scratchimg ${pkgs.python3}/bin/python -m http.server 8000"
|
|
|
|
)
|
|
|
|
dns.succeed("podman ps | grep webserver")
|
|
|
|
dns.wait_until_succeeds(
|
|
|
|
"podman run --rm --name=client -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin scratchimg ${pkgs.curl}/bin/curl http://webserver:8000 | grep Testing"
|
|
|
|
)
|
|
|
|
dns.succeed("podman stop webserver")
|
|
|
|
dns.succeed("podman rm webserver")
|
2022-08-18 03:58:03 +00:00
|
|
|
|
2021-05-25 08:26:28 +00:00
|
|
|
with subtest("A podman member can use the docker cli"):
|
2022-11-06 00:28:37 +00:00
|
|
|
docker.succeed(su_cmd("docker version"))
|
2021-05-25 08:26:28 +00:00
|
|
|
|
|
|
|
with subtest("Run container via docker cli"):
|
2022-11-06 00:28:37 +00:00
|
|
|
docker.succeed("tar cv --files-from /dev/null | podman import - scratchimg")
|
|
|
|
docker.succeed(
|
2022-02-17 00:56:18 +00:00
|
|
|
"docker run -d --name=sleeping -v /nix/store:/nix/store -v /run/current-system/sw/bin:/bin localhost/scratchimg /bin/sleep 10"
|
2021-05-25 08:26:28 +00:00
|
|
|
)
|
2022-11-06 00:28:37 +00:00
|
|
|
docker.succeed("docker ps | grep sleeping")
|
|
|
|
docker.succeed("podman ps | grep sleeping")
|
|
|
|
docker.succeed("docker stop sleeping")
|
|
|
|
docker.succeed("docker rm sleeping")
|
2021-05-25 08:26:28 +00:00
|
|
|
|
|
|
|
with subtest("A podman non-member can not use the docker cli"):
|
2022-11-06 00:28:37 +00:00
|
|
|
docker.fail(su_cmd("docker version", user="mallory"))
|
2021-05-25 08:26:28 +00:00
|
|
|
|
|
|
|
# TODO: add docker-compose test
|
|
|
|
|
2020-04-20 08:37:53 +00:00
|
|
|
'';
|
|
|
|
}
|
|
|
|
)
|