infrastructure/modules/nixos/dgn-access-control.nix
sinavir 07d226a06e
All checks were successful
Build the shell / build-shell (push) Successful in 26s
Build all the nodes / netcore02 (push) Successful in 32s
Build all the nodes / ap01 (push) Successful in 33s
Run pre-commit on all files / pre-commit (push) Successful in 23s
Build all the nodes / geo01 (push) Successful in 1m34s
Build all the nodes / tower01 (push) Successful in 1m39s
Build all the nodes / hypervisor02 (push) Successful in 1m46s
Build all the nodes / hypervisor03 (push) Successful in 1m46s
Build all the nodes / bridge01 (push) Successful in 1m55s
Build all the nodes / geo02 (push) Successful in 1m59s
Build all the nodes / vault01 (push) Successful in 1m59s
Build all the nodes / web02 (push) Successful in 1m58s
Build all the nodes / rescue01 (push) Successful in 2m0s
Build all the nodes / hypervisor01 (push) Successful in 2m6s
Build all the nodes / web03 (push) Successful in 2m4s
Build all the nodes / compute01 (push) Successful in 2m17s
Build all the nodes / build01 (push) Successful in 2m18s
Build all the nodes / storage01 (push) Successful in 2m23s
Build all the nodes / web01 (push) Successful in 2m56s
fix(build01/nix-builder): Use dgn-access-control
2025-01-10 19:26:24 +01:00

67 lines
1.4 KiB
Nix

# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
{
config,
lib,
dgn-keys,
meta,
nodeMeta,
...
}:
let
inherit (lib)
mkDefault
mkEnableOption
mkIf
mkOption
optionalAttrs
types
;
admins =
meta.organization.groups.root
++ nodeMeta.admins
++ (builtins.concatMap (g: meta.organization.groups.${g}) nodeMeta.adminGroups);
cfg = config.dgn-access-control;
in
{
options.dgn-access-control = {
enable = mkEnableOption "DGNum access control." // {
default = true;
};
users = mkOption {
type = with types; attrsOf (listOf str);
default = { };
description = ''
Attribute set describing which member has access to which user on the node.
Members must be declared in `meta/members.nix`.
'';
example = ''
{
user1 = [ "member1" "member2" ];
}
'';
};
};
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:
{
isNormalUser = lib.mkIf (username != "root") true;
openssh.authorizedKeys.keys = dgn-keys.getKeys members;
}
// optionalAttrs (username == "root") { inherit (nodeMeta) hashedPassword; }
) cfg.users;
};
}