Better Server cfg
This commit is contained in:
13
modules/server/arion/default.nix
Normal file
13
modules/server/arion/default.nix
Normal file
@@ -0,0 +1,13 @@
|
||||
{ config, pkgs, lib, ... }:{
|
||||
config = lib.mkIf (config.syscfg.server ? arion) {
|
||||
environment.systemPackages = with pkgs; [ arion ];
|
||||
virtualisation.arion = {
|
||||
backend = "podman-socket";
|
||||
projects = {
|
||||
cloud.settings = import ./docker/cloud.nix { inherit config pkgs lib; };
|
||||
authentik.settings =
|
||||
import ./docker/authentik.nix { inherit config pkgs lib; };
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
@@ -1,15 +1,3 @@
|
||||
{ config, pkgs, lib, ... }:
|
||||
let
|
||||
in {
|
||||
imports = [ ./sops ];
|
||||
environment.systemPackages = with pkgs; [ arion ];
|
||||
virtualisation.arion = {
|
||||
backend = "podman-socket";
|
||||
projects = {
|
||||
cloud.settings = import ./docker/cloud.nix { inherit config pkgs lib; };
|
||||
authentik.settings =
|
||||
import ./docker/authentik.nix { inherit config pkgs lib; };
|
||||
};
|
||||
};
|
||||
|
||||
{ config, pkgs, lib, ... }:{
|
||||
imports = [ ./sops ./nftables ./openssh ./arion ];
|
||||
}
|
||||
|
||||
40
modules/server/nftables/default.nix
Normal file
40
modules/server/nftables/default.nix
Normal file
@@ -0,0 +1,40 @@
|
||||
|
||||
|
||||
{ config, lib, ... }:{
|
||||
config = lib.mkIf (config.syscfg.server.nftables.enable) {
|
||||
boot.kernel.sysctl = {
|
||||
"net.ipv4.ip_forward" = 1;
|
||||
"net.ipv6.conf.all.forwarding" = 1;
|
||||
};
|
||||
|
||||
networking.nftables.enable = true;
|
||||
networking.nftables.ruleset = ''
|
||||
table inet nat {
|
||||
chain prerouting {
|
||||
type nat hook prerouting priority dstnat; policy accept;
|
||||
|
||||
${lib.concatMapStringsSep "\n" (rule:
|
||||
let
|
||||
srcInt = builtins.elemAt rule 0;
|
||||
dstAddr4 = builtins.elemAt rule 1;
|
||||
dstAddr6 = builtins.elemAt rule 2;
|
||||
srcPort = toString (builtins.elemAt rule 3);
|
||||
dstPort = toString (builtins.elemAt rule 4);
|
||||
in ''
|
||||
iifname "${srcInt}" tcp dport ${srcPort} counter dnat ip to ${dstAddr4}:${dstPort}
|
||||
iifname "${srcInt}" udp dport ${srcPort} counter dnat ip to ${dstAddr4}:${dstPort}
|
||||
|
||||
iifname "${srcInt}" tcp dport ${srcPort} counter dnat ip6 to [${dstAddr6}]:${dstPort}
|
||||
iifname "${srcInt}" udp dport ${srcPort} counter dnat ip6 to [${dstAddr6}]:${dstPort}
|
||||
''
|
||||
) config.syscfg.server.nftables.ports}
|
||||
}
|
||||
|
||||
chain postrouting {
|
||||
type nat hook postrouting priority srcnat; policy accept;
|
||||
oifname { ${lib.concatMapStringsSep ", " (iface: ''"${iface}"'') config.syscfg.server.nftables.ifs} } masquerade
|
||||
}
|
||||
}
|
||||
'';
|
||||
};
|
||||
}
|
||||
27
modules/server/openssh/default.nix
Normal file
27
modules/server/openssh/default.nix
Normal file
@@ -0,0 +1,27 @@
|
||||
{ config, lib, ... }:
|
||||
let
|
||||
allUsers = lib.concatMap (peer: if peer.syscfg ? users then peer.syscfg.users else []) config.syscfg.peers;
|
||||
groupedUsers = lib.groupBy (u: u.username) allUsers;
|
||||
allowedUsernames = map (u: u.username) config.syscfg.users;
|
||||
activeUsers = lib.filterAttrs (name: _: lib.elem name allowedUsernames) groupedUsers;
|
||||
in {
|
||||
config = lib.mkIf (config.syscfg.server.nftables.enable) {
|
||||
services.openssh = {
|
||||
enable = true;
|
||||
ports = [ 422 ];
|
||||
banner = "";
|
||||
settings = {
|
||||
PasswordAuthentication = false;
|
||||
PermitRootLogin = "no";
|
||||
ClientAliveInterval = 60;
|
||||
ClientAliveCountMax = 3;
|
||||
TCPKeepAlive = true;
|
||||
};
|
||||
};
|
||||
users.users = lib.mapAttrs (name: userList: {
|
||||
openssh.authorizedKeys.keys = lib.unique (
|
||||
lib.concatMap (u: if u ? pubssh then [ u.pubssh ] else []) userList
|
||||
);
|
||||
}) activeUsers;
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user