feat: add connectivity fix options + hardening
This commit is contained in:
41 files changed
+626
-111
No files matched your search
+8
-1
@@ -113,6 +113,12 @@ ask_all() {
|
||||
fi
|
||||
reject "A free port from 1 to 65535 (80, 443, 2053 and 8443 are taken)." SSH_PORT
|
||||
done
|
||||
say "With a public key, SSH takes no passwords (the console still does)."
|
||||
while true; do
|
||||
ask SSH_KEY "SSH public key for $ADMIN_USER (empty: the password)" ""
|
||||
[[ -z $SSH_KEY || $SSH_KEY =~ ^(ssh-|ecdsa-sha2-|sk-)[a-z0-9@.-]+\ [A-Za-z0-9+/]+=*(\ [^[:cntrl:]]*)?$ ]] && break
|
||||
reject "Not an OpenSSH public key (ssh-ed25519 AAAA... comment)." SSH_KEY
|
||||
done
|
||||
ask_yes QEMU_GUEST "QEMU guest agent (lets the VPS panel see the server's state)" "y"
|
||||
|
||||
# --- Proxy --------------------------------------------------------------------
|
||||
@@ -202,7 +208,7 @@ show_summary() {
|
||||
DNS $NET_DNS
|
||||
Public IP $PUBLIC_IP
|
||||
Hostname $HOST_NAME
|
||||
SSH $ADMIN_USER@$PUBLIC_IP port $SSH_PORT (password shown at the end)
|
||||
SSH $ADMIN_USER@$PUBLIC_IP port $SSH_PORT ($(if [[ -n $SSH_KEY ]]; then echo "your key; password for the console"; else echo "password shown at the end"; fi))
|
||||
Guest agent $(if [[ $QEMU_GUEST == true ]]; then echo yes; else echo no; fi)
|
||||
Proxy user $PROXY_USER
|
||||
Certificate ${DOMAIN:-$PUBLIC_IP (IP certificate)}${ACME_EMAIL:+, $ACME_EMAIL}
|
||||
@@ -277,6 +283,7 @@ cat >"$etc_nixos/host.nix" <<HOST
|
||||
disko.enable = true;
|
||||
adminUser = $(nix_str "$ADMIN_USER");
|
||||
sshPort = $SSH_PORT;
|
||||
sshKeys = [ $(if [[ -n $SSH_KEY ]]; then nix_str "$SSH_KEY"; fi) ];
|
||||
$(print_network_nix " ")
|
||||
publicAddress = $(nix_str "$PUBLIC_IP");
|
||||
domain = $(if [[ -n $DOMAIN ]]; then nix_str "$DOMAIN"; else printf null; fi);
|
||||
|
||||
@@ -77,6 +77,16 @@ in
|
||||
description = "SSH port.";
|
||||
};
|
||||
|
||||
sshKeys = mkOption {
|
||||
type = types.listOf (types.strMatching "(ssh-|ecdsa-sha2-|sk-)[^\n]+");
|
||||
default = [ ];
|
||||
description = ''
|
||||
Public keys adminUser logs in with over SSH. With any, SSH takes no passwords (the
|
||||
console still does); without, it takes the password, and fail2ban bans guessers.
|
||||
'';
|
||||
example = [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... admin@laptop" ];
|
||||
};
|
||||
|
||||
tools.enable = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
@@ -261,9 +271,13 @@ in
|
||||
enable = true;
|
||||
ports = [ cfg.sshPort ];
|
||||
settings = {
|
||||
PasswordAuthentication = true;
|
||||
PasswordAuthentication = cfg.sshKeys == [ ];
|
||||
KbdInteractiveAuthentication = false;
|
||||
PermitRootLogin = "no";
|
||||
# The one login this server has: an account some package adds later gets no SSH.
|
||||
AllowUsers = [ cfg.adminUser ];
|
||||
MaxAuthTries = 3;
|
||||
X11Forwarding = false;
|
||||
};
|
||||
};
|
||||
|
||||
@@ -271,6 +285,7 @@ in
|
||||
users.users.${cfg.adminUser} = {
|
||||
isNormalUser = true;
|
||||
extraGroups = [ "wheel" ];
|
||||
openssh.authorizedKeys.keys = cfg.sshKeys;
|
||||
};
|
||||
|
||||
boot.kernel.sysctl = {
|
||||
@@ -415,6 +430,14 @@ in
|
||||
# Bandwidth per process and connection, without sudo (a capability wrapper).
|
||||
bandwhich.enable = true;
|
||||
};
|
||||
# Wheel only: the wrapper's capabilities (sys_ptrace, dac_read_search, net_raw) show
|
||||
# every connection on the host, the proxy users' included, to whoever runs it.
|
||||
security.wrappers = lib.mkIf cfg.tools.enable {
|
||||
bandwhich = {
|
||||
group = lib.mkForce "wheel";
|
||||
permissions = "u+rx,g+x";
|
||||
};
|
||||
};
|
||||
users.defaultUserShell = lib.mkIf cfg.tools.enable pkgs.fish;
|
||||
|
||||
# Man pages stay; the NixOS manual, info and HTML docs are a download no server needs.
|
||||
|
||||
Reference in new issue
Block a user