infrastructure/lib/keys/default.nix
Tom Hubrecht 3748efa295
Some checks failed
Build all the nodes / netaccess01 (push) Successful in 21s
Build all the nodes / netcore01 (push) Successful in 21s
Build all the nodes / netcore00 (push) Successful in 22s
Build all the nodes / netcore02 (push) Successful in 26s
Build all the nodes / ap01 (push) Successful in 36s
Build the shell / build-shell (push) Successful in 30s
Build all the nodes / geo01 (push) Successful in 1m4s
Run pre-commit on all files / pre-commit (push) Successful in 37s
Build all the nodes / bridge01 (push) Successful in 1m15s
Build all the nodes / hypervisor01 (push) Successful in 1m16s
Build all the nodes / rescue01 (push) Successful in 1m16s
Build all the nodes / build01 (push) Successful in 1m18s
Build all the nodes / hypervisor02 (push) Successful in 1m18s
Build all the nodes / cof02 (push) Successful in 1m19s
Build all the nodes / tower01 (push) Successful in 1m18s
Build all the nodes / hypervisor03 (push) Successful in 1m22s
Build all the nodes / geo02 (push) Successful in 1m24s
Build all the nodes / web02 (push) Successful in 1m5s
Build all the nodes / web03 (push) Successful in 1m13s
Build all the nodes / compute01 (push) Successful in 1m45s
Build all the nodes / web01 (push) Successful in 1m43s
Build all the nodes / storage01 (push) Failing after 1m0s
Build all the nodes / vault01 (push) Failing after 1m59s
fix(keys): unique is not in extra anymore
2025-04-15 00:34:36 +02:00

51 lines
1.6 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;
getAttr = lib.flip builtins.getAttr;
in
rec {
_memberKeys = builtins.mapAttrs (_: v: v.sshKeys) meta.organization.members;
_builderKeys = builtins.mapAttrs (_: v: v.builderKeys) 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 builder keys of the users
getBuilderKeys = getAttr _builderKeys;
# 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 admins for a node
getNodeAdmins = node: meta.organization.groups.root ++ meta.nodes.${node}.admins;
# All keys needed for secret encryption
getSecretKeys = node: lib.unique (getMemberKeys (getNodeAdmins node) ++ getNodeKeys [ node ]);
# List of keys for all machines wide secrets
machineKeys = rootKeys ++ (getNodeKeys (builtins.attrNames meta.nodes));
mkSecrets = nodes: setDefault { publicKeys = lib.unique (builtins.concatMap getSecretKeys nodes); };
mkRootSecrets = setDefault { publicKeys = lib.unique rootKeys; };
machineKeysBySystem =
system:
rootKeys
++ (getNodeKeys (
builtins.attrNames (lib.filterAttrs (_: v: v.nixpkgs.system == system) meta.nodes)
));
}