diff --git a/flake.nix b/flake.nix index 1a62a56..d549d15 100644 --- a/flake.nix +++ b/flake.nix @@ -69,6 +69,8 @@ let pkgs = nixpkgs.legacyPackages.${system}; + colmena = inputs.colmena.defaultPackage.${system}; + pre-commit-hooks = inputs.pre-commit-hooks.lib.${system}.run { src = ./.; hooks = { diff --git a/gathered/manager/ssh_host_ed25519_key.pub b/gathered/manager/ssh_host_ed25519_key.pub new file mode 100644 index 0000000..fda1e26 --- /dev/null +++ b/gathered/manager/ssh_host_ed25519_key.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILzkFbPeDhbSD7K+gJZ7peJYe36kyKKHsLnQWGTxJptq root@nixos diff --git a/gathered/node-00/ssh_host_ed25519_key.pub b/gathered/node-00/ssh_host_ed25519_key.pub new file mode 100644 index 0000000..6243b3e --- /dev/null +++ b/gathered/node-00/ssh_host_ed25519_key.pub @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIcyF+SJiS1f1j2Waa0Af2Mx4zxPHl6J3u9gaDMhE9Yv root@nixos diff --git a/machines.nix b/machines.nix index dfa60bd..24c959a 100644 --- a/machines.nix +++ b/machines.nix @@ -5,6 +5,8 @@ let localSystem.system = "x86_64-linux"; }; + nrNodes = 1; + in with deploymentPkgs.lib; let @@ -31,7 +33,8 @@ with deploymentPkgs.lib; let (i: nameValuePair "node-${fixedWidthNumber 2 i}" (mkMachine "node" { id = i; }) - ) 16)); + ) + nrNodes)); in { diff --git a/machines/manager/cache.nix b/machines/manager/cache.nix index df64ee3..940c699 100644 --- a/machines/manager/cache.nix +++ b/machines/manager/cache.nix @@ -20,4 +20,8 @@ }; }; }; + + hpc.hostFile.aliases = [ + "cache.${config.networking.domain}" + ]; } diff --git a/machines/manager/default.nix b/machines/manager/default.nix index 7043369..7fa2958 100644 --- a/machines/manager/default.nix +++ b/machines/manager/default.nix @@ -10,6 +10,7 @@ with lib; ./network.nix ./nfs.nix ./ldap.nix + ./users.nix #./beegfs.nix ./ntp.nix #./gateway.nix diff --git a/machines/manager/ldap.nix b/machines/manager/ldap.nix index 14e720e..e7d3f60 100644 --- a/machines/manager/ldap.nix +++ b/machines/manager/ldap.nix @@ -50,4 +50,8 @@ in sops.secrets."ldap/root/password" = { owner = "openldap"; }; + + hpc.hostFile.aliases = [ + "ldap.${config.networking.domain}" + ]; } diff --git a/machines/manager/netinstall.nix b/machines/manager/netinstall.nix index 29d3c34..e085432 100644 --- a/machines/manager/netinstall.nix +++ b/machines/manager/netinstall.nix @@ -26,4 +26,8 @@ }; }; }; + + hpc.hostFile = [ + "boot.${config.networking.domain}" + ]; } diff --git a/machines/manager/network.nix b/machines/manager/network.nix index 78005cd..b7e6920 100644 --- a/machines/manager/network.nix +++ b/machines/manager/network.nix @@ -10,4 +10,8 @@ address = "10.32.30.1"; interface = "enp11s0f0"; }; + + networking.firewall.trustedInterfaces = [ + "enp11s0f0" + ]; } diff --git a/machines/manager/nfs.nix b/machines/manager/nfs.nix index e61ccb2..030a822 100644 --- a/machines/manager/nfs.nix +++ b/machines/manager/nfs.nix @@ -2,7 +2,7 @@ services.nfs.server = { enable = true; exports = '' - /home node*.${config.networking.domain}(rw) + /home node-*.${config.networking.domain}(rw,no_root_squash) ''; }; } diff --git a/machines/manager/users.nix b/machines/manager/users.nix new file mode 100644 index 0000000..855bbce --- /dev/null +++ b/machines/manager/users.nix @@ -0,0 +1,27 @@ +{ pkgs, lib, config, ... }: + +with lib; + +{ + programs.ssh = { + package = pkgs.openssh.overrideAttrs (final: prev: { + patches = prev.patches ++ [ + ../../patches/openssh-keysign-check-remove.patch + ]; + }); + + extraConfig = '' + EnableSSHKeysign yes + + Host node-*.${config.networking.domain} + HostbasedAuthentication yes + ''; + }; + + security.wrappers."ssh-keysign" = { + source = "${pkgs.openssh}/libexec/ssh-keysign"; + setuid = true; + owner = "root"; + group = "root"; + }; +} diff --git a/machines/node/default.nix b/machines/node/default.nix index 0faac4a..75edc85 100644 --- a/machines/node/default.nix +++ b/machines/node/default.nix @@ -8,6 +8,7 @@ with lib; ./hardware.nix ./disk.nix ./network.nix + ./users.nix ]; deployment = { diff --git a/machines/node/users.nix b/machines/node/users.nix index 56576a3..dc28a6c 100644 --- a/machines/node/users.nix +++ b/machines/node/users.nix @@ -1,16 +1,11 @@ -{ - users.ldap = { - enable = true; - - server = "ldap://manager.hpc.informatik.hs-fulda.de/"; - base = "dc=hpc,dc=informatik,dc=hs-fulda,dc=de"; - - daemon.enable = true; - }; +{ lib, config, nodes, ... }: + +with lib; - filesystem."home" = { +{ + fileSystems."home" = { mountPoint = "/home"; - device = "manager.hpc.informatik.hs-fulda.de:/home"; + device = "manager.${config.networking.domain}:/home"; fsType = "nfs"; options = [ "nfsvers=4.2" @@ -19,4 +14,21 @@ "x-systemd.idle-timeout=600" ]; }; + + services.openssh = { + extraConfig = '' + IgnoreRhosts no + + Match Group cluster + HostbasedAuthentication yes + HostbasedAcceptedAlgorithms ssh-ed25519* + HostbasedUsesNameFromPacketOnly yes + ''; + }; + + environment.etc."ssh/shosts.equiv".text = concatMapStringsSep "\n" + (node: node.config.networking.fqdn) + (attrValues nodes); + + users.groups."cluster" = { }; } diff --git a/modules/default.nix b/modules/default.nix index e7c28b8..f5d01be 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -1,5 +1,6 @@ { imports = [ + ./hostFile.nix ./beegfs.nix ]; -} \ No newline at end of file +} diff --git a/modules/hostFile.nix b/modules/hostFile.nix new file mode 100644 index 0000000..c0cec11 --- /dev/null +++ b/modules/hostFile.nix @@ -0,0 +1,55 @@ +{ pkgs, lib, config, nodes, ... }: + +with lib; + +{ + options.hpc.hostFile = { + addresses = mkOption { + description = '' + IP addresses of this host + ''; + type = types.listOf types.str; + default = + let + interface = config.networking.interfaces.${config.networking.defaultGateway.interface}; + in + concatLists [ + (map (e: e.address) interface.ipv4.addresses) + (map (e: e.address) interface.ipv6.addresses) + ]; + }; + + canonical = mkOption { + description = '' + Canonical host name + ''; + type = types.str; + default = config.networking.fqdn; + }; + + aliases = mkOption { + description = '' + Aliases for this host + ''; + type = types.listOf types.str; + default = [ ]; + }; + + entries = mkOption { + description = '' + Host name entries for this host + ''; + type = types.listOf types.str; + readOnly = true; + default = (singleton config.hpc.hostFile.canonical) ++ config.hpc.hostFile.aliases; + }; + }; + + config = { + networking.hosts = listToAttrs (concatMap + (node: map + (address: nameValuePair address node.config.hpc.hostFile.entries) + node.config.hpc.hostFile.addresses) + (attrValues nodes)); + }; +} diff --git a/patches/openssh-keysign-check-remove.patch b/patches/openssh-keysign-check-remove.patch new file mode 100644 index 0000000..26b788e --- /dev/null +++ b/patches/openssh-keysign-check-remove.patch @@ -0,0 +1,14 @@ +diff --git a/sshconnect2.c b/sshconnect2.c +--- a/sshconnect2.c ++++ b/sshconnect2.c +@@ -2055,10 +2055,6 @@ + *sigp = NULL; + *lenp = 0; + +- if (stat(_PATH_SSH_KEY_SIGN, &st) == -1) { +- error_f("not installed: %s", strerror(errno)); +- return -1; +- } + if (fflush(stdout) != 0) { + error_f("fflush: %s", strerror(errno)); + return -1; diff --git a/shared/default.nix b/shared/default.nix index db0a40b..9132699 100644 --- a/shared/default.nix +++ b/shared/default.nix @@ -1,9 +1,10 @@ -{ pkgs, modulesPath, ... }: +{ pkgs, config, modulesPath, ... }: { imports = [ ./network.nix ./users.nix + ./ssh.nix "${modulesPath}/profiles/headless.nix" "${modulesPath}/profiles/all-hardware.nix" @@ -16,6 +17,11 @@ age.sshKeyPaths = [ "/etc/ssh/ssh_host_ed25519_key" ]; }; + gather = { + target = part: "gathered/${config.networking.hostName}/${part}"; + root = ../.; + }; + time.timeZone = "Europe/Berlin"; console.keyMap = "de"; @@ -26,5 +32,7 @@ tmux ]; + services.haveged.enable = true; + system.stateVersion = "22.11"; } diff --git a/shared/ssh.nix b/shared/ssh.nix new file mode 100644 index 0000000..ceb2f81 --- /dev/null +++ b/shared/ssh.nix @@ -0,0 +1,23 @@ +{ lib, nodes, ... }: + +with lib; + +{ + programs.ssh = { + # Add know-host entries for all machines in the cluster + knownHosts = mapAttrs + (name: node: { + hostNames = [ + node.config.networking.hostName + node.config.networking.fqdn + ]; + publicKeyFile = node.config.gather.parts."ssh/hostKey".path; + }) + nodes; + }; + + gather.parts."ssh/hostKey" = { + name = "ssh_host_ed25519_key.pub"; + file = "/etc/ssh/ssh_host_ed25519_key.pub"; + }; +} diff --git a/shared/users.nix b/shared/users.nix index d0fdae2..42d17f0 100644 --- a/shared/users.nix +++ b/shared/users.nix @@ -1,3 +1,12 @@ +{ lib, config, ... }: + +with lib; + +let + baseDN = concatMapStringsSep "," + (part: "dc=${part}") + (splitString "." config.networking.domain); +in { users.mutableUsers = false; @@ -8,4 +17,19 @@ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIK2nkarN0+uSuP5sGwDCb9KRu+FCjO/+da4VypGanPUZ fooker@k-2so" ]; }; + + users.ldap = { + enable = true; + + server = "ldap://manager.${config.networking.domain}/"; + base = baseDN; + + daemon.enable = true; + }; + + users.users."fooker" = { + isNormalUser = true; + group = "cluster"; + password = "asdasd123"; + }; }