Skip to content

Avoid race condition in attestation-server #83

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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