Skip to content

Commit d638560

Browse files
committed
nixos/attestation-server: use systemd credentials
1 parent d232ba3 commit d638560

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

nixos/attestation-server/module.nix

+4-5
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ in
107107
wantedBy = [ "multi-user.target" ];
108108
requires = [ "network-online.target" ];
109109

110-
serviceConfig = {
110+
serviceConfig = (lib.optionalAttrs (passwordFile != null) {
111+
LoadCredential = lib."emailPassword:${passwordFile}";
112+
}) // {
111113
ExecStart = "${cfg.package}/bin/AttestationServer";
112114
ExecStartPre = let
113115
inherit (cfg.email) username passwordFile host port local;
@@ -116,7 +118,7 @@ in
116118
# truncate the trailing newline (\n = char(10)) anyway.
117119
values = lib.concatStringsSep ", " [
118120
"('emailUsername', '${username}')"
119-
"('emailPassword', TRIM(readfile('%S/attestation/emailPassword'), char(10)))"
121+
"('emailPassword', TRIM(readfile('$CREDENTIALS_DIRECTORY/emailPassword'), char(10)))"
120122
"('emailHost', '${host}')"
121123
"('emailPort', '${toString port}')"
122124
"('emailLocal', '${if local then "1" else "0"}')"
@@ -125,12 +127,9 @@ in
125127
# Note the leading + on the first command. The passwordFile could be
126128
# anywhere in the file system, so it has to be copied as root and
127129
# permissions fixed to be accessible by the service.
128-
"+${pkgs.coreutils}/bin/install -m 0640 -g keys ${passwordFile} %S/attestation/emailPassword"
129130
''${pkgs.sqlite}/bin/sqlite3 %S/attestation/attestation.db "CREATE TABLE IF NOT EXISTS Configuration (key TEXT PRIMARY KEY NOT NULL, value NOT NULL)"''
130131
''${pkgs.sqlite}/bin/sqlite3 %S/attestation/attestation.db "INSERT OR REPLACE INTO Configuration VALUES ${values}"''
131-
"${pkgs.coreutils}/bin/rm -f %S/attestation/emailPassword"
132132
];
133-
SupplementaryGroups = [ "keys" ];
134133

135134
# When sending TERM, e.g. for restart, AttestationServer fails with
136135
# this exit code.

0 commit comments

Comments
 (0)