Skip to content

Commit

Permalink
nixos/attestation-server: fix boot failure nix-community#80
Browse files Browse the repository at this point in the history
As already noted previously, using the service name as the user and
group name in conjunction with DynamicUser sporadically fails.  There is
a better way to provision secrets for services with upcoming systemd
247, but for now we use a SupplementaryGroup to install the secret.
  • Loading branch information
hmenke committed Jan 21, 2021
1 parent 40a71e5 commit f844239
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
11 changes: 5 additions & 6 deletions nixos/attestation-server/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,15 @@ in
"('emailLocal', '${if local then "1" else "0"}')"
];
in optionals (passwordFile != null) [
# Note the leading + on the second command. The passwordFile could be
# Note the leading + on the first command. The passwordFile could be
# anywhere in the file system, so it has to be copied as root and
# permissions fixed to be accessible by the service. However, if the
# first command is run as root the allocation of uid and gid for the
# service seems to be delayed, so we just run something else first.
"${pkgs.coreutils}/bin/touch %S/attestation/emailPassword"
"+${pkgs.coreutils}/bin/install -m 0600 -o %N -g %N ${passwordFile} %S/attestation/emailPassword"
# permissions fixed to be accessible by the service.
"+${pkgs.coreutils}/bin/install -m 0640 -g keys ${passwordFile} %S/attestation/emailPassword"
''${pkgs.sqlite}/bin/sqlite3 %S/attestation/attestation.db "CREATE TABLE IF NOT EXISTS Configuration (key TEXT PRIMARY KEY NOT NULL, value NOT NULL)"''
''${pkgs.sqlite}/bin/sqlite3 %S/attestation/attestation.db "INSERT OR REPLACE INTO Configuration VALUES ${values}"''
"${pkgs.coreutils}/bin/rm -f %S/attestation/emailPassword"
];
SupplementaryGroups = [ "keys" ];

# When sending TERM, e.g. for restart, AttestationServer fails with
# this exit code.
Expand Down
11 changes: 5 additions & 6 deletions nixos/attestation-server/test.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import "${pkgs.path}/nixos/tests/make-test-python.nix" ({ pkgs, ... }: {
device = "crosshatch";
signatureFingerprint = "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA";
avbFingerprint = "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB";
# TODO: Uncomment when https://github.com/danielfullmer/robotnix/issues/80 is resolved
# email = {
# host = "example.com";
# username = "test";
# passwordFile = "${pkgs.writeText "fake-password" "testing123"}"; # NOTE: Don't use writeText like this with a real password!
# };
email = {
host = "example.com";
username = "test";
passwordFile = "${pkgs.writeText "fake-password" "testing123"}"; # NOTE: Don't use writeText like this with a real password!
};
nginx.enable = false;
};
};
Expand Down

0 comments on commit f844239

Please sign in to comment.