infrastructure/lib/keys/default.nix
sinavir d6bf6f6d7f
All checks were successful
Check meta / check_dns (pull_request) Successful in 16s
Check meta / check_meta (pull_request) Successful in 16s
Check workflows / check_workflows (pull_request) Successful in 17s
Build all the nodes / netcore02 (pull_request) Successful in 21s
Build all the nodes / ap01 (pull_request) Successful in 31s
Check meta / check_dns (push) Successful in 17s
Build the shell / build-shell (pull_request) Successful in 24s
Run pre-commit on all files / pre-commit (pull_request) Successful in 27s
Check meta / check_meta (push) Successful in 15s
Run pre-commit on all files / pre-commit (push) Successful in 23s
Build all the nodes / hypervisor01 (pull_request) Successful in 1m45s
Build all the nodes / geo01 (pull_request) Successful in 1m48s
Build all the nodes / build01 (pull_request) Successful in 1m55s
Build all the nodes / web02 (pull_request) Successful in 1m54s
Build all the nodes / storage01 (pull_request) Successful in 2m1s
Build all the nodes / tower01 (pull_request) Successful in 4m51s
Build all the nodes / hypervisor02 (pull_request) Successful in 5m26s
Build all the nodes / vault01 (pull_request) Successful in 5m21s
Build all the nodes / web03 (pull_request) Successful in 5m20s
Build all the nodes / geo02 (pull_request) Successful in 5m37s
Build all the nodes / hypervisor03 (pull_request) Successful in 5m45s
Build all the nodes / bridge01 (pull_request) Successful in 5m50s
Build all the nodes / rescue01 (pull_request) Successful in 5m58s
Build all the nodes / web01 (pull_request) Successful in 6m28s
Build all the nodes / compute01 (pull_request) Successful in 6m45s
chore(lib): Clean instanciation
2025-01-16 11:31:26 +01:00

45 lines
1.4 KiB
Nix

# SPDX-FileCopyrightText: 2024 Ryan Lahfa <ryan.lahfa@dgnum.eu>
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
# SPDX-FileContributor: Maurice Debray <maurice.debray@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
{ meta, lib }:
let
inherit (lib.extra) setDefault unique;
getAttr = lib.flip builtins.getAttr;
in
rec {
_memberKeys = builtins.mapAttrs (_: v: v.sshKeys) meta.organization.members;
_nodeKeys = builtins.mapAttrs (_: v: v.sshKeys) meta.nodes;
# Get keys of the users
getMemberKeys = name: builtins.concatLists (builtins.map (getAttr _memberKeys) name);
# Get keys of the ssh server
getNodeKeys = name: builtins.concatLists (builtins.map (getAttr _nodeKeys) name);
# List of keys for the root group
rootKeys = getMemberKeys meta.organization.groups.root;
# All keys that can access a node
getNodeKeys' =
node:
let
names = meta.nodes.${node}.admins;
in
unique (getMemberKeys names ++ getNodeKeys [ node ]);
# List of keys for all machines wide secrets
machineKeys = rootKeys ++ (getNodeKeys (builtins.attrNames meta.nodes));
mkSecrets = nodes: setDefault { publicKeys = unique (builtins.concatMap getNodeKeys' nodes); };
machineKeysBySystem =
system:
rootKeys
++ (getNodeKeys (
builtins.attrNames (lib.filterAttrs (_: v: v.nixpkgs.system == system) meta.nodes)
));
}