2015-05-07 15:49:01 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
cfg = config.services.taskserver;
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
|
|
|
|
taskd = "${pkgs.taskserver}/bin/taskd";
|
|
|
|
|
|
|
|
mkVal = val:
|
|
|
|
if val == true then "true"
|
|
|
|
else if val == false then "false"
|
|
|
|
else if isList val then concatStringsSep ", " val
|
|
|
|
else toString val;
|
|
|
|
|
|
|
|
mkConfLine = key: val: let
|
|
|
|
result = "${key} = ${mkVal val}";
|
|
|
|
in optionalString (val != null && val != []) result;
|
|
|
|
|
|
|
|
needToCreateCA = all isNull (with cfg; [
|
|
|
|
server.key server.cert server.crl caCert
|
|
|
|
]);
|
|
|
|
|
|
|
|
configFile = pkgs.writeText "taskdrc" ''
|
|
|
|
# systemd related
|
|
|
|
daemon = false
|
|
|
|
log = -
|
|
|
|
|
|
|
|
# logging
|
|
|
|
${mkConfLine "debug" cfg.debug}
|
|
|
|
${mkConfLine "ip.log" cfg.ipLog}
|
|
|
|
|
|
|
|
# general
|
|
|
|
${mkConfLine "ciphers" cfg.ciphers}
|
|
|
|
${mkConfLine "confirmation" cfg.confirmation}
|
|
|
|
${mkConfLine "extensions" cfg.extensions}
|
|
|
|
${mkConfLine "queue.size" cfg.queueSize}
|
|
|
|
${mkConfLine "request.limit" cfg.requestLimit}
|
|
|
|
|
|
|
|
# client
|
|
|
|
${mkConfLine "client.cert" cfg.client.cert}
|
|
|
|
${mkConfLine "client.allow" cfg.client.allow}
|
|
|
|
${mkConfLine "client.deny" cfg.client.deny}
|
|
|
|
|
|
|
|
# server
|
|
|
|
server = ${cfg.server.host}:${toString cfg.server.port}
|
|
|
|
${mkConfLine "server.crl" cfg.server.crl}
|
|
|
|
|
|
|
|
# certificates
|
2016-04-05 14:09:12 +00:00
|
|
|
${mkConfLine "trust" cfg.server.trust}
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
${if needToCreateCA then ''
|
2016-04-04 20:55:39 +00:00
|
|
|
ca.cert = ${cfg.dataDir}/keys/ca.cert
|
|
|
|
server.cert = ${cfg.dataDir}/keys/server.cert
|
|
|
|
server.key = ${cfg.dataDir}/keys/server.key
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
'' else ''
|
2016-04-04 20:55:39 +00:00
|
|
|
ca.cert = ${cfg.caCert}
|
|
|
|
server.cert = ${cfg.server.cert}
|
|
|
|
server.key = ${cfg.server.key}
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
''}
|
|
|
|
'';
|
|
|
|
|
nixos/taskserver: Add a nixos-taskdctl command
It's a helper for NixOS systems to make it easier to handle CA
certificate signing, similar to what taskd provides but comes preseeded
with the values from the system configuration.
The tool is very limited at the moment and only allows to *add*
organisations, users and groups. Deletion and suspension however is much
simpler to implement, because we don't need to handle certificate
signing.
Another limitation is that we don't take into account whether
certificates and keys are already set in the system configuration and if
they're set it will fail spectacularly.
For passing the commands to the taskd command, we're using a small C
program which does setuid() and setgid() to the Taskserver user and
group, because runuser(1) needs PAM (quite pointless if you're already
root) and su(1) doesn't allow for setting the group and setgid()s to the
default group of the user, so it even doesn't work in conjunction with
sg(1).
In summary, we now have a shiny nixos-taskdctl command, which lets us do
things like:
nixos-taskdctl add-org NixOS
nixos-taskdctl add-user NixOS alice
nixos-taskdctl export-user NixOS alice
The last command writes a series of shell commands to stdout, which then
can be imported on the client by piping it into a shell as well as doing
it for example via SSH:
ssh root@server nixos-taskdctl export-user NixOS alice | sh
Of course, in terms of security we need to improve this even further so
that we generate the private key on the client and just send a CSR to
the server so that we don't need to push any secrets over the wire.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2016-04-05 15:31:58 +00:00
|
|
|
genClientKey = ''
|
|
|
|
umask 0077
|
|
|
|
if tmpdir="$(${pkgs.coreutils}/bin/mktemp -d)"; then
|
|
|
|
trap "rm -rf '$tmpdir'" EXIT
|
|
|
|
${pkgs.gnutls}/bin/certtool -p --bits 2048 --outfile "$tmpdir/key"
|
|
|
|
|
|
|
|
cat > "$tmpdir/template" <<-\ \ EOF
|
|
|
|
organization = $organisation
|
|
|
|
cn = ${cfg.server.fqdn}
|
|
|
|
tls_www_client
|
|
|
|
encryption_key
|
|
|
|
signing_key
|
|
|
|
EOF
|
|
|
|
|
|
|
|
${pkgs.gnutls}/bin/certtool -c \
|
|
|
|
--load-privkey "$tmpdir/key" \
|
|
|
|
--load-ca-privkey "${cfg.dataDir}/keys/ca.key" \
|
|
|
|
--load-ca-certificate "${cfg.dataDir}/keys/ca.cert" \
|
|
|
|
--template "$tmpdir/template" \
|
|
|
|
--outfile "$tmpdir/cert"
|
|
|
|
|
|
|
|
mkdir -m 0700 -p "${cfg.dataDir}/keys/user/$organisation/$user"
|
|
|
|
chown root:root "${cfg.dataDir}/keys/user/$organisation/$user"
|
|
|
|
cat "$tmpdir/key" \
|
|
|
|
> "${cfg.dataDir}/keys/user/$organisation/$user/private.key"
|
|
|
|
cat "$tmpdir/cert" \
|
|
|
|
> "${cfg.dataDir}/keys/user/$organisation/$user/public.cert"
|
|
|
|
|
|
|
|
rm -rf "$tmpdir"
|
|
|
|
trap - EXIT
|
|
|
|
else
|
|
|
|
echo "Unable to create temporary directory for client" \
|
|
|
|
"certificate creation." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
2016-04-05 15:27:58 +00:00
|
|
|
orgOptions = { name, ... }: {
|
|
|
|
options.users = mkOption {
|
|
|
|
type = types.uniq (types.listOf types.str);
|
|
|
|
default = [];
|
|
|
|
example = [ "alice" "bob" ];
|
|
|
|
description = ''
|
|
|
|
A list of user names that belong to the organization.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
options.groups = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "workers" "slackers" ];
|
|
|
|
description = ''
|
|
|
|
A list of group names that belong to the organization.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
nixos/taskserver: Add a nixos-taskdctl command
It's a helper for NixOS systems to make it easier to handle CA
certificate signing, similar to what taskd provides but comes preseeded
with the values from the system configuration.
The tool is very limited at the moment and only allows to *add*
organisations, users and groups. Deletion and suspension however is much
simpler to implement, because we don't need to handle certificate
signing.
Another limitation is that we don't take into account whether
certificates and keys are already set in the system configuration and if
they're set it will fail spectacularly.
For passing the commands to the taskd command, we're using a small C
program which does setuid() and setgid() to the Taskserver user and
group, because runuser(1) needs PAM (quite pointless if you're already
root) and su(1) doesn't allow for setting the group and setgid()s to the
default group of the user, so it even doesn't work in conjunction with
sg(1).
In summary, we now have a shiny nixos-taskdctl command, which lets us do
things like:
nixos-taskdctl add-org NixOS
nixos-taskdctl add-user NixOS alice
nixos-taskdctl export-user NixOS alice
The last command writes a series of shell commands to stdout, which then
can be imported on the client by piping it into a shell as well as doing
it for example via SSH:
ssh root@server nixos-taskdctl export-user NixOS alice | sh
Of course, in terms of security we need to improve this even further so
that we generate the private key on the client and just send a CSR to
the server so that we don't need to push any secrets over the wire.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2016-04-05 15:31:58 +00:00
|
|
|
mkShellStr = val: "'${replaceStrings ["'"] ["'\\''"] val}'";
|
|
|
|
mkShellName = replaceStrings ["-"] ["_"];
|
|
|
|
|
|
|
|
mkSubCommand = name: { args, description, script }: let
|
|
|
|
mkArg = pos: arg: "local ${arg}=\"\$${toString pos}\"";
|
|
|
|
mkDesc = line: "echo ${mkShellStr " ${line}"} >&2";
|
|
|
|
usagePosArgs = concatMapStringsSep " " (a: "<${a}>") args;
|
|
|
|
in ''
|
|
|
|
subcmd_${mkShellName name}() {
|
|
|
|
${concatImapStringsSep "\n " mkArg args}
|
|
|
|
${script}
|
|
|
|
}
|
|
|
|
|
|
|
|
usage_${mkShellName name}() {
|
|
|
|
echo " nixos-taskdctl ${name} ${usagePosArgs}" >&2
|
|
|
|
${concatMapStringsSep "\n " mkDesc description}
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
|
|
|
|
mkCStr = val: "\"${escape ["\\" "\""] val}\"";
|
|
|
|
|
|
|
|
taskdUser = let
|
|
|
|
runUser = pkgs.writeText "runuser.c" ''
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <pwd.h>
|
|
|
|
#include <grp.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
struct passwd *userinfo;
|
|
|
|
struct group *groupinfo;
|
|
|
|
errno = 0;
|
|
|
|
if ((userinfo = getpwnam(${mkCStr cfg.user})) == NULL) {
|
|
|
|
if (errno == 0)
|
|
|
|
fputs(${mkCStr "User name `${cfg.user}' not found."}, stderr);
|
|
|
|
else
|
|
|
|
perror("getpwnam");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
errno = 0;
|
|
|
|
if ((groupinfo = getgrnam(${mkCStr cfg.group})) == NULL) {
|
|
|
|
if (errno == 0)
|
|
|
|
fputs(${mkCStr "Group name `${cfg.group}' not found."}, stderr);
|
|
|
|
else
|
|
|
|
perror("getgrnam");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
if (setgid(groupinfo->gr_gid) == -1) {
|
|
|
|
perror("setgid");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
if (setuid(userinfo->pw_uid) == -1) {
|
|
|
|
perror("setgid");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
argv[0] = "taskd";
|
|
|
|
if (execv(${mkCStr taskd}, argv) == -1) {
|
|
|
|
perror("execv");
|
|
|
|
return EXIT_FAILURE;
|
|
|
|
}
|
|
|
|
/* never reached */
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
in pkgs.runCommand "taskd-user" {} ''
|
|
|
|
cc -Wall -std=c11 "${runUser}" -o "$out"
|
|
|
|
'';
|
|
|
|
|
|
|
|
subcommands = {
|
|
|
|
list-users = {
|
|
|
|
args = [ "organisation" ];
|
|
|
|
|
|
|
|
description = [
|
|
|
|
"List all users belonging to the specified organisation."
|
|
|
|
];
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
legend "The following users exist for $organisation:"
|
|
|
|
${pkgs.findutils}/bin/find \
|
|
|
|
"${cfg.dataDir}/orgs/$organisation/users" \
|
|
|
|
-mindepth 2 -maxdepth 2 -name config \
|
|
|
|
-exec ${pkgs.gnused}/bin/sed -ne 's/^user *= *//p' {} +
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
list-orgs = {
|
|
|
|
args = [];
|
|
|
|
|
|
|
|
description = [
|
|
|
|
"List available organisations"
|
|
|
|
];
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
legend "The following organisations exist:"
|
|
|
|
${pkgs.findutils}/bin/find \
|
|
|
|
"${cfg.dataDir}/orgs" -mindepth 1 -maxdepth 1 \
|
|
|
|
-type d
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
get-uuid = {
|
|
|
|
args = [ "organisation" "user" ];
|
|
|
|
|
|
|
|
description = [
|
|
|
|
"Get the UUID of the specified user belonging to the specified"
|
|
|
|
"organisation."
|
|
|
|
];
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
for uuid in "${cfg.dataDir}/orgs/$organisation/users"/*; do
|
|
|
|
usr="$(${pkgs.gnused}/bin/sed -ne 's/^user *= *//p' "$uuid/config")"
|
|
|
|
if [ "$usr" = "$user" ]; then
|
|
|
|
legend "User $user has the following UUID:"
|
|
|
|
echo "$(${pkgs.coreutils}/bin/basename "$uuid")"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
echo "No UUID found for user $user." >&2
|
|
|
|
exit 1
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
export-user = {
|
|
|
|
args = [ "organisation" "user" ];
|
|
|
|
|
|
|
|
description = [
|
|
|
|
"Export user of the specified organisation as a series of shell"
|
|
|
|
"commands that can be used on the client side to easily import"
|
|
|
|
"the certificates."
|
|
|
|
""
|
|
|
|
"Note that the private key will be exported as well, so use this"
|
|
|
|
"with care!"
|
|
|
|
];
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
if ! subcmd_quiet list-users "$organisation" | grep -qxF "$user"; then
|
|
|
|
exists "User $user doesn't exist in organisation $organisation."
|
|
|
|
fi
|
|
|
|
|
|
|
|
uuid="$(subcmd_quiet get-uuid "$organisation" "$user")" || exit 1
|
|
|
|
|
|
|
|
cat <<COMMANDS
|
|
|
|
taskdatadir="\''${TASKDATA:-\$HOME/.task}"
|
|
|
|
umask 0077
|
|
|
|
mkdir -p "\$taskdatadir/keys"
|
|
|
|
cat > "\$taskdatadir/keys/public.cert" <<EOF
|
|
|
|
$(cat "${cfg.dataDir}/keys/user/$organisation/$user/public.cert")
|
|
|
|
EOF
|
|
|
|
cat > "\$taskdatadir/keys/private.key" <<EOF
|
|
|
|
$(${pkgs.gnused}/bin/sed -ne '/^---* *BEGIN /,/^---* *END /p' \
|
|
|
|
"${cfg.dataDir}/keys/user/$organisation/$user/private.key")
|
|
|
|
EOF
|
|
|
|
cat > "\$taskdatadir/keys/ca.cert" <<EOF
|
|
|
|
$(cat "${cfg.dataDir}/keys/ca.cert")
|
|
|
|
EOF
|
|
|
|
task config taskd.certificate -- "\$taskdatadir/keys/public.cert"
|
|
|
|
task config taskd.key -- "\$taskdatadir/keys/private.key"
|
|
|
|
task config taskd.ca -- "\$taskdatadir/keys/ca.cert"
|
|
|
|
task config taskd.credentials -- "$organisation/$user/$uuid"
|
|
|
|
COMMANDS
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
add-org = {
|
|
|
|
args = [ "name" ];
|
|
|
|
|
|
|
|
description = [
|
|
|
|
"Create an organisation with the specified name."
|
|
|
|
];
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
if [ -e "orgs/$name" ]; then
|
|
|
|
exists "Organisation with name $name already exists."
|
|
|
|
fi
|
|
|
|
${taskdUser} add org "$name"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
add-user = {
|
|
|
|
args = [ "organisation" "user" ];
|
|
|
|
|
|
|
|
description = [
|
|
|
|
"Create a user for the given organisation and print the UUID along"
|
|
|
|
"with the client certificate and key."
|
|
|
|
];
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
if subcmd list-users "$organisation" | grep -qxF "$user"; then
|
|
|
|
exists "User $user already exists in organisation $organisation."
|
|
|
|
fi
|
|
|
|
${taskdUser} add user "$organisation" "$user"
|
|
|
|
${genClientKey}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
add-group = {
|
|
|
|
args = [ "organisation" "group" ];
|
|
|
|
|
|
|
|
description = [
|
|
|
|
"Create a group for the given organisation."
|
|
|
|
];
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
if [ -e "orgs/$organisation/groups/$group" ]; then
|
|
|
|
exists "Group $group already exists in organisation $organisation."
|
|
|
|
fi
|
|
|
|
${taskdUser} add group "$organisation" "$group"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
mkCase = name: { args, ... }: let
|
|
|
|
mkPosArg = pos: const "\"\$${toString (pos + 1)}\"";
|
|
|
|
cmdArgs = concatImapStringsSep " " mkPosArg args;
|
|
|
|
in ''
|
|
|
|
${name})
|
|
|
|
if [ $# -ne ${toString ((length args) + 1)} ]; then
|
|
|
|
echo "Wrong number of arguments to ${name}." >&2
|
|
|
|
echo >&2
|
|
|
|
usage_${mkShellName name}
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
subcmd "${name}" ${cmdArgs};;
|
|
|
|
'';
|
|
|
|
|
|
|
|
nixos-taskdctl = pkgs.writeScriptBin "nixos-taskdctl" ''
|
|
|
|
#!${pkgs.stdenv.shell}
|
|
|
|
export TASKDDATA=${mkShellStr cfg.dataDir}
|
|
|
|
|
|
|
|
quiet=0
|
|
|
|
# Deliberately undocumented, because we don't want people to use this as
|
|
|
|
# it's only used in and specific to the preStart script of the Taskserver
|
|
|
|
# service.
|
|
|
|
if [ "$1" = "--service-helper" ]; then
|
|
|
|
quiet=1
|
|
|
|
exists() {
|
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
exists() {
|
|
|
|
echo "$@" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
fi
|
|
|
|
|
|
|
|
legend() {
|
|
|
|
if [ $quiet -eq 0 ]; then
|
|
|
|
echo "$@" >&2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
subcmd() {
|
|
|
|
local cmdname="''${1//-/_}"
|
|
|
|
shift
|
|
|
|
"subcmd_$cmdname" "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
subcmd_quiet() {
|
|
|
|
local prev_quiet=$quiet
|
|
|
|
quiet=1
|
|
|
|
subcmd "$@"
|
|
|
|
local ret=$?
|
|
|
|
quiet=$prev_quiet
|
|
|
|
return $ret
|
|
|
|
}
|
|
|
|
|
|
|
|
${concatStrings (mapAttrsToList mkSubCommand subcommands)}
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
${concatStrings (mapAttrsToList mkCase subcommands)}
|
|
|
|
*) echo "Usage: nixos-taskdctl <subcommand> [<args>]" >&2
|
|
|
|
echo >&2
|
|
|
|
echo "A tool to manage taskserver users on NixOS" >&2
|
|
|
|
echo >&2
|
|
|
|
echo "The following subcommands are available:" >&2
|
|
|
|
${concatMapStringsSep "\n " (c: "usage_${mkShellName c}")
|
|
|
|
(attrNames subcommands)}
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
'';
|
|
|
|
|
|
|
|
ctlcmd = "${nixos-taskdctl}/bin/nixos-taskdctl --service-helper";
|
|
|
|
|
2015-05-07 15:49:01 +00:00
|
|
|
in {
|
|
|
|
|
|
|
|
options = {
|
|
|
|
services.taskserver = {
|
|
|
|
|
2015-09-27 17:30:02 +00:00
|
|
|
enable = mkEnableOption "the Taskwarrior server";
|
2015-05-07 15:49:01 +00:00
|
|
|
|
|
|
|
user = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.str;
|
2015-05-07 15:49:01 +00:00
|
|
|
default = "taskd";
|
2015-09-27 17:30:02 +00:00
|
|
|
description = "User for Taskserver.";
|
2015-05-07 15:49:01 +00:00
|
|
|
};
|
|
|
|
|
2015-09-27 13:35:42 +00:00
|
|
|
group = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.str;
|
2015-09-27 13:35:42 +00:00
|
|
|
default = "taskd";
|
2015-09-27 17:30:02 +00:00
|
|
|
description = "Group for Taskserver.";
|
2015-09-27 13:35:42 +00:00
|
|
|
};
|
|
|
|
|
2015-05-07 15:49:01 +00:00
|
|
|
dataDir = mkOption {
|
|
|
|
type = types.path;
|
2015-09-27 17:30:02 +00:00
|
|
|
default = "/var/lib/taskserver";
|
|
|
|
description = "Data directory for Taskserver.";
|
2015-05-07 15:49:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
caCert = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
|
|
|
description = "Fully qualified path to the CA certificate.";
|
2015-05-07 15:49:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
ciphers = mkOption {
|
2016-04-05 14:12:55 +00:00
|
|
|
type = types.nullOr types.str;
|
2015-09-27 17:30:02 +00:00
|
|
|
default = null;
|
|
|
|
example = "NORMAL";
|
2015-05-07 15:49:01 +00:00
|
|
|
description = ''
|
2015-09-27 17:30:02 +00:00
|
|
|
List of GnuTLS ciphers to use. See the GnuTLS documentation for full
|
|
|
|
details.
|
2015-05-07 15:49:01 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-04-05 15:27:58 +00:00
|
|
|
organisations = mkOption {
|
|
|
|
type = types.attrsOf (types.submodule orgOptions);
|
|
|
|
default = {};
|
|
|
|
example.myShinyOrganisation.users = [ "alice" "bob" ];
|
|
|
|
example.myShinyOrganisation.groups = [ "staff" "outsiders" ];
|
|
|
|
example.yetAnotherOrganisation.users = [ "foo" "bar" ];
|
|
|
|
description = ''
|
|
|
|
An attribute set where the keys name the organisation and the values
|
|
|
|
are a set of lists of <option>users</option> and
|
|
|
|
<option>groups</option>.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-05-07 15:49:01 +00:00
|
|
|
confirmation = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.bool;
|
2015-05-07 15:49:01 +00:00
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Determines whether certain commands are confirmed.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
debug = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.bool;
|
2015-05-07 15:49:01 +00:00
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Logs debugging information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
extensions = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2015-05-07 15:49:01 +00:00
|
|
|
description = ''
|
2015-09-27 17:30:02 +00:00
|
|
|
Fully qualified path of the Taskserver extension scripts.
|
|
|
|
Currently there are none.
|
2015-05-07 15:49:01 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
ipLog = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2015-05-07 15:49:01 +00:00
|
|
|
description = ''
|
|
|
|
Logs the IP addresses of incoming requests.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
queueSize = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.int;
|
2015-05-07 15:49:01 +00:00
|
|
|
default = 10;
|
|
|
|
description = ''
|
2015-09-27 17:30:02 +00:00
|
|
|
Size of the connection backlog, see <citerefentry>
|
|
|
|
<refentrytitle>listen</refentrytitle>
|
|
|
|
<manvolnum>2</manvolnum>
|
|
|
|
</citerefentry>.
|
2015-05-07 15:49:01 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
requestLimit = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.int;
|
2015-05-07 15:49:01 +00:00
|
|
|
default = 1048576;
|
|
|
|
description = ''
|
|
|
|
Size limit of incoming requests, in bytes.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
client = {
|
|
|
|
|
|
|
|
allow = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "[Tt]ask [2-9]+" ];
|
2015-05-07 15:49:01 +00:00
|
|
|
description = ''
|
2015-09-27 17:30:02 +00:00
|
|
|
A list of regular expressions that are matched against the reported
|
|
|
|
client id (such as <literal>task 2.3.0</literal>).
|
|
|
|
|
|
|
|
The values <literal>all</literal> or <literal>none</literal> have
|
|
|
|
special meaning. Overidden by any entry in the option
|
|
|
|
<option>services.taskserver.client.deny</option>.
|
2015-05-07 15:49:01 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
cert = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2015-05-07 15:49:01 +00:00
|
|
|
description = ''
|
2015-09-27 17:30:02 +00:00
|
|
|
Fully qualified path of the client cert. This is used by the
|
|
|
|
<command>client</command> command.
|
2015-05-07 15:49:01 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
deny = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
example = [ "[Tt]ask [2-9]+" ];
|
2015-05-07 15:49:01 +00:00
|
|
|
description = ''
|
2015-09-27 17:30:02 +00:00
|
|
|
A list of regular expressions that are matched against the reported
|
|
|
|
client id (such as <literal>task 2.3.0</literal>).
|
|
|
|
|
|
|
|
The values <literal>all</literal> or <literal>none</literal> have
|
|
|
|
special meaning. Any entry here overrides these in
|
|
|
|
<option>services.taskserver.client.allow</option>.
|
2015-05-07 15:49:01 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
server = {
|
|
|
|
host = mkOption {
|
2016-04-05 14:12:55 +00:00
|
|
|
type = types.str;
|
2015-05-07 15:49:01 +00:00
|
|
|
default = "localhost";
|
|
|
|
description = ''
|
2016-04-05 14:16:14 +00:00
|
|
|
The address (IPv4, IPv6 or DNS) to listen on.
|
2015-05-07 15:49:01 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
port = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.int;
|
2015-05-07 15:49:01 +00:00
|
|
|
default = 53589;
|
|
|
|
description = ''
|
2015-09-27 17:30:02 +00:00
|
|
|
Port number of the Taskserver.
|
2015-05-07 15:49:01 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2016-04-05 14:16:14 +00:00
|
|
|
fqdn = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "localhost";
|
|
|
|
description = ''
|
|
|
|
The fully qualified domain name of this server.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2015-05-07 15:49:01 +00:00
|
|
|
cert = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2015-05-07 15:49:01 +00:00
|
|
|
description = "Fully qualified path to the server certificate";
|
|
|
|
};
|
|
|
|
|
|
|
|
crl = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2015-05-07 15:49:01 +00:00
|
|
|
description = ''
|
2015-09-27 17:30:02 +00:00
|
|
|
Fully qualified path to the server certificate revocation list.
|
2015-05-07 15:49:01 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
key = mkOption {
|
2015-09-27 17:30:02 +00:00
|
|
|
type = types.nullOr types.path;
|
|
|
|
default = null;
|
2015-05-07 15:49:01 +00:00
|
|
|
description = ''
|
|
|
|
Fully qualified path to the server key.
|
|
|
|
|
2015-09-27 17:30:02 +00:00
|
|
|
Note that reloading the <literal>taskserver.service</literal> causes
|
|
|
|
a configuration file reload before the next request is handled.
|
2015-05-07 15:49:01 +00:00
|
|
|
'';
|
|
|
|
};
|
2016-04-05 14:09:12 +00:00
|
|
|
|
|
|
|
trust = mkOption {
|
|
|
|
type = types.enum [ "allow all" "strict" ];
|
|
|
|
default = "strict";
|
|
|
|
description = ''
|
|
|
|
Determines how client certificates are validated.
|
|
|
|
|
|
|
|
The value <literal>allow all</literal> performs no client
|
|
|
|
certificate validation. This is not recommended. The value
|
|
|
|
<literal>strict</literal> causes the client certificate to be
|
|
|
|
validated against a CA.
|
|
|
|
'';
|
|
|
|
};
|
2015-05-07 15:49:01 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
nixos/taskserver: Add a nixos-taskdctl command
It's a helper for NixOS systems to make it easier to handle CA
certificate signing, similar to what taskd provides but comes preseeded
with the values from the system configuration.
The tool is very limited at the moment and only allows to *add*
organisations, users and groups. Deletion and suspension however is much
simpler to implement, because we don't need to handle certificate
signing.
Another limitation is that we don't take into account whether
certificates and keys are already set in the system configuration and if
they're set it will fail spectacularly.
For passing the commands to the taskd command, we're using a small C
program which does setuid() and setgid() to the Taskserver user and
group, because runuser(1) needs PAM (quite pointless if you're already
root) and su(1) doesn't allow for setting the group and setgid()s to the
default group of the user, so it even doesn't work in conjunction with
sg(1).
In summary, we now have a shiny nixos-taskdctl command, which lets us do
things like:
nixos-taskdctl add-org NixOS
nixos-taskdctl add-user NixOS alice
nixos-taskdctl export-user NixOS alice
The last command writes a series of shell commands to stdout, which then
can be imported on the client by piping it into a shell as well as doing
it for example via SSH:
ssh root@server nixos-taskdctl export-user NixOS alice | sh
Of course, in terms of security we need to improve this even further so
that we generate the private key on the client and just send a CSR to
the server so that we don't need to push any secrets over the wire.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2016-04-05 15:31:58 +00:00
|
|
|
environment.systemPackages = [ pkgs.taskserver nixos-taskdctl ];
|
2015-05-07 15:49:01 +00:00
|
|
|
|
2015-09-27 13:35:42 +00:00
|
|
|
users.users = optional (cfg.user == "taskd") {
|
|
|
|
name = "taskd";
|
|
|
|
uid = config.ids.uids.taskd;
|
|
|
|
description = "Taskserver user";
|
|
|
|
group = cfg.group;
|
|
|
|
};
|
|
|
|
|
|
|
|
users.groups = optional (cfg.group == "taskd") {
|
|
|
|
name = "taskd";
|
|
|
|
gid = config.ids.gids.taskd;
|
|
|
|
};
|
|
|
|
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
systemd.services.taskserver-ca = mkIf needToCreateCA {
|
|
|
|
requiredBy = [ "taskserver.service" ];
|
|
|
|
after = [ "taskserver-init.service" ];
|
|
|
|
description = "Initialize CA for TaskServer";
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.UMask = "0077";
|
|
|
|
|
|
|
|
script = ''
|
|
|
|
mkdir -m 0700 -p "${cfg.dataDir}/keys"
|
|
|
|
chown root:root "${cfg.dataDir}/keys"
|
|
|
|
|
|
|
|
if [ ! -e "${cfg.dataDir}/keys/ca.key" ]; then
|
|
|
|
${pkgs.gnutls}/bin/certtool -p \
|
|
|
|
--bits 2048 \
|
|
|
|
--outfile "${cfg.dataDir}/keys/ca.key"
|
|
|
|
${pkgs.gnutls}/bin/certtool -s \
|
|
|
|
--template "${pkgs.writeText "taskserver-ca.template" ''
|
2016-04-05 14:16:14 +00:00
|
|
|
cn = ${cfg.server.fqdn}
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
cert_signing_key
|
|
|
|
ca
|
|
|
|
''}" \
|
|
|
|
--load-privkey "${cfg.dataDir}/keys/ca.key" \
|
|
|
|
--outfile "${cfg.dataDir}/keys/ca.cert"
|
|
|
|
|
|
|
|
chgrp "${cfg.group}" "${cfg.dataDir}/keys/ca.cert"
|
|
|
|
chmod g+r "${cfg.dataDir}/keys/ca.cert"
|
|
|
|
fi
|
2015-05-07 15:49:01 +00:00
|
|
|
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
if [ ! -e "${cfg.dataDir}/keys/server.key" ]; then
|
|
|
|
${pkgs.gnutls}/bin/certtool -p \
|
|
|
|
--bits 2048 \
|
|
|
|
--outfile "${cfg.dataDir}/keys/server.key"
|
|
|
|
|
2016-04-05 14:36:49 +00:00
|
|
|
${pkgs.gnutls}/bin/certtool -c \
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
--template "${pkgs.writeText "taskserver-cert.template" ''
|
2016-04-05 14:16:14 +00:00
|
|
|
cn = ${cfg.server.fqdn}
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
tls_www_server
|
|
|
|
encryption_key
|
|
|
|
signing_key
|
|
|
|
''}" \
|
|
|
|
--load-ca-privkey "${cfg.dataDir}/keys/ca.key" \
|
|
|
|
--load-ca-certificate "${cfg.dataDir}/keys/ca.cert" \
|
|
|
|
--load-privkey "${cfg.dataDir}/keys/server.key" \
|
|
|
|
--outfile "${cfg.dataDir}/keys/server.cert"
|
|
|
|
|
|
|
|
chgrp "${cfg.group}" "${cfg.dataDir}/keys/server.key"
|
|
|
|
chmod g+r "${cfg.dataDir}/keys/server.key"
|
|
|
|
chmod a+r "${cfg.dataDir}/keys/server.cert"
|
|
|
|
fi
|
|
|
|
|
|
|
|
chmod go+x "${cfg.dataDir}/keys"
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.taskserver-init = {
|
|
|
|
requiredBy = [ "taskserver.service" ];
|
|
|
|
description = "Initialize Taskserver Data Directory";
|
2015-05-07 15:49:01 +00:00
|
|
|
|
|
|
|
preStart = ''
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
mkdir -m 0770 -p "${cfg.dataDir}"
|
|
|
|
chown "${cfg.user}:${cfg.group}" "${cfg.dataDir}"
|
2015-05-07 15:49:01 +00:00
|
|
|
'';
|
|
|
|
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
script = ''
|
|
|
|
${taskd} init
|
|
|
|
echo "include ${configFile}" > "${cfg.dataDir}/config"
|
|
|
|
touch "${cfg.dataDir}/.is_initialized"
|
|
|
|
'';
|
|
|
|
|
|
|
|
environment.TASKDDATA = cfg.dataDir;
|
|
|
|
|
|
|
|
unitConfig.ConditionPathExists = "!${cfg.dataDir}/.is_initialized";
|
|
|
|
|
|
|
|
serviceConfig.Type = "oneshot";
|
|
|
|
serviceConfig.User = cfg.user;
|
|
|
|
serviceConfig.Group = cfg.group;
|
|
|
|
serviceConfig.PermissionsStartOnly = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.taskserver = {
|
|
|
|
description = "Taskwarrior Server";
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network.target" ];
|
|
|
|
|
|
|
|
environment.TASKDDATA = cfg.dataDir;
|
2015-05-07 15:49:01 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
nixos/taskserver: Refactor module for CA creation
Now the service starts up if only the services.taskserver.enable option
is set to true.
We now also have three systemd services (started in this order):
* taskserver-init: For creating the necessary data directory and also
includes a refecence to the configuration file in
the Nix store.
* taskserver-ca: Only enabled if none of the server.key, server.cert,
server.crl and caCert options are set, so we can
allow for certificates that are issued by another
CA.
This service creates a new CA key+certificate and a
server key+certificate and signs the latter using
the CA key.
The permissions of these keys/certs are set quite
strictly to allow only the root user to sign
certificates.
* taskserver: The main Taskserver service which just starts taskd.
We now also log to stdout and thus to the journal.
Of course, there are still a few problems left to solve, for instance:
* The CA currently only signs the server certificates, so it's
only usable for clients if the server doesn't validate client certs
(which is kinda pointless).
* Using "taskd <command>" is currently still a bit awkward to use, so
we need to properly wrap it in environment.systemPackages to set the
dataDir by default.
* There are still a few configuration options left to include, for
example the "trust" option.
* We might want to introduce an extraConfig option.
* It might be useful to allow for declarative configuration of
organisations and users, especially when it comes to creating client
certificates.
* The right signal has to be sent for the taskserver service to reload
properly.
* Currently the CA and server certificates are created using
server.host as the common name and doesn't set additional certificate
information. This could be improved by adding options that explicitly
set that information.
As for the config file, we might need to patch taskd to allow for
setting not only --data but also a --cfgfile, which then omits the
${dataDir}/config file. We can still use the "include" directive from
the file specified using --cfgfile in order to chainload
${dataDir}/config.
Signed-off-by: aszlig <aszlig@redmoonstudios.org>
2015-09-27 19:52:55 +00:00
|
|
|
ExecStart = "@${taskd} taskd server";
|
2015-05-07 15:49:01 +00:00
|
|
|
User = cfg.user;
|
2015-09-27 13:35:42 +00:00
|
|
|
Group = cfg.group;
|
2015-05-07 15:49:01 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|