Make dropbear configuration flexible, closes #13

This commit is contained in:
Fabian Hauser 2020-11-24 21:50:57 +00:00
parent f5668614bd
commit 024105c44c
3 changed files with 88 additions and 36 deletions

View file

@ -11,17 +11,26 @@ in {
networking.interfaces.eno1 = { networking.interfaces.eno1 = {
ipv4.addresses = [{ ipv4.addresses = [{
address = montalin-net.v4.ip; address = montalin-net.v4.ip;
prefixLength = plessur-net.lan.v4.bitmask; prefixLength = plessur-net.dmz.v4.bitmask;
}]; }];
}; };
networking.interfaces.wlp1s0.useDHCP = true; networking.interfaces.wlp1s0.useDHCP = true;
networking.defaultGateway = plessur-net.lan.v4.gateway; networking.defaultGateway = plessur-net.dmz.v4.gateway;
networking.nameservers = plessur-net.lan.v4.nameservers; networking.nameservers = plessur-net.dmz.v4.nameservers;
# Configure network proxy if necessary # Configure network proxy if necessary
# networking.proxy.default = "http://user:password@proxy:port/"; # networking.proxy.default = "http://user:password@proxy:port/";
# networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain"; # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";
networking.firewall.allowedTCPPorts = [ 80 443 ]; networking.firewall.allowedTCPPorts = [ 80 443 ];
services.dropbear = {
enable = true;
interface = "eno1";
ip = montalin-net.v4.ip;
netmask = "255.255.255.0";
gateway = plessur-net.dmz.v4.gateway;
sshPort = 2222;
};
} }

View file

@ -12,6 +12,8 @@
v4 = { v4 = {
id = "10.1.2.0"; id = "10.1.2.0";
bitmask = 24; bitmask = 24;
gateway = "10.1.2.1";
nameservers = [ "10.1.2.1" ];
}; };
hosts = { hosts = {
@ -23,9 +25,7 @@
plessur.lan = { plessur.lan = {
v4 = { v4 = {
id = "10.1.1.0"; id = "10.1.1.0";
gateway = "10.1.2.1";
bitmask = 24; bitmask = 24;
nameservers = [ "10.1.2.1" ];
}; };
hosts = { calanda.v4.ip = "10.1.1.1"; }; hosts = { calanda.v4.ip = "10.1.1.1"; };

View file

@ -1,38 +1,81 @@
{ config, pkgs, lib, ... }: { config, lib, pkgs, ... }:
# Note: This implementation currently only allows eno1 (first interface) with dhcp. with lib;
let
ip = "10.1.2.2"; let cfg = config.services.dropbear;
gateway = "10.1.2.1";
netmask = "255.255.255.0";
hostname = config.networking.hostName;
primaryInterface = "eno1";
in { in {
boot.initrd.network = { options.services.dropbear = {
enable = true; enable = mkEnableOption "dropbear service";
ssh = {
enable = true; interface = mkOption {
port = 2222; type = types.str;
authorizedKeys = with lib; example = "enp0";
concatLists (mapAttrsToList (name: user: description = ''
if elem "wheel" user.extraGroups then Interface name.
user.openssh.authorizedKeys.keys '';
else };
[ ]) config.users.users);
hostRSAKey = /boot/dropbear_rsa_host_key; ip = mkOption {
hostECDSAKey = /boot/dropbear_ecdsa_host_key; type = types.str;
# Key generation with dropbearkey -t <type> -f <output-keyfile> example = "192.168.0.1";
description = ''
Host IP Address.
'';
};
gateway = mkOption {
type = types.str;
example = "192.168.0.1";
description = ''
IP of gateway.
'';
};
netmask = mkOption {
type = types.str;
example = "192.168.0.1";
description = ''
Netmask of internal network.
'';
};
sshPort = mkOption {
type = types.addCheck types.int (n: n > 0 && n < 65536);
default = 2222;
description = ''
SSH Port of the dropbear deamon.
Should be different from default SSH port to prevent known hosts collissions.
'';
}; };
postCommands = ''
echo 'cryptsetup-askpass' >> /root/.profile
'';
}; };
boot.kernelParams = [ config = mkIf cfg.enable {
"ip=${ip}::${gateway}:${netmask}:${hostname}:${primaryInterface}:none" boot.initrd.network = {
]; # see https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt enable = true;
ssh = {
enable = true;
port = cfg.sshPort;
authorizedKeys = with lib;
concatLists (mapAttrsToList (name: user:
if elem "wheel" user.extraGroups then
user.openssh.authorizedKeys.keys
else
[ ]) config.users.users);
hostRSAKey = /boot/dropbear_rsa_host_key;
hostECDSAKey = /boot/dropbear_ecdsa_host_key;
# Key generation with dropbearkey -t <type> -f <output-keyfile>
};
postCommands = ''
echo 'cryptsetup-askpass' >> /root/.profile
'';
};
boot.initrd.postMountCommands = '' boot.kernelParams = [
ip link set ${primaryInterface} down "ip=${cfg.ip}::${cfg.gateway}:${cfg.netmask}:${config.networking.hostName}:${cfg.interface}:none"
''; ]; # see https://www.kernel.org/doc/Documentation/filesystems/nfs/nfsroot.txt
boot.initrd.postMountCommands = ''
ip link set ${cfg.interface} down
'';
};
} }