WIP CA bootstrap rework
This commit is contained in:
@@ -2,9 +2,16 @@
|
|||||||
let
|
let
|
||||||
username = "john";
|
username = "john";
|
||||||
hostname = "janus";
|
hostname = "janus";
|
||||||
caURL = "https://janus.john-stream.com/";
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
|
flake.modules.homeManager.janus-ca = { config, ... }: {
|
||||||
|
home.file.".step/config/defaults.json".text = builtins.toJSON {
|
||||||
|
"ca-url" = "https://janus.john-stream.com/";
|
||||||
|
fingerprint = "2036c44f7b5901566ff7611ea6c927291ecc6d2dd00779c0eead70ec77fa10d6";
|
||||||
|
root = (builtins.readFile ./root_ca.crt);
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
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
|
||||||
@@ -20,12 +27,10 @@ in
|
|||||||
networking.hostName = hostname;
|
networking.hostName = hostname;
|
||||||
step-ssh-host = {
|
step-ssh-host = {
|
||||||
hostname = hostname;
|
hostname = hostname;
|
||||||
caURL = caURL;
|
|
||||||
};
|
};
|
||||||
mtls = {
|
mtls = {
|
||||||
enable = true;
|
enable = true;
|
||||||
subject = hostname;
|
subject = hostname;
|
||||||
caURL = caURL;
|
|
||||||
san = [
|
san = [
|
||||||
"${hostname}.john-stream.com"
|
"${hostname}.john-stream.com"
|
||||||
"192.168.1.244"
|
"192.168.1.244"
|
||||||
@@ -36,6 +41,7 @@ in
|
|||||||
imports = with inputs.self.modules.homeManager; [
|
imports = with inputs.self.modules.homeManager; [
|
||||||
sops
|
sops
|
||||||
step-ssh-user
|
step-ssh-user
|
||||||
|
janus-ca
|
||||||
];
|
];
|
||||||
|
|
||||||
shell.program = "zsh";
|
shell.program = "zsh";
|
||||||
@@ -19,6 +19,7 @@ in
|
|||||||
rebuild
|
rebuild
|
||||||
john
|
john
|
||||||
mysops
|
mysops
|
||||||
|
janus-ca
|
||||||
step-ssh-user
|
step-ssh-user
|
||||||
mtls
|
mtls
|
||||||
restic
|
restic
|
||||||
@@ -91,10 +92,6 @@ in
|
|||||||
mtls = {
|
mtls = {
|
||||||
enable = true;
|
enable = true;
|
||||||
subject = hostname;
|
subject = hostname;
|
||||||
ca = {
|
|
||||||
url = "https://janus.john-stream.com/";
|
|
||||||
fingerprint = "2036c44f7b5901566ff7611ea6c927291ecc6d2dd00779c0eead70ec77fa10d6";
|
|
||||||
};
|
|
||||||
san = [
|
san = [
|
||||||
"${hostname}"
|
"${hostname}"
|
||||||
"192.168.1.85"
|
"192.168.1.85"
|
||||||
@@ -24,7 +24,6 @@ in
|
|||||||
];
|
];
|
||||||
step-ssh-host = {
|
step-ssh-host = {
|
||||||
hostname = hostname;
|
hostname = hostname;
|
||||||
caURL = caURL;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
home-manager.users."${username}" = {
|
home-manager.users."${username}" = {
|
||||||
@@ -40,6 +39,7 @@ in
|
|||||||
imports = with inputs.self.modules; [
|
imports = with inputs.self.modules; [
|
||||||
homeManager.rebuild
|
homeManager.rebuild
|
||||||
homeManager.mysops
|
homeManager.mysops
|
||||||
|
homeManager.janus-ca
|
||||||
homeManager.mtls
|
homeManager.mtls
|
||||||
homeManager.docker
|
homeManager.docker
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -17,10 +17,6 @@ in
|
|||||||
{
|
{
|
||||||
options.step-ssh-user = {
|
options.step-ssh-user = {
|
||||||
enable = lib.mkEnableOption "opionated step client config for SSH certs";
|
enable = lib.mkEnableOption "opionated step client config for SSH certs";
|
||||||
caURL = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
default = "${caURL}";
|
|
||||||
};
|
|
||||||
fingerprint = lib.mkOption {
|
fingerprint = lib.mkOption {
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
default = "${stepFingerprint}";
|
default = "${stepFingerprint}";
|
||||||
@@ -48,11 +44,6 @@ in
|
|||||||
};
|
};
|
||||||
config = lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
home.file."${cfg.rootCertFile.path}".source = cfg.rootCertFile.source;
|
home.file."${cfg.rootCertFile.path}".source = cfg.rootCertFile.source;
|
||||||
home.file.".step/config/defaults.json".text = builtins.toJSON {
|
|
||||||
"ca-url" = cfg.caURL;
|
|
||||||
fingerprint = cfg.fingerprint;
|
|
||||||
root = "${config.home.homeDirectory}/${cfg.rootCertFile.path}";
|
|
||||||
};
|
|
||||||
sops.secrets."janus/admin_jwk".mode = "0400";
|
sops.secrets."janus/admin_jwk".mode = "0400";
|
||||||
home.packages = with pkgs; [
|
home.packages = with pkgs; [
|
||||||
(writeShellScriptBin "sign-ssh-cert" ''
|
(writeShellScriptBin "sign-ssh-cert" ''
|
||||||
|
|||||||
@@ -3,14 +3,6 @@ let
|
|||||||
# Options that will be in common between
|
# Options that will be in common between
|
||||||
opts = {
|
opts = {
|
||||||
enable = lib.mkEnableOption "Enable mTLS";
|
enable = lib.mkEnableOption "Enable mTLS";
|
||||||
ca = {
|
|
||||||
url = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
};
|
|
||||||
fingerprint = lib.mkOption {
|
|
||||||
type = lib.types.str;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
subject = lib.mkOption {
|
subject = lib.mkOption {
|
||||||
description = "The Common Name, DNS Name, or IP address that will be set as the Subject Common Name for the certificate. If no Subject Alternative Names (SANs) are configured (via the --san flag) then the subject will be set as the only SAN.";
|
description = "The Common Name, DNS Name, or IP address that will be set as the Subject Common Name for the certificate. If no Subject Alternative Names (SANs) are configured (via the --san flag) then the subject will be set as the only SAN.";
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
@@ -221,7 +213,6 @@ in
|
|||||||
tlsKey = "${certDir}/${cfg.keyFilename}";
|
tlsKey = "${certDir}/${cfg.keyFilename}";
|
||||||
tlsCert = "${certDir}/${cfg.certFilename}";
|
tlsCert = "${certDir}/${cfg.certFilename}";
|
||||||
mtlsBundle = "${certDir}/${cfg.bundleFilename}";
|
mtlsBundle = "${certDir}/${cfg.bundleFilename}";
|
||||||
rootCA = "${certDir}/root_ca.crt";
|
|
||||||
sanArgs = lib.concatMapStringsSep " " (san: "--san \"${san}\"") cfg.san;
|
sanArgs = lib.concatMapStringsSep " " (san: "--san \"${san}\"") cfg.san;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
@@ -264,7 +255,6 @@ in
|
|||||||
tlsKey = "${certDir}/${cfg.keyFilename}";
|
tlsKey = "${certDir}/${cfg.keyFilename}";
|
||||||
tlsCert = "${certDir}/${cfg.certFilename}";
|
tlsCert = "${certDir}/${cfg.certFilename}";
|
||||||
mtlsBundle = "${certDir}/${cfg.bundleFilename}";
|
mtlsBundle = "${certDir}/${cfg.bundleFilename}";
|
||||||
rootCA = "${certDir}/root_ca.crt";
|
|
||||||
sanArgs = lib.concatMapStringsSep " " (san: "--san \"${san}\"") cfg.san;
|
sanArgs = lib.concatMapStringsSep " " (san: "--san \"${san}\"") cfg.san;
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
@@ -277,12 +267,6 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home.file.".step/config/defaults.json".text = builtins.toJSON {
|
|
||||||
"ca-url" = cfg.ca.url;
|
|
||||||
fingerprint = cfg.ca.fingerprint;
|
|
||||||
root = "${cfg.certDir}/root_ca.crt";
|
|
||||||
};
|
|
||||||
|
|
||||||
home.packages = with pkgs; lib.optionals cfg.enable [
|
home.packages = with pkgs; lib.optionals cfg.enable [
|
||||||
step-cli
|
step-cli
|
||||||
(writeShellScriptBin "mtls-generate" ''
|
(writeShellScriptBin "mtls-generate" ''
|
||||||
|
|||||||
@@ -14,10 +14,6 @@
|
|||||||
description = "Networking host name";
|
description = "Networking host name";
|
||||||
type = lib.types.str;
|
type = lib.types.str;
|
||||||
};
|
};
|
||||||
caURL = lib.mkOption {
|
|
||||||
description = "URL for the certificate authority";
|
|
||||||
type = lib.types.str;
|
|
||||||
};
|
|
||||||
rootCertFile = {
|
rootCertFile = {
|
||||||
path = lib.mkOption {
|
path = lib.mkOption {
|
||||||
description = "String path to where the root_ca.crt file will be stored for the user";
|
description = "String path to where the root_ca.crt file will be stored for the user";
|
||||||
@@ -55,8 +51,6 @@
|
|||||||
(writeShellScriptBin "ssh-host-cert-renew" ''
|
(writeShellScriptBin "ssh-host-cert-renew" ''
|
||||||
${lib.getExe pkgs.step-cli} ssh certificate \
|
${lib.getExe pkgs.step-cli} ssh certificate \
|
||||||
--host --sign \
|
--host --sign \
|
||||||
--root "${rootCertPath}" \
|
|
||||||
--ca-url ${cfg.caURL} \
|
|
||||||
--provisioner "${cfg.provisioner}" \
|
--provisioner "${cfg.provisioner}" \
|
||||||
--provisioner-password-file "${provisionerPasswordPath}" \
|
--provisioner-password-file "${provisionerPasswordPath}" \
|
||||||
--principal "${cfg.hostname}" \
|
--principal "${cfg.hostname}" \
|
||||||
|
|||||||
Reference in New Issue
Block a user