2024-12-12 14:41:43 +01:00
|
|
|
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
|
2023-06-30 18:39:38 +02:00
|
|
|
#
|
2024-12-12 14:41:43 +01:00
|
|
|
# SPDX-License-Identifier: EUPL-1.2
|
2023-06-30 18:39:38 +02:00
|
|
|
|
2024-02-02 10:51:31 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
2024-10-09 17:04:30 +02:00
|
|
|
dgn-keys,
|
2024-02-02 10:51:31 +01:00
|
|
|
meta,
|
2024-04-18 15:53:20 +02:00
|
|
|
nodeMeta,
|
2024-02-02 10:51:31 +01:00
|
|
|
...
|
|
|
|
}:
|
2023-05-22 15:07:03 +02:00
|
|
|
|
|
|
|
let
|
2023-07-18 17:00:51 +02:00
|
|
|
inherit (lib)
|
|
|
|
mkDefault
|
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
2024-12-07 16:19:59 +01:00
|
|
|
optionalAttrs
|
2023-07-18 17:00:51 +02:00
|
|
|
|
2024-02-02 10:51:31 +01:00
|
|
|
types
|
|
|
|
;
|
2023-07-18 17:00:51 +02:00
|
|
|
|
2024-02-02 10:51:31 +01:00
|
|
|
admins =
|
2024-02-23 10:50:50 +01:00
|
|
|
meta.organization.groups.root
|
2024-02-02 10:51:31 +01:00
|
|
|
++ nodeMeta.admins
|
2024-02-23 10:50:50 +01:00
|
|
|
++ (builtins.concatMap (g: meta.organization.groups.${g}) nodeMeta.adminGroups);
|
2023-05-22 15:07:03 +02:00
|
|
|
|
|
|
|
cfg = config.dgn-access-control;
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options.dgn-access-control = {
|
2024-02-02 10:51:31 +01:00
|
|
|
enable = mkEnableOption "DGNum access control." // {
|
|
|
|
default = true;
|
|
|
|
};
|
2023-05-22 15:07:03 +02:00
|
|
|
|
|
|
|
users = mkOption {
|
|
|
|
type = with types; attrsOf (listOf str);
|
|
|
|
default = { };
|
|
|
|
description = ''
|
|
|
|
Attribute set describing which member has access to which user on the node.
|
2023-05-22 17:24:42 +02:00
|
|
|
Members must be declared in `meta/members.nix`.
|
|
|
|
'';
|
|
|
|
example = ''
|
|
|
|
{
|
|
|
|
user1 = [ "member1" "member2" ];
|
|
|
|
}
|
2023-05-22 15:07:03 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2024-12-08 15:41:24 +01:00
|
|
|
config = mkIf cfg.enable {
|
|
|
|
# Admins have root access to the node
|
|
|
|
dgn-access-control.users.root = mkDefault admins;
|
|
|
|
users.mutableUsers = false;
|
|
|
|
users.users = builtins.mapAttrs (
|
|
|
|
username: members:
|
|
|
|
{
|
2024-10-10 09:23:09 +02:00
|
|
|
openssh.authorizedKeys.keys = dgn-keys.getKeys members;
|
2024-12-08 15:41:24 +01:00
|
|
|
}
|
|
|
|
// optionalAttrs (username == "root") { inherit (nodeMeta) hashedPassword; }
|
|
|
|
) cfg.users;
|
|
|
|
};
|
2023-05-22 15:07:03 +02:00
|
|
|
}
|