2013-08-21 16:44:29 +01:00
|
|
|
# tcsd daemon.
|
|
|
|
|
2021-12-05 20:28:49 +00:00
|
|
|
{ config, options, pkgs, lib, ... }:
|
2013-08-21 16:44:29 +01:00
|
|
|
|
2014-08-25 13:40:40 +01:00
|
|
|
with lib;
|
2013-08-21 16:44:29 +01:00
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.tcsd;
|
2021-12-05 20:28:49 +00:00
|
|
|
opt = options.services.tcsd;
|
2013-08-21 16:44:29 +01:00
|
|
|
|
|
|
|
tcsdConf = pkgs.writeText "tcsd.conf" ''
|
|
|
|
port = 30003
|
|
|
|
num_threads = 10
|
|
|
|
system_ps_file = ${cfg.stateDir}/system.data
|
|
|
|
# This is the log of each individual measurement done by the system.
|
|
|
|
# By re-calculating the PCR registers based on this information, even
|
|
|
|
# finer details about the measured environment can be inferred than
|
|
|
|
# what is available directly from the PCR registers.
|
|
|
|
firmware_log_file = /sys/kernel/security/tpm0/binary_bios_measurements
|
|
|
|
kernel_log_file = /sys/kernel/security/ima/binary_runtime_measurements
|
2015-08-01 15:56:06 +01:00
|
|
|
firmware_pcrs = ${cfg.firmwarePCRs}
|
|
|
|
kernel_pcrs = ${cfg.kernelPCRs}
|
2013-08-21 16:44:29 +01:00
|
|
|
platform_cred = ${cfg.platformCred}
|
|
|
|
conformance_cred = ${cfg.conformanceCred}
|
|
|
|
endorsement_cred = ${cfg.endorsementCred}
|
|
|
|
#remote_ops = create_key,random
|
|
|
|
#host_platform_class = server_12
|
|
|
|
#all_platform_classes = pc_11,pc_12,mobile_12
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.tcsd = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
default = false;
|
2014-04-22 12:39:28 +01:00
|
|
|
type = types.bool;
|
2013-08-21 16:44:29 +01:00
|
|
|
description = ''
|
|
|
|
Whether to enable tcsd, a Trusted Computing management service
|
|
|
|
that provides TCG Software Stack (TSS). The tcsd daemon is
|
|
|
|
the only portal to the Trusted Platform Module (TPM), a hardware
|
|
|
|
chip on the motherboard.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
user = mkOption {
|
|
|
|
default = "tss";
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.str;
|
2013-08-21 16:44:29 +01:00
|
|
|
description = "User account under which tcsd runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
group = mkOption {
|
|
|
|
default = "tss";
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.str;
|
2013-08-21 16:44:29 +01:00
|
|
|
description = "Group account under which tcsd runs.";
|
|
|
|
};
|
|
|
|
|
|
|
|
stateDir = mkOption {
|
2015-08-01 15:56:06 +01:00
|
|
|
default = "/var/lib/tpm";
|
2014-04-22 12:39:28 +01:00
|
|
|
type = types.path;
|
2015-08-01 15:56:06 +01:00
|
|
|
description = ''
|
2013-08-21 16:44:29 +01:00
|
|
|
The location of the system persistent storage file.
|
|
|
|
The system persistent storage file holds keys and data across
|
2019-08-08 21:48:27 +01:00
|
|
|
restarts of the TCSD and system reboots.
|
2015-08-01 15:56:06 +01:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
firmwarePCRs = mkOption {
|
|
|
|
default = "0,1,2,3,4,5,6,7";
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.str;
|
2015-08-01 15:56:06 +01:00
|
|
|
description = "PCR indices used in the TPM for firmware measurements.";
|
|
|
|
};
|
|
|
|
|
|
|
|
kernelPCRs = mkOption {
|
2015-08-02 21:55:45 +01:00
|
|
|
default = "8,9,10,11,12";
|
2019-08-08 21:48:27 +01:00
|
|
|
type = types.str;
|
2015-08-01 15:56:06 +01:00
|
|
|
description = "PCR indices used in the TPM for kernel measurements.";
|
2013-08-21 16:44:29 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
platformCred = mkOption {
|
|
|
|
default = "${cfg.stateDir}/platform.cert";
|
2021-12-05 20:28:49 +00:00
|
|
|
defaultText = literalExpression ''"''${config.${opt.stateDir}}/platform.cert"'';
|
2014-04-22 12:39:28 +01:00
|
|
|
type = types.path;
|
2013-08-21 16:44:29 +01:00
|
|
|
description = ''
|
2015-08-01 15:56:06 +01:00
|
|
|
Path to the platform credential for your TPM. Your TPM
|
2013-08-21 16:44:29 +01:00
|
|
|
manufacturer may have provided you with a set of credentials
|
|
|
|
(certificates) that should be used when creating identities
|
|
|
|
using your TPM. When a user of your TPM makes an identity,
|
|
|
|
this credential will be encrypted as part of that process.
|
|
|
|
See the 1.1b TPM Main specification section 9.3 for information
|
|
|
|
on this process. '';
|
|
|
|
};
|
|
|
|
|
|
|
|
conformanceCred = mkOption {
|
|
|
|
default = "${cfg.stateDir}/conformance.cert";
|
2021-12-05 20:28:49 +00:00
|
|
|
defaultText = literalExpression ''"''${config.${opt.stateDir}}/conformance.cert"'';
|
2014-04-22 12:39:28 +01:00
|
|
|
type = types.path;
|
2013-08-21 16:44:29 +01:00
|
|
|
description = ''
|
|
|
|
Path to the conformance credential for your TPM.
|
|
|
|
See also the platformCred option'';
|
|
|
|
};
|
|
|
|
|
|
|
|
endorsementCred = mkOption {
|
|
|
|
default = "${cfg.stateDir}/endorsement.cert";
|
2021-12-05 20:28:49 +00:00
|
|
|
defaultText = literalExpression ''"''${config.${opt.stateDir}}/endorsement.cert"'';
|
2014-04-22 12:39:28 +01:00
|
|
|
type = types.path;
|
2013-08-21 16:44:29 +01:00
|
|
|
description = ''
|
|
|
|
Path to the endorsement credential for your TPM.
|
|
|
|
See also the platformCred option'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.trousers ];
|
|
|
|
|
nixos/tcsd: several improvements and fixes
- Actually run tcsd as tss/tss
- Install a udev rule to set /dev/tpm* permissions
- Remove systemd-udev-settle dependency, use dev-tpm0.device instead
- Use systemd-tmpfiles to set up the state directory
- Add documentation URI to tcsd.service
This module cannot be easily tested with a NixOS test due to the TPM
dependency. Technically, one could be emulated using swtpm[1], but this
is not packaged in Nixpkgs. If you computer has a real TPM you can do a
passthrough in Qemu, but this requires running the VM as root and of
course it's not determinstic:
$ nix build -f nixos vm --arg configuration '
{
virtualisation.qemu.options = [
"-tpmdev passthrough,id=tpm0,path=/dev/tpm0,cancel-path=/sys/class/tpm/tpm0/cancel"
"-device tpm-tis,tpmdev=tpm0"
];
users.users.root.hashedPassword = "";
services.tcsd.enable = true;
}'
After starting the VM, log in as root, you can check the service has
started with `systemctl status tcsd`.
[1]: https://github.com/stefanberger/swtpm
2021-02-28 18:39:10 +00:00
|
|
|
services.udev.extraRules = ''
|
|
|
|
# Give tcsd ownership of all TPM devices
|
|
|
|
KERNEL=="tpm[0-9]*", MODE="0660", OWNER="${cfg.user}", GROUP="${cfg.group}"
|
|
|
|
# Tag TPM devices to create a .device unit for tcsd to depend on
|
|
|
|
ACTION=="add", KERNEL=="tpm[0-9]*", TAG+="systemd"
|
|
|
|
'';
|
|
|
|
|
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
# Initialise the state directory
|
|
|
|
"d ${cfg.stateDir} 0770 ${cfg.user} ${cfg.group} - -"
|
|
|
|
];
|
2013-08-21 16:44:29 +01:00
|
|
|
|
|
|
|
systemd.services.tcsd = {
|
nixos/tcsd: several improvements and fixes
- Actually run tcsd as tss/tss
- Install a udev rule to set /dev/tpm* permissions
- Remove systemd-udev-settle dependency, use dev-tpm0.device instead
- Use systemd-tmpfiles to set up the state directory
- Add documentation URI to tcsd.service
This module cannot be easily tested with a NixOS test due to the TPM
dependency. Technically, one could be emulated using swtpm[1], but this
is not packaged in Nixpkgs. If you computer has a real TPM you can do a
passthrough in Qemu, but this requires running the VM as root and of
course it's not determinstic:
$ nix build -f nixos vm --arg configuration '
{
virtualisation.qemu.options = [
"-tpmdev passthrough,id=tpm0,path=/dev/tpm0,cancel-path=/sys/class/tpm/tpm0/cancel"
"-device tpm-tis,tpmdev=tpm0"
];
users.users.root.hashedPassword = "";
services.tcsd.enable = true;
}'
After starting the VM, log in as root, you can check the service has
started with `systemctl status tcsd`.
[1]: https://github.com/stefanberger/swtpm
2021-02-28 18:39:10 +00:00
|
|
|
description = "Manager for Trusted Computing resources";
|
|
|
|
documentation = [ "man:tcsd(8)" ];
|
|
|
|
|
|
|
|
requires = [ "dev-tpm0.device" ];
|
|
|
|
after = [ "dev-tpm0.device" ];
|
2013-08-21 16:44:29 +01:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
nixos/tcsd: several improvements and fixes
- Actually run tcsd as tss/tss
- Install a udev rule to set /dev/tpm* permissions
- Remove systemd-udev-settle dependency, use dev-tpm0.device instead
- Use systemd-tmpfiles to set up the state directory
- Add documentation URI to tcsd.service
This module cannot be easily tested with a NixOS test due to the TPM
dependency. Technically, one could be emulated using swtpm[1], but this
is not packaged in Nixpkgs. If you computer has a real TPM you can do a
passthrough in Qemu, but this requires running the VM as root and of
course it's not determinstic:
$ nix build -f nixos vm --arg configuration '
{
virtualisation.qemu.options = [
"-tpmdev passthrough,id=tpm0,path=/dev/tpm0,cancel-path=/sys/class/tpm/tpm0/cancel"
"-device tpm-tis,tpmdev=tpm0"
];
users.users.root.hashedPassword = "";
services.tcsd.enable = true;
}'
After starting the VM, log in as root, you can check the service has
started with `systemctl status tcsd`.
[1]: https://github.com/stefanberger/swtpm
2021-02-28 18:39:10 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = cfg.user;
|
|
|
|
Group = cfg.group;
|
|
|
|
ExecStart = "${pkgs.trousers}/sbin/tcsd -f -c ${tcsdConf}";
|
|
|
|
};
|
2013-08-21 16:44:29 +01:00
|
|
|
};
|
|
|
|
|
2019-09-14 18:51:29 +01:00
|
|
|
users.users = optionalAttrs (cfg.user == "tss") {
|
|
|
|
tss = {
|
2013-08-21 16:44:29 +01:00
|
|
|
group = "tss";
|
2021-09-19 20:42:46 +01:00
|
|
|
isSystemUser = true;
|
2019-09-14 18:51:29 +01:00
|
|
|
};
|
|
|
|
};
|
2013-08-21 16:44:29 +01:00
|
|
|
|
2021-09-19 20:42:46 +01:00
|
|
|
users.groups = optionalAttrs (cfg.group == "tss") { tss = {}; };
|
2013-08-21 16:44:29 +01:00
|
|
|
};
|
|
|
|
}
|