Compare commits
10
Commits
c762c24d86
...
bfbdbae99b
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfbdbae99b | ||
|
|
9f29907ec3 | ||
|
|
87821ed109 | ||
|
|
b37ee5777d | ||
|
|
68f40feffb | ||
|
|
a60d2bcd28 | ||
|
|
dc89592eb1 | ||
|
|
fa29ce93f4 | ||
|
|
73f5df1832 | ||
|
|
225020eb8d |
@@ -9,7 +9,7 @@ in
|
|||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
package = (pkgs.symlinkJoin {
|
package = (pkgs.symlinkJoin {
|
||||||
name = "ssh-certs";
|
name = "ssh-certs";
|
||||||
meta.mainProgram = "sign-ssh-user-cert";
|
meta.mainProgram = "ssh-user-cert-sign";
|
||||||
paths = [
|
paths = [
|
||||||
(inputs.self.wrappers.signUserWrapper.apply {
|
(inputs.self.wrappers.signUserWrapper.apply {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
@@ -18,11 +18,18 @@ in
|
|||||||
validUsers = [ "john" "root" "appdaemon" ];
|
validUsers = [ "john" "root" "appdaemon" ];
|
||||||
}).wrapper
|
}).wrapper
|
||||||
|
|
||||||
|
(inputs.self.wrappers.userCheckWrapper.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
}).wrapper
|
||||||
|
|
||||||
(inputs.self.wrappers.signHostWrapper.apply {
|
(inputs.self.wrappers.signHostWrapper.apply {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
provisioner = "admin";
|
provisioner = "admin";
|
||||||
overwrite = true;
|
overwrite = true;
|
||||||
# extraPrincipals = [ "home-pc" ];
|
}).wrapper
|
||||||
|
|
||||||
|
(inputs.self.wrappers.hostCheckWrapper.apply {
|
||||||
|
inherit pkgs;
|
||||||
}).wrapper
|
}).wrapper
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
@@ -35,6 +42,9 @@ in
|
|||||||
type = lib.types.nullOr lib.types.str;
|
type = lib.types.nullOr lib.types.str;
|
||||||
default = "admin";
|
default = "admin";
|
||||||
};
|
};
|
||||||
|
provisionerPasswordFile = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
};
|
||||||
extraPrincipals = lib.mkOption {
|
extraPrincipals = lib.mkOption {
|
||||||
type = lib.types.listOf lib.types.str;
|
type = lib.types.listOf lib.types.str;
|
||||||
default = [ ];
|
default = [ ];
|
||||||
@@ -43,7 +53,7 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
binName = "sign-ssh-host-cert";
|
binName = "ssh-host-cert-sign";
|
||||||
package = config.pkgs.step-cli;
|
package = config.pkgs.step-cli;
|
||||||
extraPackages = with config.pkgs; [ hostname iproute2 systemd ];
|
extraPackages = with config.pkgs; [ hostname iproute2 systemd ];
|
||||||
preHook = ''
|
preHook = ''
|
||||||
@@ -66,6 +76,9 @@ in
|
|||||||
"--principal" "$IP_ADDRESS"
|
"--principal" "$IP_ADDRESS"
|
||||||
]
|
]
|
||||||
++ lib.optionals (config.provisioner != null) [ "--provisioner" "${config.provisioner}" ]
|
++ lib.optionals (config.provisioner != null) [ "--provisioner" "${config.provisioner}" ]
|
||||||
|
++ lib.optionals (config.provisionerPasswordFile != null) [
|
||||||
|
"--provisioner-password-file" "${config.provisionerPasswordFile}"
|
||||||
|
]
|
||||||
++ lib.optionals config.overwrite [ "-f" ]
|
++ lib.optionals config.overwrite [ "-f" ]
|
||||||
++ mkPrincipalArgs config.extraPrincipals;
|
++ mkPrincipalArgs config.extraPrincipals;
|
||||||
postHook = ''
|
postHook = ''
|
||||||
@@ -74,12 +87,50 @@ in
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
flake.wrappers.renewHostWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
sshHostKeyFile = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "/etc/ssh/ssh_host_ed25519_key";
|
||||||
|
};
|
||||||
|
overwrite = lib.mkEnableOption "Overwrite existing cert file?";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "ssh-host-cert-renew";
|
||||||
|
package = config.pkgs.step-cli;
|
||||||
|
extraPackages = with config.pkgs; [ systemd ];
|
||||||
|
args =
|
||||||
|
[ "ssh" "renew" "${config.sshHostKeyFile}-cert.pub" "${config.sshHostKeyFile}" ]
|
||||||
|
++ lib.optionals config.overwrite [ "-f" ];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
flake.wrappers.hostCheckWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
certPath = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
default = "/etc/ssh/ssh_host_ed25519_key-cert.pub";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "ssh-host-cert-check";
|
||||||
|
package = config.pkgs.openssh;
|
||||||
|
exePath = lib.getExe' config.pkgs.openssh "ssh-keygen";
|
||||||
|
args = [ "-Lf" "${config.certPath}" ];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
flake.wrappers.signUserWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
flake.wrappers.signUserWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
||||||
options = {
|
options = {
|
||||||
provisioner = lib.mkOption {
|
provisioner = lib.mkOption {
|
||||||
type = lib.types.nullOr lib.types.str;
|
type = lib.types.nullOr lib.types.str;
|
||||||
default = "admin";
|
default = "admin";
|
||||||
};
|
};
|
||||||
|
provisionerPasswordFile = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
};
|
||||||
validUsers = lib.mkOption {
|
validUsers = lib.mkOption {
|
||||||
description = "A list of the user names that this cert will be valid for";
|
description = "A list of the user names that this cert will be valid for";
|
||||||
type = lib.types.listOf lib.types.str;
|
type = lib.types.listOf lib.types.str;
|
||||||
@@ -89,12 +140,55 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
binName = "sign-ssh-user-cert";
|
binName = "ssh-user-cert-sign";
|
||||||
package = config.pkgs.step-cli;
|
package = config.pkgs.step-cli;
|
||||||
args = [ "ssh" "certificate" "--sign" ]
|
args = [ "ssh" "certificate" "--sign" ]
|
||||||
++ lib.optionals (config.provisioner != null) [ "--provisioner" "${config.provisioner}" ]
|
++ lib.optionals (config.provisioner != null) [ "--provisioner" "${config.provisioner}" ]
|
||||||
|
++ lib.optionals (config.provisionerPasswordFile != null) [
|
||||||
|
"--provisioner-password-file" "${config.provisionerPasswordFile}"
|
||||||
|
]
|
||||||
++ lib.optionals config.overwrite [ "-f" ]
|
++ lib.optionals config.overwrite [ "-f" ]
|
||||||
++ mkPrincipalArgs config.validUsers;
|
++ mkPrincipalArgs config.validUsers;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
flake.wrappers.userCheckWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
certPath = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
default = "$HOME/.ssh/id_ed25519-cert.pub";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
binName = "ssh-user-cert-check";
|
||||||
|
package = config.pkgs.openssh;
|
||||||
|
exePath = lib.getExe' config.pkgs.openssh "ssh-keygen";
|
||||||
|
args = [ "-Lf" "${config.certPath}" ];
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
flake.wrappers.renewalCheck = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
|
||||||
|
options = {
|
||||||
|
certPath = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
default = "$HOME/.ssh/id_ed25519-cert.pub";
|
||||||
|
};
|
||||||
|
expires-in = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "4h";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
config = {
|
||||||
|
binName = "ssh-renewal-check";
|
||||||
|
package = config.pkgs.step-cli;
|
||||||
|
preHook = ''
|
||||||
|
echo "Checking SSH cert at ${config.certPath}"
|
||||||
|
'';
|
||||||
|
args = [
|
||||||
|
"ssh" "needs-renewal" "${config.certPath}"
|
||||||
|
"--expires-in" "${config.expires-in}"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
});
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,281 @@
|
|||||||
|
# New attempt at consolidating SSH config that wraps the step client, SSH certs, and all that in a top-level module
|
||||||
|
{ self, inputs, ... }:
|
||||||
|
let
|
||||||
|
caPatterns = [ "*.john-stream.com" "192.168.1.*" "fded:fb16:653e:25da:be24:11ff:*" ];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
flake.modules.nixos.ssh-new = { config, pkgs, lib, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.ssh-new;
|
||||||
|
hostKeyFile = "${cfg.host.configDir}/${cfg.host.keyFile}";
|
||||||
|
hostCertFile = "${hostKeyFile}-cert.pub";
|
||||||
|
userCAFile = "${cfg.host.configDir}/${cfg.certificates.user.CAFile}";
|
||||||
|
sshHostCAContent = lib.removeSuffix "\n" (builtins.readFile ../hosts/janus/public/ssh_host_ca_key.pub);
|
||||||
|
CAknownHosts = (lib.genAttrs caPatterns (_: {
|
||||||
|
certAuthority = true;
|
||||||
|
publicKey = sshHostCAContent;
|
||||||
|
}));
|
||||||
|
|
||||||
|
wrappers = inputs.self.wrappers;
|
||||||
|
provisionerPasswordFile = config.sops.secrets."janus/admin_jwk".path;
|
||||||
|
sshHostCertSign = (wrappers.signHostWrapper.apply {
|
||||||
|
inherit pkgs provisionerPasswordFile;
|
||||||
|
inherit (cfg.certificates) provisioner;
|
||||||
|
inherit (cfg.certificates.host) extraPrincipals;
|
||||||
|
}).wrapper;
|
||||||
|
sshHostCertRenew = (wrappers.renewHostWrapper.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
sshHostKeyFile = hostKeyFile;
|
||||||
|
overwrite = true;
|
||||||
|
}).wrapper;
|
||||||
|
sshHostCertCheck = (wrappers.hostCheckWrapper.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
certPath = hostCertFile;
|
||||||
|
}).wrapper;
|
||||||
|
sshHostRenewalCheck = (wrappers.renewalCheck.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
certPath = hostCertFile;
|
||||||
|
expires-in = "4h";
|
||||||
|
}).wrapper;
|
||||||
|
sshUserCertSign = (wrappers.signUserWrapper.apply {
|
||||||
|
inherit pkgs provisionerPasswordFile;
|
||||||
|
inherit (cfg.certificates) provisioner;
|
||||||
|
validUsers = [ "root" "john" "appdaemon" ];
|
||||||
|
}).wrapper;
|
||||||
|
sshUserCertCheck = (wrappers.userCheckWrapper.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
certPath = "${cfg.user.keyFile}-cert.pub";
|
||||||
|
}).wrapper;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.ssh-new = {
|
||||||
|
user = {
|
||||||
|
keyFile = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "$HOME/.ssh/id_ed25519";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
host = {
|
||||||
|
configDir = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "/etc/ssh";
|
||||||
|
};
|
||||||
|
keyFile = lib.mkOption {
|
||||||
|
description = "String path to the host private key file";
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "ssh_host_ed25519_key";
|
||||||
|
};
|
||||||
|
keyType = lib.mkOption {
|
||||||
|
description = "OpenSSH host key type for ssh.hostKey.";
|
||||||
|
type = lib.types.enum [ "ed25519" "rsa" "ecdsa" ];
|
||||||
|
default = "ed25519";
|
||||||
|
};
|
||||||
|
extraSettings = lib.mkOption {
|
||||||
|
description = "Extra settings to merge";
|
||||||
|
type = lib.types.attrs;
|
||||||
|
default = { };
|
||||||
|
};
|
||||||
|
};
|
||||||
|
certificates = {
|
||||||
|
provisioner = lib.mkOption {
|
||||||
|
type = lib.types.nullOr lib.types.str;
|
||||||
|
};
|
||||||
|
host = {
|
||||||
|
enable = lib.mkEnableOption "Enable SSH host certs";
|
||||||
|
autoRenew = lib.mkEnableOption "Auto-renew the SSH host certs with a systemd service/timer";
|
||||||
|
extraPrincipals = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
user = {
|
||||||
|
enable = lib.mkEnableOption "Enable SSH user certs";
|
||||||
|
CAFile = lib.mkOption {
|
||||||
|
description = "Filename of the SSH user CA with the config directory";
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "ssh_user_ca_key.pub";
|
||||||
|
};
|
||||||
|
extraPrincipals = lib.mkOption {
|
||||||
|
type = lib.types.listOf lib.types.str;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
services.openssh = {
|
||||||
|
enable = true;
|
||||||
|
openFirewall = true;
|
||||||
|
hostKeys = [
|
||||||
|
{
|
||||||
|
path = hostKeyFile;
|
||||||
|
type = cfg.host.keyType;
|
||||||
|
}
|
||||||
|
];
|
||||||
|
settings = lib.mkMerge [
|
||||||
|
{
|
||||||
|
PasswordAuthentication = false;
|
||||||
|
KbdInteractiveAuthentication = false;
|
||||||
|
}
|
||||||
|
cfg.host.extraSettings
|
||||||
|
(lib.mkIf cfg.certificates.host.enable {
|
||||||
|
HostCertificate = "${hostKeyFile}-cert.pub";
|
||||||
|
})
|
||||||
|
(lib.mkIf cfg.certificates.user.enable {
|
||||||
|
TrustedUserCAKeys = "${cfg.host.configDir}/${cfg.certificates.user.CAFile}";
|
||||||
|
})
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
environment.etc."ssh/${cfg.certificates.user.CAFile}" = lib.mkIf cfg.certificates.user.enable {
|
||||||
|
source = ../hosts/janus/public/ssh_user_ca_key.pub;
|
||||||
|
};
|
||||||
|
|
||||||
|
environment.systemPackages = (
|
||||||
|
lib.optionals cfg.certificates.host.enable [
|
||||||
|
sshHostCertSign
|
||||||
|
sshHostCertRenew
|
||||||
|
sshHostRenewalCheck
|
||||||
|
sshHostCertCheck
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
sops = lib.mkIf cfg.certificates.host.autoRenew {
|
||||||
|
secrets."janus/admin_jwk" = {
|
||||||
|
sopsFile = ../../keys/secrets.yaml;
|
||||||
|
owner = "root";
|
||||||
|
group = "root";
|
||||||
|
mode = "0400";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd = lib.mkIf cfg.certificates.host.autoRenew {
|
||||||
|
services.ssh-certs-renew = {
|
||||||
|
description = "SSH host certificate renewal";
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [ "network-online.target" ];
|
||||||
|
wants = [ "network-online.target" ];
|
||||||
|
path = with pkgs; [ step-cli systemd ];
|
||||||
|
serviceConfig = {
|
||||||
|
Type = "oneshot";
|
||||||
|
User = "root";
|
||||||
|
Group = "root";
|
||||||
|
ExecCondition = lib.getExe sshHostRenewalCheck;
|
||||||
|
ExecStart = lib.getExe sshHostCertRenew;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
timers.ssh-certs-renew = {
|
||||||
|
description = "Periodic Step SSH host certificate renewal";
|
||||||
|
wantedBy = [ "timers.target" ];
|
||||||
|
timerConfig = {
|
||||||
|
OnBootSec = "5m";
|
||||||
|
OnUnitActiveSec = "4h";
|
||||||
|
RandomizedDelaySec = "15m";
|
||||||
|
Persistent = true;
|
||||||
|
Unit = "ssh-certs-renew.service";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
# This winds up in /etc/ssh/ssh_known_hosts, which applies to all users
|
||||||
|
programs.ssh.knownHosts = lib.mkIf cfg.certificates.user.enable CAknownHosts;
|
||||||
|
|
||||||
|
home-manager.users.root = lib.mkIf cfg.certificates.user.enable {
|
||||||
|
home.stateVersion = lib.mkDefault config.system.stateVersion;
|
||||||
|
imports = with inputs.self.modules.homeManager; [
|
||||||
|
ssh-new
|
||||||
|
];
|
||||||
|
home.packages = [
|
||||||
|
sshUserCertSign
|
||||||
|
sshUserCertCheck
|
||||||
|
];
|
||||||
|
ssh-new.certificates.enable = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
flake.modules.homeManager.ssh-new = { config, pkgs, lib, ... }:
|
||||||
|
let
|
||||||
|
cfg = config.ssh-new;
|
||||||
|
sshHostCAContent = lib.removeSuffix "\n" (builtins.readFile ../hosts/janus/public/ssh_host_ca_key.pub);
|
||||||
|
knownHostsText = lib.concatMapStrings
|
||||||
|
(pattern: "@cert-authority ${pattern} ${sshHostCAContent}\n")
|
||||||
|
caPatterns;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.ssh-new = {
|
||||||
|
keyFile = lib.mkOption {
|
||||||
|
type = lib.types.str;
|
||||||
|
default = "${config.home.homeDirectory}/.ssh/id_ed25519";
|
||||||
|
};
|
||||||
|
certificates = {
|
||||||
|
enable = lib.mkEnableOption "Enable SSH client certificates";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
home.file.".ssh/known_hosts" = lib.mkIf cfg.certificates.enable {
|
||||||
|
text = knownHostsText;
|
||||||
|
};
|
||||||
|
programs.ssh = {
|
||||||
|
enable = true;
|
||||||
|
enableDefaultConfig = false;
|
||||||
|
settings = {
|
||||||
|
# These settings apply to all connections
|
||||||
|
"*" = lib.mkMerge (
|
||||||
|
[
|
||||||
|
# Default settings
|
||||||
|
{
|
||||||
|
Compression = false;
|
||||||
|
ServerAliveInterval = 60;
|
||||||
|
ServerAliveCountMax = 3;
|
||||||
|
TCPKeepAlive = "yes";
|
||||||
|
ConnectTimeout = 3;
|
||||||
|
|
||||||
|
PubkeyAuthentication = "yes";
|
||||||
|
PasswordAuthentication = "no";
|
||||||
|
PreferredAuthentications = "publickey";
|
||||||
|
IdentitiesOnly = true;
|
||||||
|
IdentityFile = cfg.keyFile;
|
||||||
|
|
||||||
|
StrictHostKeyChecking = "accept-new";
|
||||||
|
UserKnownHostsFile = "${config.home.homeDirectory}/.ssh/known_hosts";
|
||||||
|
|
||||||
|
HashKnownHosts = lib.mkDefault false;
|
||||||
|
AddKeysToAgent = lib.mkDefault "yes";
|
||||||
|
ForwardAgent = lib.mkDefault false;
|
||||||
|
|
||||||
|
RequestTTY = lib.mkDefault "auto";
|
||||||
|
SetEnv.TERM = "xterm-256color";
|
||||||
|
}
|
||||||
|
]
|
||||||
|
# SSH certificate settings
|
||||||
|
++ lib.optionals cfg.certificates.enable [
|
||||||
|
{
|
||||||
|
CertificateFile = "${cfg.keyFile}-cert.pub";
|
||||||
|
}
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
"gitea" = {
|
||||||
|
HostName = "192.168.1.104";
|
||||||
|
User = "john";
|
||||||
|
};
|
||||||
|
"janus" = {
|
||||||
|
HostName = "fded:fb16:653e:25da:be24:11ff:fe6b:4d57";
|
||||||
|
User = "root";
|
||||||
|
};
|
||||||
|
"hermes" = {
|
||||||
|
HostName = "192.168.1.150";
|
||||||
|
User = "root";
|
||||||
|
};
|
||||||
|
"jdl-docker" = {
|
||||||
|
HostName = "jdl-docker.tailcf205.ts.net";
|
||||||
|
User = "john";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
let
|
let
|
||||||
defaultCaUrl = "https://janus.john-stream.com/";
|
defaultCaUrl = "https://janus.john-stream.com/";
|
||||||
defaultFingerprint = "2036c44f7b5901566ff7611ea6c927291ecc6d2dd00779c0eead70ec77fa10d6";
|
defaultFingerprint = "2036c44f7b5901566ff7611ea6c927291ecc6d2dd00779c0eead70ec77fa10d6";
|
||||||
defaultRoot = ../hosts/janus/root_ca.crt;
|
defaultRoot = ../hosts/janus/public/root_ca.crt;
|
||||||
|
|
||||||
mkStepBootstrap = { pkgs, caUrl, fingerprint, install ? false }:
|
mkStepBootstrap = { pkgs, caUrl, fingerprint, install ? false }:
|
||||||
(inputs.self.wrappers.stepBootstrap.apply {
|
(inputs.self.wrappers.stepBootstrap.apply {
|
||||||
|
|||||||
@@ -38,14 +38,14 @@ Secret source-of-truth after this split:
|
|||||||
|
|
||||||
Then update public artifacts in repo from generated output:
|
Then update public artifacts in repo from generated output:
|
||||||
|
|
||||||
- `modules/hosts/janus/root_ca.crt` from `/tmp/janus-step-ca-bootstrap/step/certs/root_ca.crt`
|
- `modules/hosts/janus/public/root_ca.crt` from `/tmp/janus-step-ca-bootstrap/step/certs/root_ca.crt`
|
||||||
- `modules/hosts/janus/intermediate_ca.crt` from `/tmp/janus-step-ca-bootstrap/step/certs/intermediate_ca.crt` (public certificate; intentionally committed, not stored in SOPS)
|
- `modules/hosts/janus/public/intermediate_ca.crt` from `/tmp/janus-step-ca-bootstrap/step/certs/intermediate_ca.crt` (public certificate; intentionally committed, not stored in SOPS)
|
||||||
- `modules/hosts/janus/fingerprint` from:
|
- `modules/hosts/janus/fingerprint` from:
|
||||||
```shell
|
```shell
|
||||||
step certificate fingerprint /tmp/janus-step-ca-bootstrap/step/certs/root_ca.crt
|
step certificate fingerprint /tmp/janus-step-ca-bootstrap/step/certs/root_ca.crt
|
||||||
```
|
```
|
||||||
- `modules/hosts/janus/ssh_user_ca_key.pub` from `/tmp/janus-step-ca-bootstrap/step/certs/ssh_user_ca_key.pub`
|
- `modules/hosts/janus/public/ssh_user_ca_key.pub` from `/tmp/janus-step-ca-bootstrap/step/certs/ssh_user_ca_key.pub`
|
||||||
- `modules/hosts/janus/ssh_host_ca_key.pub` from `/tmp/janus-step-ca-bootstrap/step/certs/ssh_host_ca_key.pub`
|
- `modules/hosts/janus/public/ssh_host_ca_key.pub` from `/tmp/janus-step-ca-bootstrap/step/certs/ssh_host_ca_key.pub`
|
||||||
|
|
||||||
## First boot checks
|
## First boot checks
|
||||||
|
|
||||||
|
|||||||
@@ -4,19 +4,19 @@ let
|
|||||||
hostname = "janus";
|
hostname = "janus";
|
||||||
ipv4 = "192.168.1.32";
|
ipv4 = "192.168.1.32";
|
||||||
ipv6 = "fded:fb16:653e:25da:be24:11ff:fe6b:4d57";
|
ipv6 = "fded:fb16:653e:25da:be24:11ff:fe6b:4d57";
|
||||||
|
names = [ "${hostname}.john-stream.com" ipv4 ipv6 ];
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
flake.nixosConfigurations."${hostname}" = inputs.nixpkgs.lib.nixosSystem {
|
flake.nixosConfigurations."${hostname}" = inputs.nixpkgs.lib.nixosSystem {
|
||||||
modules = with inputs.self.modules; [
|
modules = with inputs.self.modules; [
|
||||||
nixos.lxc
|
nixos.lxc
|
||||||
nixos.mysops
|
nixos.login-text
|
||||||
nixos.ssh-certs
|
|
||||||
nixos.step-client
|
|
||||||
nixos.step-ca
|
|
||||||
inputs.home-manager.nixosModules.home-manager
|
inputs.home-manager.nixosModules.home-manager
|
||||||
nixos."${username}"
|
nixos."${username}"
|
||||||
nixos.docker
|
nixos.ssh-new
|
||||||
nixos.login-text
|
nixos.mysops
|
||||||
|
nixos.step-ca # Runs the step-ca server
|
||||||
|
nixos.step-client # Uses the step-ca server as a client
|
||||||
nixos.mtls
|
nixos.mtls
|
||||||
({ config, lib, pkgs, ... }: {
|
({ config, lib, pkgs, ... }: {
|
||||||
networking.hostName = hostname;
|
networking.hostName = hostname;
|
||||||
@@ -24,18 +24,19 @@ in
|
|||||||
"Step-CA" = "step-ca";
|
"Step-CA" = "step-ca";
|
||||||
};
|
};
|
||||||
sops.defaultSopsFile = ./secrets.yaml;
|
sops.defaultSopsFile = ./secrets.yaml;
|
||||||
ssh-certs = {
|
ssh-new.certificates = {
|
||||||
hostname = hostname;
|
provisioner = "admin";
|
||||||
extraPrincipals = [ ipv4 ipv6 ];
|
host = {
|
||||||
|
enable = true;
|
||||||
|
extraPrincipals = names;
|
||||||
|
autoRenew = true;
|
||||||
|
};
|
||||||
|
user.enable = true;
|
||||||
};
|
};
|
||||||
step-ca = {
|
step-ca = {
|
||||||
rootCertPath = ./root_ca.crt;
|
rootCertPath = ./public/root_ca.crt;
|
||||||
intermediateCertPath = ./intermediate_ca.crt;
|
intermediateCertPath = ./public/intermediate_ca.crt;
|
||||||
dnsNames = [
|
dnsNames = names;
|
||||||
"${hostname}.john-stream.com"
|
|
||||||
ipv4
|
|
||||||
ipv6
|
|
||||||
];
|
|
||||||
secrets = {
|
secrets = {
|
||||||
sopsFile = ./secrets.yaml;
|
sopsFile = ./secrets.yaml;
|
||||||
caPassword = "janus/ca_password";
|
caPassword = "janus/ca_password";
|
||||||
@@ -49,10 +50,7 @@ in
|
|||||||
mtls = {
|
mtls = {
|
||||||
enable = true;
|
enable = true;
|
||||||
subject = hostname;
|
subject = hostname;
|
||||||
san = [
|
san = names;
|
||||||
"${hostname}.john-stream.com"
|
|
||||||
ipv4
|
|
||||||
];
|
|
||||||
bootstrap = {
|
bootstrap = {
|
||||||
enable = true;
|
enable = true;
|
||||||
after = [ "sops-nix.service" "step-ca.service" ];
|
after = [ "sops-nix.service" "step-ca.service" ];
|
||||||
@@ -60,24 +58,6 @@ in
|
|||||||
provisionerPasswordFile = config.sops.secrets."janus/admin_jwk".path;
|
provisionerPasswordFile = config.sops.secrets."janus/admin_jwk".path;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
users.users."${username}" = {
|
|
||||||
shell = lib.mkForce (
|
|
||||||
lib.getExe inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.jsl-zsh
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
# users.users."${username}".openssh.authorizedKeys.keys = [
|
|
||||||
# "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMOkGLo4N/L3RYvaIZ1FmePlxa1HK0fMciZxKtRhN58F root@janus"
|
|
||||||
# ];
|
|
||||||
|
|
||||||
home-manager.users."${username}" = {
|
|
||||||
imports = with inputs.self.modules.homeManager; [
|
|
||||||
mysops
|
|
||||||
step-client
|
|
||||||
];
|
|
||||||
docker.enable = true;
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,11 +3,8 @@ let
|
|||||||
username = "john";
|
username = "john";
|
||||||
hostname = "john-pc-ubuntu";
|
hostname = "john-pc-ubuntu";
|
||||||
|
|
||||||
# testTarget = "fded:fb16:653e:25da:be24:11ff:fe89:1cc3"; # soteria
|
|
||||||
# testTarget = "fded:fb16:653e:25da:be24:11ff:fea0:753f"; # test-nix
|
|
||||||
testHost = "soteria"; # which host to test build
|
testHost = "soteria"; # which host to test build
|
||||||
testTarget = "test-nix";
|
testTarget = "test-nix";
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
flake.modules.homeManager."${hostname}" = { config, pkgs, lib, ... }:
|
flake.modules.homeManager."${hostname}" = { config, pkgs, lib, ... }:
|
||||||
@@ -41,11 +38,7 @@ in
|
|||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
nil # Nix language server
|
nil # Nix language server
|
||||||
selfPkgs.jsl-zsh
|
selfPkgs.jsl-zsh
|
||||||
# selfPkgs.my-neovim
|
# selfPkgs.ssh-certs
|
||||||
selfPkgs.ssh-certs
|
|
||||||
# selfPkgs.step-bootstrap
|
|
||||||
# selfPkgs.wg-platform
|
|
||||||
# self'.packages.myWrappedPackage
|
|
||||||
(inputs.self.wrappers.test-push.apply {
|
(inputs.self.wrappers.test-push.apply {
|
||||||
inherit pkgs flakeDir;
|
inherit pkgs flakeDir;
|
||||||
host = testHost;
|
host = testHost;
|
||||||
@@ -55,20 +48,18 @@ in
|
|||||||
|
|
||||||
homeManagerFlakeDir = flakeDir;
|
homeManagerFlakeDir = flakeDir;
|
||||||
docker.enable = true;
|
docker.enable = true;
|
||||||
|
ssh-new = {
|
||||||
ssh = {
|
|
||||||
certificates.enable = true;
|
certificates.enable = true;
|
||||||
knownHosts = [
|
|
||||||
"@cert-authority fded:fb16:653e:25da:be24:11ff:* ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBNug18oLH0vZxnibXJzMJvTWFPZTnSlhCDDVi+rHhgnIum6ZXQ4SF+VHOOAM5BbzZmMKitNJ5lcrGP15Eur7DzQ="
|
|
||||||
];
|
|
||||||
matchSets = {
|
|
||||||
certs = true;
|
|
||||||
appdaemon = true;
|
|
||||||
homelab = true;
|
|
||||||
dev = true;
|
|
||||||
tailscale = true;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
# ssh = {
|
||||||
|
# matchSets = {
|
||||||
|
# certs = true;
|
||||||
|
# appdaemon = true;
|
||||||
|
# homelab = true;
|
||||||
|
# dev = true;
|
||||||
|
# tailscale = true;
|
||||||
|
# };
|
||||||
|
# };
|
||||||
|
|
||||||
# This provides the keys at build time and will be included in the nix store
|
# This provides the keys at build time and will be included in the nix store
|
||||||
sops.defaultSopsFile = ../../../keys/secrets.yaml;
|
sops.defaultSopsFile = ../../../keys/secrets.yaml;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
flake.modules.nixos.login-text = { config, lib, ... }:
|
flake.modules.nixos.login-text = { config, lib, ... }:
|
||||||
let
|
let
|
||||||
defaultServiceStatus = {
|
defaultServiceStatus = {
|
||||||
SSH = "sshd.socket";
|
"SSH Socket" = "sshd.socket";
|
||||||
"SSH Cert Renewal" = "ssh-certs-renew.timer";
|
"SSH Cert Renewal" = "ssh-certs-renew.timer";
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
|
|||||||
@@ -15,12 +15,9 @@
|
|||||||
nix.settings.experimental-features = [ "nix-command" "flakes" ];
|
nix.settings.experimental-features = [ "nix-command" "flakes" ];
|
||||||
environment.systemPackages = with pkgs; [
|
environment.systemPackages = with pkgs; [
|
||||||
git
|
git
|
||||||
zsh
|
|
||||||
selfPackages.jsl-zsh-tty
|
selfPackages.jsl-zsh-tty
|
||||||
];
|
];
|
||||||
environment.shells = lib.mkAfter [
|
environment.shells = lib.mkAfter [ rootShellPath ];
|
||||||
rootShellPath
|
|
||||||
];
|
|
||||||
users.users.root.shell = lib.mkForce rootShellPath;
|
users.users.root.shell = lib.mkForce rootShellPath;
|
||||||
|
|
||||||
# security.sudo-rs.enable = true;
|
# security.sudo-rs.enable = true;
|
||||||
|
|||||||
@@ -16,5 +16,9 @@
|
|||||||
[[ssh-keys]]
|
[[ssh-keys]]
|
||||||
vault = "Private"
|
vault = "Private"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
programs.ssh.settings."*" = {
|
||||||
|
IdentityAgent = "${config.home.homeDirectory}/.1password/agent.sock";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,10 @@ in
|
|||||||
|
|
||||||
config =
|
config =
|
||||||
let
|
let
|
||||||
|
identityFile = config.ssh-new.keyFile;
|
||||||
my-sops = (inputs.self.wrappers.mySops.apply {
|
my-sops = (inputs.self.wrappers.mySops.apply {
|
||||||
inherit pkgs;
|
inherit pkgs;
|
||||||
sshKey = config.ssh.identityFile;
|
sshKey = identityFile;
|
||||||
}).wrapper;
|
}).wrapper;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
@@ -46,7 +47,7 @@ in
|
|||||||
sops = {
|
sops = {
|
||||||
defaultSopsFile = ../../keys/secrets.yaml;
|
defaultSopsFile = ../../keys/secrets.yaml;
|
||||||
defaultSopsFormat = "yaml";
|
defaultSopsFormat = "yaml";
|
||||||
age.sshKeyPaths = [ "${config.ssh.identityFile}" ];
|
age.sshKeyPaths = [ identityFile ];
|
||||||
};
|
};
|
||||||
|
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
|
|||||||
@@ -1,249 +0,0 @@
|
|||||||
{ inputs, ... }:
|
|
||||||
let
|
|
||||||
userName = "john";
|
|
||||||
sshHostCAPubKeyPath = ../hosts/janus/ssh_host_ca_key.pub;
|
|
||||||
in
|
|
||||||
{
|
|
||||||
flake.modules.nixos.ssh = { config, pkgs, lib, ... }:
|
|
||||||
let
|
|
||||||
cfg = config.ssh;
|
|
||||||
configDir = "/etc/ssh";
|
|
||||||
sshHostCAPubKey = lib.removeSuffix "\n" (builtins.readFile sshHostCAPubKeyPath);
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options.ssh = {
|
|
||||||
hostKey = lib.mkOption {
|
|
||||||
description = "String path to the host private key file";
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "ssh_host_ed25519_key";
|
|
||||||
};
|
|
||||||
hostKeyType = lib.mkOption {
|
|
||||||
description = "OpenSSH host key type for ssh.hostKey.";
|
|
||||||
type = lib.types.enum [ "ed25519" "rsa" "ecdsa" ];
|
|
||||||
default = "ed25519";
|
|
||||||
};
|
|
||||||
fallbackHostKeys = lib.mkOption {
|
|
||||||
description = "Additional non-certificate host keys that keep sshd reachable during certificate bootstrap.";
|
|
||||||
type = with lib.types; listOf (submodule {
|
|
||||||
options = {
|
|
||||||
path = lib.mkOption {
|
|
||||||
description = "Path to the host private key file.";
|
|
||||||
type = str;
|
|
||||||
};
|
|
||||||
type = lib.mkOption {
|
|
||||||
description = "OpenSSH host key type.";
|
|
||||||
type = enum [ "ed25519" "rsa" "ecdsa" ];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
});
|
|
||||||
default = [
|
|
||||||
{
|
|
||||||
path = "${configDir}/ssh_host_rsa_key";
|
|
||||||
type = "rsa";
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
|
||||||
certificates = {
|
|
||||||
enable = lib.mkEnableOption "Enable SSH host certificates";
|
|
||||||
userCA = lib.mkOption {
|
|
||||||
description = "Content for the SSH user CA file (public key)";
|
|
||||||
type = lib.types.path;
|
|
||||||
default = sshHostCAPubKeyPath;
|
|
||||||
};
|
|
||||||
userCAFile = lib.mkOption {
|
|
||||||
description = "String path to the SSh user CA";
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "ssh_user_ca_key.pub";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = {
|
|
||||||
services.openssh = {
|
|
||||||
enable = true;
|
|
||||||
hostKeys = cfg.fallbackHostKeys ++ [
|
|
||||||
{
|
|
||||||
path = "${configDir}/${cfg.hostKey}";
|
|
||||||
type = cfg.hostKeyType;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
# require public key authentication for better security
|
|
||||||
settings = lib.mkMerge [
|
|
||||||
{
|
|
||||||
PasswordAuthentication = false;
|
|
||||||
KbdInteractiveAuthentication = false;
|
|
||||||
}
|
|
||||||
(lib.mkIf cfg.certificates.enable {
|
|
||||||
TrustedUserCAKeys = "${configDir}/${cfg.certificates.userCAFile}";
|
|
||||||
HostCertificate = "${configDir}/${cfg.hostKey}-cert.pub";
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
|
||||||
|
|
||||||
environment.etc."ssh/${cfg.certificates.userCAFile}" = lib.mkIf cfg.certificates.enable {
|
|
||||||
source = cfg.certificates.userCA;
|
|
||||||
};
|
|
||||||
|
|
||||||
programs.ssh.knownHosts = lib.mkIf cfg.certificates.enable {
|
|
||||||
"192.168.1.*" = {
|
|
||||||
certAuthority = true;
|
|
||||||
publicKey = sshHostCAPubKey;
|
|
||||||
};
|
|
||||||
"*.john-stream.com" = {
|
|
||||||
certAuthority = true;
|
|
||||||
publicKey = sshHostCAPubKey;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
flake.modules.homeManager.ssh = { config, pkgs, lib, ... }:
|
|
||||||
let
|
|
||||||
cfg = config.ssh;
|
|
||||||
configDir = "${config.home.homeDirectory}/.ssh";
|
|
||||||
identityFile = cfg.identityFile;
|
|
||||||
publicKeyFile = "${identityFile}.pub";
|
|
||||||
certificateFile = "${identityFile}-cert.pub";
|
|
||||||
sshHostCAPubKey = lib.removeSuffix "\n" (builtins.readFile sshHostCAPubKeyPath);
|
|
||||||
in
|
|
||||||
{
|
|
||||||
options.ssh = with lib; {
|
|
||||||
identityFile = mkOption {
|
|
||||||
# Intentionally not using a path type here because that will end up with the private key getting copied into the store
|
|
||||||
type = types.str;
|
|
||||||
default = "${config.home.homeDirectory}/.ssh/id_ed25519";
|
|
||||||
description = "Path to the SSH identity file.";
|
|
||||||
};
|
|
||||||
|
|
||||||
certificates = {
|
|
||||||
enable = mkEnableOption "Enable SSH client certificates";
|
|
||||||
};
|
|
||||||
|
|
||||||
knownHostsFile = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = "${configDir}/known_hosts";
|
|
||||||
};
|
|
||||||
|
|
||||||
knownHosts = mkOption {
|
|
||||||
description = "";
|
|
||||||
type = types.listOf types.str;
|
|
||||||
default = [ ];
|
|
||||||
};
|
|
||||||
|
|
||||||
matchSets = {
|
|
||||||
appdaemon = mkEnableOption "Enable AppDaemon SSH targets";
|
|
||||||
certs = mkEnableOption "Enable Janus and Soteria SSH targets";
|
|
||||||
homelab = mkEnableOption "Enable various Homelab targets";
|
|
||||||
dev = mkEnableOption "Enable development targets";
|
|
||||||
tailscale = mkEnableOption "Enable tailscale targets";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = {
|
|
||||||
home.file.".ssh/known_hosts" = {
|
|
||||||
text = lib.concatStringsSep "\n" (
|
|
||||||
cfg.knownHosts ++ lib.optionals cfg.certificates.enable [
|
|
||||||
"@cert-authority 192.168.1.* ${sshHostCAPubKey}"
|
|
||||||
"@cert-authority *.john-stream.com ${sshHostCAPubKey}"
|
|
||||||
]
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
programs.ssh = {
|
|
||||||
enable = true;
|
|
||||||
enableDefaultConfig = false;
|
|
||||||
extraConfig = ''
|
|
||||||
SetEnv TERM="xterm-256color"
|
|
||||||
'';
|
|
||||||
|
|
||||||
settings = lib.mkMerge [
|
|
||||||
{
|
|
||||||
"john-pc-ubuntu" = {
|
|
||||||
HostName = "192.168.1.85";
|
|
||||||
};
|
|
||||||
|
|
||||||
"*" = lib.mkMerge [
|
|
||||||
{
|
|
||||||
User = "john";
|
|
||||||
IdentityAgent = "${config.home.homeDirectory}/.1password/agent.sock";
|
|
||||||
|
|
||||||
Compression = false;
|
|
||||||
ServerAliveInterval = 0;
|
|
||||||
ServerAliveCountMax = 3;
|
|
||||||
|
|
||||||
IdentitiesOnly = true;
|
|
||||||
IdentityFile = identityFile;
|
|
||||||
|
|
||||||
HashKnownHosts = false;
|
|
||||||
UserKnownHostsFile = cfg.knownHostsFile;
|
|
||||||
|
|
||||||
AddKeysToAgent = "yes";
|
|
||||||
ForwardAgent = false;
|
|
||||||
}
|
|
||||||
(lib.mkIf cfg.certificates.enable { CertificateFile = certificateFile; })
|
|
||||||
];
|
|
||||||
}
|
|
||||||
(lib.mkIf cfg.matchSets.appdaemon {
|
|
||||||
"appdaemon" = {
|
|
||||||
HostName = "192.168.1.242";
|
|
||||||
User = "appdaemon";
|
|
||||||
};
|
|
||||||
"ad-nix" = {
|
|
||||||
HostName = "192.168.1.201";
|
|
||||||
User = "appdaemon";
|
|
||||||
};
|
|
||||||
})
|
|
||||||
(lib.mkIf cfg.matchSets.certs {
|
|
||||||
"janus" = {
|
|
||||||
HostName = "fded:fb16:653e:25da:be24:11ff:fe6b:4d57";
|
|
||||||
User = "root";
|
|
||||||
};
|
|
||||||
"soteria" = {
|
|
||||||
HostName = "soteria.john-stream.com";
|
|
||||||
User = "john";
|
|
||||||
};
|
|
||||||
})
|
|
||||||
(lib.mkIf cfg.matchSets.homelab {
|
|
||||||
"docs" = {
|
|
||||||
HostName = "192.168.1.110";
|
|
||||||
User = "root";
|
|
||||||
RequestTTY = "force";
|
|
||||||
RemoteCommand = "~/.nix-profile/bin/jsl-zsh";
|
|
||||||
};
|
|
||||||
"gitea" = {
|
|
||||||
HostName = "192.168.1.104";
|
|
||||||
User = "john";
|
|
||||||
};
|
|
||||||
"hermes" = {
|
|
||||||
HostName = "192.168.1.150";
|
|
||||||
User = "root";
|
|
||||||
# Enabling this breaks the ability of Zed to install its remote stuff
|
|
||||||
# RequestTTY = "force";
|
|
||||||
# RemoteCommand = "/root/.nix-profile/bin/jsl-zsh";
|
|
||||||
};
|
|
||||||
"panoptes" = {
|
|
||||||
HostName = "192.168.1.107";
|
|
||||||
User = "panoptes";
|
|
||||||
};
|
|
||||||
})
|
|
||||||
(lib.mkIf cfg.matchSets.dev {
|
|
||||||
"test-nix" = {
|
|
||||||
HostName = "fded:fb16:653e:25da:be24:11ff:fea0:753f";
|
|
||||||
User = "john";
|
|
||||||
RequestTTY = "auto";
|
|
||||||
# RemoteCommand = "/run/current-system/sw/bin/jsl-zsh";
|
|
||||||
};
|
|
||||||
})
|
|
||||||
(lib.mkIf cfg.matchSets.tailscale {
|
|
||||||
"jdl-docker" = {
|
|
||||||
HostName = "jdl-docker.tailcf205.ts.net";
|
|
||||||
User = "john";
|
|
||||||
RequestTTY = "auto";
|
|
||||||
# RemoteCommand = "~/.nix-profile/bin/jsl-zsh";
|
|
||||||
};
|
|
||||||
})
|
|
||||||
];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
@@ -2,41 +2,33 @@
|
|||||||
flake.modules.nixos.ssh-certs = { config, pkgs, lib, ... }:
|
flake.modules.nixos.ssh-certs = { config, pkgs, lib, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.ssh-certs;
|
cfg = config.ssh-certs;
|
||||||
provisionerPasswordPath = config.sops.secrets."janus/admin_jwk".path;
|
wrappers = inputs.self.wrappers;
|
||||||
sshKeyPath = "/etc/ssh/ssh_host_ed25519_key";
|
sshKeyPath = "/etc/ssh/ssh_host_ed25519_key";
|
||||||
sshCertPath = "${sshKeyPath}-cert.pub";
|
sshCertPath = "${sshKeyPath}-cert.pub";
|
||||||
mkPrincipalArgs = principals:
|
|
||||||
lib.concatMapStringsSep " " (principal: ''--principal "${principal}"'') principals;
|
|
||||||
principalArgs = mkPrincipalArgs ([
|
|
||||||
cfg.hostname
|
|
||||||
"${cfg.hostname}.john-stream.com"
|
|
||||||
] ++ cfg.extraPrincipals);
|
|
||||||
sshHostCertRenew = pkgs.writeShellScriptBin "ssh-host-cert-renew" ''
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
if [ ! -s "${sshKeyPath}.pub" ]; then
|
sshHostCertSign = (wrappers.signHostWrapper.apply {
|
||||||
${lib.getExe' pkgs.openssh "ssh-keygen"} -y -f "${sshKeyPath}" > "${sshKeyPath}.pub"
|
inherit pkgs;
|
||||||
chmod 0644 "${sshKeyPath}.pub"
|
inherit (cfg) provisioner extraPrincipals;
|
||||||
fi
|
provisionerPasswordFile = config.sops.secrets."janus/admin_jwk".path;
|
||||||
|
}).wrapper;
|
||||||
${lib.getExe pkgs.step-cli} ssh certificate \
|
sshHostCertRenew = (wrappers.renewHostWrapper.apply {
|
||||||
--host --sign \
|
inherit pkgs;
|
||||||
--provisioner "${cfg.provisioner}" \
|
sshHostKeyFile = sshKeyPath;
|
||||||
--provisioner-password-file "${provisionerPasswordPath}" \
|
overwrite = true;
|
||||||
${principalArgs} \
|
}).wrapper;
|
||||||
"${cfg.hostname}" "${sshKeyPath}.pub"
|
sshHostCertCheck = (wrappers.hostCheckWrapper.apply {
|
||||||
'';
|
inherit pkgs;
|
||||||
sshHostCertCheck = pkgs.writeShellScriptBin "ssh-host-cert-check" ''
|
certPath = sshCertPath;
|
||||||
${lib.getExe' pkgs.openssh "ssh-keygen"} -Lf ${sshCertPath}
|
}).wrapper;
|
||||||
'';
|
sshHostRenewalCheck = (wrappers.renewalCheck.apply {
|
||||||
|
inherit pkgs;
|
||||||
|
certPath = sshCertPath;
|
||||||
|
expires-in = "4h";
|
||||||
|
}).wrapper;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
# NixOS Options
|
# NixOS Options
|
||||||
options.ssh-certs = {
|
options.ssh-certs = {
|
||||||
hostname = lib.mkOption {
|
|
||||||
description = "Networking host name to register with the CA";
|
|
||||||
type = lib.types.str;
|
|
||||||
};
|
|
||||||
provisioner = lib.mkOption {
|
provisioner = lib.mkOption {
|
||||||
description = "Provisioner inside Step CA to use for the SSH certificates";
|
description = "Provisioner inside Step CA to use for the SSH certificates";
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
@@ -64,59 +56,30 @@
|
|||||||
networking.nameservers = [ "192.168.1.150" ];
|
networking.nameservers = [ "192.168.1.150" ];
|
||||||
networking.dhcpcd.extraConfig = "nohook resolv.conf";
|
networking.dhcpcd.extraConfig = "nohook resolv.conf";
|
||||||
environment.systemPackages = [
|
environment.systemPackages = [
|
||||||
|
sshHostCertSign
|
||||||
sshHostCertRenew
|
sshHostCertRenew
|
||||||
|
sshHostRenewalCheck
|
||||||
sshHostCertCheck
|
sshHostCertCheck
|
||||||
];
|
];
|
||||||
|
|
||||||
systemd.services.ssh-certs-renew = {
|
systemd.services.ssh-certs-renew = {
|
||||||
description = "Renew Step SSH host certificate if needed";
|
description = "SSH host certificate renewal";
|
||||||
wantedBy = [ "multi-user.target" ];
|
wantedBy = [ "multi-user.target" ];
|
||||||
before = [ "sshd.service" ];
|
|
||||||
after = [ "network-online.target" ];
|
after = [ "network-online.target" ];
|
||||||
wants = [ "network-online.target" ];
|
wants = [ "network-online.target" ];
|
||||||
path = with pkgs; [ coreutils systemd step-cli openssh ];
|
path = with pkgs; [ step-cli systemd ];
|
||||||
serviceConfig = {
|
serviceConfig = {
|
||||||
Type = "oneshot";
|
Type = "oneshot";
|
||||||
User = "root";
|
User = "root";
|
||||||
Group = "root";
|
Group = "root";
|
||||||
|
ExecCondition = lib.getExe sshHostRenewalCheck;
|
||||||
|
ExecStart = lib.getExe sshHostCertRenew;
|
||||||
};
|
};
|
||||||
script = ''
|
|
||||||
set -euo pipefail
|
|
||||||
|
|
||||||
renew=0
|
|
||||||
if [ ! -s "${sshCertPath}" ]; then
|
|
||||||
echo "SSH host cert missing: ${sshCertPath}"
|
|
||||||
renew=1
|
|
||||||
elif ${lib.getExe pkgs.step-cli} ssh needs-renewal "${sshCertPath}" --expires-in "4h"; then
|
|
||||||
echo "SSH host cert needs renewal"
|
|
||||||
renew=1
|
|
||||||
else
|
|
||||||
rc=$?
|
|
||||||
if [ "$rc" -eq 1 ]; then
|
|
||||||
echo "SSH host cert does not need renewal"
|
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$rc" -eq 2 ]; then
|
|
||||||
echo "SSH host cert missing or unreadable: ${sshCertPath}"
|
|
||||||
renew=1
|
|
||||||
else
|
|
||||||
echo "step ssh needs-renewal failed with rc=$rc" >&2
|
|
||||||
exit "$rc"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "$renew" -eq 1 ]; then
|
|
||||||
${lib.getExe sshHostCertRenew}
|
|
||||||
${lib.getExe sshHostCertCheck}
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.timers.ssh-certs-renew = {
|
systemd.timers.ssh-certs-renew = {
|
||||||
description = "Periodic Step SSH host certificate renewal";
|
description = "Periodic Step SSH host certificate renewal";
|
||||||
wantedBy = [ "timers.target" ];
|
wantedBy = [ "timers.target" ];
|
||||||
|
|
||||||
timerConfig = {
|
timerConfig = {
|
||||||
OnBootSec = "5m";
|
OnBootSec = "5m";
|
||||||
OnUnitActiveSec = "4h";
|
OnUnitActiveSec = "4h";
|
||||||
@@ -125,10 +88,6 @@
|
|||||||
Unit = "ssh-certs-renew.service";
|
Unit = "ssh-certs-renew.service";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
# Ensure sshd waits for a cert reconciliation attempt at boot.
|
|
||||||
systemd.services.sshd.wants = [ "ssh-certs-renew.service" ];
|
|
||||||
systemd.services.sshd.after = [ "ssh-certs-renew.service" ];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -36,10 +36,10 @@ in
|
|||||||
selfPkgs = inputs.self.packages.${pkgs.stdenv.hostPlatform.system};
|
selfPkgs = inputs.self.packages.${pkgs.stdenv.hostPlatform.system};
|
||||||
in {
|
in {
|
||||||
home.stateVersion = "25.11";
|
home.stateVersion = "25.11";
|
||||||
imports = [
|
imports = with inputs.self.modules.homeManager; [
|
||||||
inputs.self.modules.homeManager.shell-tools
|
ssh-new
|
||||||
inputs.self.modules.homeManager.ssh
|
shell-tools
|
||||||
inputs.self.modules.homeManager.git
|
git
|
||||||
];
|
];
|
||||||
xdg.enable = true;
|
xdg.enable = true;
|
||||||
home.packages = [
|
home.packages = [
|
||||||
|
|||||||
Reference in New Issue
Block a user