infrastructure/modules/dgn-access-control.nix
Tom Hubrecht 6c4099d369
All checks were successful
Check meta / check_meta (pull_request) Successful in 17s
Check meta / check_dns (pull_request) Successful in 16s
build configuration / build_compute01 (pull_request) Successful in 1m19s
build configuration / build_storage01 (pull_request) Successful in 1m15s
build configuration / build_vault01 (pull_request) Successful in 1m10s
build configuration / build_krz01 (pull_request) Successful in 2m4s
build configuration / build_web01 (pull_request) Successful in 1m40s
build configuration / build_web02 (pull_request) Successful in 1m12s
lint / check (pull_request) Successful in 24s
build configuration / build_geo01 (pull_request) Successful in 1m7s
build configuration / build_rescue01 (pull_request) Successful in 1m10s
build configuration / build_geo02 (pull_request) Successful in 1m7s
build configuration / build_bridge01 (pull_request) Successful in 1m8s
build configuration / push_to_cache_vault01 (pull_request) Successful in 1m56s
build configuration / push_to_cache_storage01 (pull_request) Successful in 1m57s
build configuration / push_to_cache_compute01 (pull_request) Successful in 2m19s
build configuration / push_to_cache_web01 (pull_request) Successful in 2m21s
build configuration / push_to_cache_krz01 (pull_request) Successful in 2m30s
build configuration / push_to_cache_geo01 (pull_request) Successful in 1m8s
build configuration / push_to_cache_web02 (pull_request) Successful in 1m17s
Check meta / check_meta (push) Successful in 17s
Check meta / check_dns (push) Successful in 17s
build configuration / push_to_cache_geo02 (pull_request) Successful in 1m11s
build configuration / push_to_cache_bridge01 (pull_request) Successful in 1m10s
build configuration / push_to_cache_rescue01 (pull_request) Successful in 1m23s
build configuration / build_storage01 (push) Successful in 1m16s
build configuration / build_vault01 (push) Successful in 1m13s
build configuration / build_compute01 (push) Successful in 1m20s
build configuration / build_web01 (push) Successful in 1m38s
build configuration / build_krz01 (push) Successful in 1m58s
lint / check (push) Successful in 25s
build configuration / build_web02 (push) Successful in 1m9s
build configuration / build_geo01 (push) Successful in 1m9s
build configuration / build_geo02 (push) Successful in 1m10s
build configuration / build_rescue01 (push) Successful in 1m15s
build configuration / build_bridge01 (push) Successful in 1m2s
build configuration / push_to_cache_storage01 (push) Successful in 1m25s
build configuration / push_to_cache_vault01 (push) Successful in 1m37s
build configuration / push_to_cache_web02 (push) Successful in 1m21s
build configuration / push_to_cache_compute01 (push) Successful in 1m56s
build configuration / push_to_cache_web01 (push) Successful in 2m18s
build configuration / push_to_cache_geo01 (push) Successful in 1m15s
build configuration / push_to_cache_krz01 (push) Successful in 2m25s
build configuration / push_to_cache_geo02 (push) Successful in 1m8s
build configuration / push_to_cache_bridge01 (push) Successful in 1m8s
build configuration / push_to_cache_rescue01 (push) Successful in 1m23s
feat(infra): Internalize nix-lib, and make keys management simpler
2024-10-09 18:58:46 +02:00

90 lines
2.9 KiB
Nix

# Copyright :
# - Tom Hubrecht <tom.hubrecht@dgnum.eu> 2023
#
# Ce logiciel est un programme informatique servant à déployer des
# configurations de serveurs via NixOS.
#
# Ce logiciel est régi par la licence CeCILL soumise au droit français et
# respectant les principes de diffusion des logiciels libres. Vous pouvez
# utiliser, modifier et/ou redistribuer ce programme sous les conditions
# de la licence CeCILL telle que diffusée par le CEA, le CNRS et l'INRIA
# sur le site "http://www.cecill.info".
#
# En contrepartie de l'accessibilité au code source et des droits de copie,
# de modification et de redistribution accordés par cette licence, il n'est
# offert aux utilisateurs qu'une garantie limitée. Pour les mêmes raisons,
# seule une responsabilité restreinte pèse sur l'auteur du programme, le
# titulaire des droits patrimoniaux et les concédants successifs.
#
# A cet égard l'attention de l'utilisateur est attirée sur les risques
# associés au chargement, à l'utilisation, à la modification et/ou au
# développement et à la reproduction du logiciel par l'utilisateur étant
# donné sa spécificité de logiciel libre, qui peut le rendre complexe à
# manipuler et qui le réserve donc à des développeurs et des professionnels
# avertis possédant des connaissances informatiques approfondies. Les
# utilisateurs sont donc invités à charger et tester l'adéquation du
# logiciel à leurs besoins dans des conditions permettant d'assurer la
# sécurité de leurs systèmes et ou de leurs données et, plus généralement,
# à l'utiliser et l'exploiter dans les mêmes conditions de sécurité.
#
# Le fait que vous puissiez accéder à cet en-tête signifie que vous avez
# pris connaissance de la licence CeCILL, et que vous en avez accepté les
# termes.
{
config,
lib,
dgn-keys,
meta,
nodeMeta,
...
}:
let
inherit (lib)
mkDefault
mkEnableOption
mkIf
mkOption
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.users = builtins.mapAttrs (_: members: {
openssh.authorizedKeys.keys = dgn-keys.getKeys members;
}) cfg.users;
};
}