From 2dd7973751e411e5dd6dc06e19b8c23e42ff2c3d Mon Sep 17 00:00:00 2001 From: Lucas Savva Date: Mon, 15 Mar 2021 19:25:49 +0000 Subject: [PATCH] nixos/acme: Add permissions tests --- nixos/tests/acme.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nixos/tests/acme.nix b/nixos/tests/acme.nix index ef5021bf1a00..99dd8ec6fd3c 100644 --- a/nixos/tests/acme.nix +++ b/nixos/tests/acme.nix @@ -334,6 +334,21 @@ in import ./make-test-python.nix ({ lib, ... }: { check_issuer(webserver, "a.example.test", "pebble") check_connection(client, "a.example.test") + with subtest("Certificates and accounts have safe + valid permissions"): + group = "${nodes.webserver.config.security.acme.certs."a.example.test".group}" + webserver.succeed( + f"test $(stat -L -c \"%a %U %G\" /var/lib/acme/a.example.test/* | tee /dev/stderr | grep '640 acme {group}' | wc -l) -eq 5" + ) + webserver.succeed( + f"test $(stat -L -c \"%a %U %G\" /var/lib/acme/.lego/a.example.test/**/* | tee /dev/stderr | grep '640 acme {group}' | wc -l) -eq 5" + ) + webserver.succeed( + f"test $(stat -L -c \"%a %U %G\" /var/lib/acme/a.example.test | tee /dev/stderr | grep '750 acme {group}' | wc -l) -eq 1" + ) + webserver.succeed( + f"test $(find /var/lib/acme/accounts -type f -exec stat -L -c \"%a %U %G\" {{}} \\; | tee /dev/stderr | grep -v '600 acme {group}' | wc -l) -eq 0" + ) + with subtest("Can generate valid selfsigned certs"): webserver.succeed("systemctl clean acme-a.example.test.service --what=state") webserver.succeed("systemctl start acme-selfsigned-a.example.test.service")