Skip to content

Commit 3fcf9cf

Browse files
committed
nixos/attestation-server: use systemd credentials
1 parent a10b7b3 commit 3fcf9cf

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

nixos/attestation-server/module.nix

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ in
111111
wantedBy = [ "multi-user.target" ];
112112
requires = [ "network-online.target" ];
113113

114-
serviceConfig = {
114+
serviceConfig = (lib.optionalAttrs (cfg.email.passwordFile != null) {
115+
LoadCredential = "emailPassword:${cfg.email.passwordFile}";
116+
}) // {
115117
ExecStart = "${cfg.package}/bin/AttestationServer";
116118
ExecStartPre = let
117119
inherit (cfg.email) username passwordFile host port local;
@@ -120,7 +122,7 @@ in
120122
# truncate the trailing newline (\n = char(10)) anyway.
121123
values = lib.concatStringsSep ", " [
122124
"('emailUsername', '${username}')"
123-
"('emailPassword', TRIM(readfile('%S/attestation/emailPassword'), char(10)))"
125+
"('emailPassword', TRIM(readfile('$CREDENTIALS_DIRECTORY/emailPassword'), char(10)))"
124126
"('emailHost', '${host}')"
125127
"('emailPort', '${toString port}')"
126128
"('emailLocal', '${if local then "1" else "0"}')"
@@ -129,12 +131,9 @@ in
129131
# Note the leading + on the first command. The passwordFile could be
130132
# anywhere in the file system, so it has to be copied as root and
131133
# permissions fixed to be accessible by the service.
132-
"+${pkgs.coreutils}/bin/install -m 0640 -g keys ${passwordFile} %S/attestation/emailPassword"
133134
''${pkgs.sqlite}/bin/sqlite3 %S/attestation/attestation.db "CREATE TABLE IF NOT EXISTS Configuration (key TEXT PRIMARY KEY NOT NULL, value NOT NULL)"''
134135
''${pkgs.sqlite}/bin/sqlite3 %S/attestation/attestation.db "INSERT OR REPLACE INTO Configuration VALUES ${values}"''
135-
"${pkgs.coreutils}/bin/rm -f %S/attestation/emailPassword"
136136
];
137-
SupplementaryGroups = [ "keys" ];
138137

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

0 commit comments

Comments
 (0)