infrastructure/lib/keys/default.nix
Tom Hubrecht 83aa42ac79
All checks were successful
Build all the nodes / netcore02 (push) Successful in 20s
Build all the nodes / ap01 (push) Successful in 32s
Build all the nodes / netcore01 (push) Successful in 40s
Build all the nodes / netaccess01 (push) Successful in 40s
Build all the nodes / hypervisor03 (push) Successful in 1m24s
Build the shell / build-shell (push) Successful in 42s
Build all the nodes / hypervisor02 (push) Successful in 1m30s
Build all the nodes / geo01 (push) Successful in 1m33s
Build all the nodes / geo02 (push) Successful in 1m44s
Build all the nodes / bridge01 (push) Successful in 1m45s
Build all the nodes / rescue01 (push) Successful in 1m46s
Build all the nodes / build01 (push) Successful in 1m47s
Build all the nodes / vault01 (push) Successful in 1m51s
Run pre-commit on all files / pre-commit (push) Successful in 29s
Build all the nodes / hypervisor01 (push) Successful in 2m5s
Build all the nodes / tower01 (push) Successful in 2m6s
Build all the nodes / storage01 (push) Successful in 2m8s
Build all the nodes / web02 (push) Successful in 1m42s
Build all the nodes / web01 (push) Successful in 1m59s
Build all the nodes / web03 (push) Successful in 1m47s
Build all the nodes / compute01 (push) Successful in 3m3s
fix(keys): Make it so agenix works again
2025-02-13 17:38:12 +01:00

49 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 unique;
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: 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 = unique (builtins.concatMap getSecretKeys nodes); };
machineKeysBySystem =
system:
rootKeys
++ (getNodeKeys (
builtins.attrNames (lib.filterAttrs (_: v: v.nixpkgs.system == system) meta.nodes)
));
}