nebula/sshd: Only allow key auth

This commit is contained in:
SebastianStork 2026-01-07 20:40:09 +01:00
parent 2f4a83a906
commit 72ed799826
Signed by: SebastianStork
SSH key fingerprint: SHA256:tRrGdjYOwgHxpSc/wTOZQZEjxcb15P0tyXRsbAfd+2Q
6 changed files with 57 additions and 10 deletions

View file

@ -39,15 +39,11 @@
}; };
}; };
ssh = {
enable = true;
enableDefaultConfig = false;
matchBlocks =
config.custom.sops.secrets.ssh-key
|> lib.mapAttrs (name: _: { identityFile = config.sops.secrets."ssh-key/${name}".path; });
};
lazygit.enable = true; lazygit.enable = true;
ssh.matchBlocks =
config.custom.sops.secrets.ssh-key
|> lib.mapAttrs (name: _: { identityFile = config.sops.secrets."ssh-key/${name}".path; });
}; };
}; };
} }

View file

@ -0,0 +1,29 @@
{
config,
self,
lib,
...
}@moduleArgs:
let
cfg = config.custom.programs.ssh;
in
{
options.custom.programs.ssh = {
enable = lib.mkEnableOption "";
hostName = lib.mkOption {
type = lib.types.nonEmptyStr;
default = moduleArgs.osConfig.networking.hostName or "";
};
publicKeyPath = lib.mkOption {
type = lib.types.path;
default = "${self}/users/${config.home.username}/@${cfg.hostName}/keys/ssh.pub";
};
};
config = lib.mkIf config.custom.programs.ssh.enable {
programs.ssh = {
enable = true;
enableDefaultConfig = false;
};
};
}

View file

@ -1,4 +1,9 @@
{ config, lib, ... }: {
config,
self,
lib,
...
}:
let let
cfg = config.custom.services.nebula.node; cfg = config.custom.services.nebula.node;
in in
@ -25,13 +30,18 @@ in
addr = cfg.address; addr = cfg.address;
inherit (cfg.sshd) port; inherit (cfg.sshd) port;
}; };
settings = {
PasswordAuthentication = false;
KbdInteractiveAuthentication = false;
PermitRootLogin = "no";
};
}; };
nebula.networks.mesh.firewall.inbound = nebula.networks.mesh.firewall.inbound =
config.custom.services.nebula.peers config.custom.services.nebula.peers
|> lib.filter (node: node.isClient) |> lib.filter (node: node.isClient)
|> lib.map (nebula: { |> lib.map (nebula: {
port = "22"; inherit (cfg.sshd) port;
proto = "tcp"; proto = "tcp";
host = nebula.name; host = nebula.name;
}); });
@ -41,5 +51,14 @@ in
requires = [ "nebula@mesh.service" ]; requires = [ "nebula@mesh.service" ];
after = [ "nebula@mesh.service" ]; after = [ "nebula@mesh.service" ];
}; };
users.users.seb.openssh.authorizedKeys.keyFiles =
self.nixosConfigurations
|> lib.filterAttrs (name: _: name != config.networking.hostName)
|> lib.attrValues
|> lib.filter (value: value.config |> lib.hasAttr "home-manager")
|> lib.map (value: value.config.home-manager.users.seb.custom.programs.ssh)
|> lib.filter (ssh: ssh.enable)
|> lib.map (ssh: ssh.publicKeyPath);
}; };
} }

View file

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGBUORYC3AvTPQmtUEApTa9DvHoJy4mjuQy8abSjCcDd seb@desktop

View file

@ -0,0 +1 @@
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAID1WFOdZCvfb1ZRycBGK0x+3viQpkkl6CQ3cV/Mf3gAJ seb@laptop

View file

@ -27,6 +27,7 @@
aliases.enable = true; aliases.enable = true;
direnv.enable = true; direnv.enable = true;
}; };
ssh.enable = true;
git.enable = true; git.enable = true;
kitty.enable = true; kitty.enable = true;
vscode.enable = true; vscode.enable = true;