4 maintainers = with lib.maintainers; [ trundle veehaitch ];
7 nodes.machine = { lib, ... }: {
11 defaultQuotingType = "ecdsa_256";
13 whitelistUrl = "http://nixos.org";
17 # Should have access to the AESM socket
18 users.users."sgxtest" = {
20 extraGroups = [ "sgx" ];
23 # Should NOT have access to the AESM socket
24 users.users."nosgxtest".isNormalUser = true;
26 # We don't have a real SGX machine in NixOS tests
27 systemd.services.aesmd.unitConfig.AssertPathExists = lib.mkForce [ ];
30 withQuoteProvider.configuration = { ... }: {
32 quoteProviderLibrary = pkgs.sgx-azure-dcap-client;
34 AZDCAP_DEBUG_LOG_LEVEL = "INFO";
41 testScript = { nodes, ... }:
43 specialisations = "${nodes.machine.system.build.toplevel}/specialisation";
47 status, main_pid = machine.systemctl("show --property MainPID --value aesmd.service")
48 assert status == 0, "Could not get MainPID of aesmd.service"
49 return main_pid.strip()
51 with subtest("aesmd.service starts"):
52 machine.wait_for_unit("aesmd.service")
54 main_pid = get_aesmd_pid()
56 with subtest("aesmd.service runtime directory permissions"):
57 runtime_dir = "/run/aesmd";
58 res = machine.succeed(f"stat -c '%a %U %G' {runtime_dir}").strip()
59 assert "750 aesmd sgx" == res, f"{runtime_dir} does not have the expected permissions: {res}"
61 with subtest("aesm.socket available on host"):
62 socket_path = "/var/run/aesmd/aesm.socket"
63 machine.wait_until_succeeds(f"test -S {socket_path}")
64 machine.succeed(f"test 777 -eq $(stat -c '%a' {socket_path})")
65 for op in [ "-r", "-w", "-x" ]:
66 machine.succeed(f"sudo -u sgxtest test {op} {socket_path}")
67 machine.fail(f"sudo -u nosgxtest test {op} {socket_path}")
69 with subtest("Copies white_list_cert_to_be_verify.bin"):
70 whitelist_path = "/var/opt/aesmd/data/white_list_cert_to_be_verify.bin"
71 whitelist_perms = machine.succeed(
72 f"nsenter -m -t {main_pid} ${pkgs.coreutils}/bin/stat -c '%a' {whitelist_path}"
74 assert "644" == whitelist_perms, f"white_list_cert_to_be_verify.bin has permissions {whitelist_perms}"
76 with subtest("Writes and binds aesm.conf in service namespace"):
77 aesmd_config = machine.succeed(f"nsenter -m -t {main_pid} ${pkgs.coreutils}/bin/cat /etc/aesmd.conf")
79 assert aesmd_config == "whitelist url = http://nixos.org\nproxy type = direct\ndefault quoting type = ecdsa_256\n", "aesmd.conf differs"
81 with subtest("aesmd.service without quote provider library has correct LD_LIBRARY_PATH"):
82 status, environment = machine.systemctl("show --property Environment --value aesmd.service")
83 assert status == 0, "Could not get Environment of aesmd.service"
84 env_by_name = dict(entry.split("=", 1) for entry in environment.split())
85 assert not env_by_name["LD_LIBRARY_PATH"], "LD_LIBRARY_PATH is not empty"
87 with subtest("aesmd.service with quote provider library starts"):
88 machine.succeed('${specialisations}/withQuoteProvider/bin/switch-to-configuration test')
89 machine.wait_for_unit("aesmd.service")
91 main_pid = get_aesmd_pid()
93 with subtest("aesmd.service with quote provider library has correct LD_LIBRARY_PATH"):
94 ld_library_path = machine.succeed(f"xargs -0 -L1 -a /proc/{main_pid}/environ | grep LD_LIBRARY_PATH")
95 assert ld_library_path.startswith("LD_LIBRARY_PATH=${pkgs.sgx-azure-dcap-client}/lib:"), \
96 "LD_LIBRARY_PATH is not set to the configured quote provider library"
98 with subtest("aesmd.service with quote provider library has set AZDCAP_DEBUG_LOG_LEVEL"):
99 azdcp_debug_log_level = machine.succeed(f"xargs -0 -L1 -a /proc/{main_pid}/environ | grep AZDCAP_DEBUG_LOG_LEVEL")
100 assert azdcp_debug_log_level == "AZDCAP_DEBUG_LOG_LEVEL=INFO\n", "AZDCAP_DEBUG_LOG_LEVEL is not set to INFO"