From 24500ed3693467f1ee66572c40d8697eeefb682b Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Mon, 22 May 2023 15:07:03 +0200 Subject: [PATCH] modules: Init with access control --- modules/default.nix | 7 +++++++ modules/dgn-access-control.nix | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 modules/default.nix create mode 100644 modules/dgn-access-control.nix diff --git a/modules/default.nix b/modules/default.nix new file mode 100644 index 0000000..596ea40 --- /dev/null +++ b/modules/default.nix @@ -0,0 +1,7 @@ +{ dgn-lib, ... }: + +{ + imports = dgn-lib.mkImports ./. [ + "dgn-access-control" + ]; +} diff --git a/modules/dgn-access-control.nix b/modules/dgn-access-control.nix new file mode 100644 index 0000000..f04e71d --- /dev/null +++ b/modules/dgn-access-control.nix @@ -0,0 +1,35 @@ +{ config, lib, dgn-lib, meta, name, ... }: + +let + nodeMeta = meta.nodes.${name}; + admins = meta.members.groups.root ++ nodeMeta.admins + ++ (builtins.concatMap (g: meta.members.groups.${g}) nodeMeta.adminGroups); + + cfg = config.dgn-access-control; +in + +with lib; + +{ + 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. + ''; + }; + }; + + config = mkIf cfg.enable { + # Admins have root access to the node + dgn-access-control.users.root = mkDefault admins; + + users.users = builtins.mapAttrs + (u: members: { openssh.authorizedKeys.keys = dgn-lib.getKeyFiles members; }) + cfg.users; + + }; +}