24 Commits
Author SHA1 Message Date
John Lancaster 809b742821 forgejo service tweaks 2026-07-19 10:59:17 -05:00
John Lancaster 1d9566115c flake.lock updates 2026-07-18 13:52:09 -05:00
John Lancaster ac5128bf74 forgejo deployment 2026-07-18 12:21:03 -05:00
John Lancaster 25ecb7ad06 forgejo reactivate 2026-07-10 00:04:34 -05:00
John Lancaster b21bfd6bb4 ssh user certs in home-manager 2026-07-09 09:01:34 -05:00
John Lancaster a0f5783bbc jsl-zsh as default shell 2026-07-09 08:07:25 -05:00
John Lancaster addf175fef WIP 2026-07-07 18:56:29 -05:00
John Lancaster b60b91926a reorg ssh wrappers 2026-07-07 18:25:09 -05:00
John Lancaster 4f9e67208b started optionModules.mtls 2026-07-05 23:58:16 -05:00
John Lancaster 118e1d8f4f silencing warnings 2026-07-05 23:57:12 -05:00
John Lancaster 1b98c83d3f breaking up mtls with better wrappers 2026-07-05 22:59:05 -05:00
John Lancaster 39504cd856 reorg 2026-07-05 20:40:28 -05:00
John Lancaster ca75da7c37 soteria off the ground 2026-07-05 20:29:04 -05:00
John Lancaster 9f1fed071d updates for soteria host 2026-07-05 20:05:02 -05:00
John Lancaster bfbdbae99b name tweak 2026-07-05 19:35:10 -05:00
John Lancaster 9f29907ec3 janus module cleanup 2026-07-05 19:34:51 -05:00
John Lancaster 87821ed109 pruned old ssh module 2026-07-05 19:23:32 -05:00
John Lancaster b37ee5777d some ssh match blocks 2026-07-05 19:11:53 -05:00
John Lancaster 68f40feffb moved 1password agent config 2026-07-05 19:04:48 -05:00
John Lancaster a60d2bcd28 moving to john-pc 2026-07-05 19:01:38 -05:00
John Lancaster dc89592eb1 started new ssh module with janus 2026-07-05 18:21:52 -05:00
John Lancaster fa29ce93f4 reorg 2026-07-05 11:26:36 -05:00
John Lancaster 73f5df1832 WIP SSH cert wrappers 2026-07-05 11:16:20 -05:00
John Lancaster 225020eb8d check wrappers 2026-07-05 08:56:32 -05:00
33 changed files with 1218 additions and 1277 deletions
+3 -3
View File
@@ -2,10 +2,10 @@ keys:
- &john-p14s age1f6drjusg866yscj8029tk4yfpgecklrvezldm02ankm6h8nnwu5s2u6ahy
- &john-pc age1ykcs39e62pz3xu6cedg8ea685kv5d5qsrhgkndygzm8rx30xd5ys5t3qxt
- &test-nix age1gvplss0ddmyf6vpjy363wu3n057vhm0j6n7tc94cxd8kadapypws5mtaj0
- &soteria age1h0prahyukq4l564yqwgcpg3g6gdrjflk0suklussjjrjstxd9uesws8633
- &soteria age1p4gyh5260ewp7t2ctzv5ewj4a06szl389fm4gzy6vltxhjj73ers87u33g
- &janus age1qahhlzeanprtykym9jymk2t95uedr7cwx9sdshx46q2m6u66fucsqua8l3
creation_rules:
- path_regex: modules/hosts/janus/secrets\.yaml$
- path_regex: janus/secrets\.yaml$
key_groups:
- age:
- *janus
@@ -22,8 +22,8 @@ creation_rules:
- path_regex: soteria/secrets\.yaml$
key_groups:
- age:
- *john-pc
- *soteria
- *john-pc
- *test-nix
- path_regex: john-p14s/secrets\.yaml$
key_groups:
Generated
+26 -64
View File
@@ -18,11 +18,11 @@
},
"flake-file": {
"locked": {
"lastModified": 1781217157,
"narHash": "sha256-N3q/SP2Ropk336e9KSgLh7kpROY6P70dprYdbPIfd5c=",
"lastModified": 1784255282,
"narHash": "sha256-srM+PTqxfyvbQ0BevsOtP8vQv/Ox6OMtY4DktoDxLKg=",
"owner": "vic",
"repo": "flake-file",
"rev": "ce63eaf7ebfe04a176653f66385a7f0a36380cee",
"rev": "66ddd2f69a5c4677f0095c6f70eea1217dc45749",
"type": "github"
},
"original": {
@@ -51,27 +51,6 @@
"type": "github"
}
},
"flake-parts_2": {
"inputs": {
"nixpkgs-lib": [
"nvf",
"nixpkgs"
]
},
"locked": {
"lastModified": 1778716662,
"narHash": "sha256-m1Yf0wZ8j1OHjTc2UwHwyQRSnNeSgLJOd7q5Y45hzi4=",
"owner": "hercules-ci",
"repo": "flake-parts",
"rev": "f7c1a2d347e4c52d5fb8d10cb4d94b5884e546fb",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "flake-parts",
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
@@ -95,11 +74,11 @@
"nixpkgs": "nixpkgs"
},
"locked": {
"lastModified": 1783134515,
"narHash": "sha256-qMoZazubXlXUD9k/syJ/aiWC4X4g73mwVmZ7Z4+rdpM=",
"lastModified": 1784351324,
"narHash": "sha256-By+kuRJZRqs2TuXgtR8vJ8cTKWXw33YG/Yollu5cO1U=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "b885baad531fa3d3beae2ba9a0712d22974d8016",
"rev": "460108009ca1ff69ca2ff19079ca2c838d6e3080",
"type": "github"
},
"original": {
@@ -110,11 +89,11 @@
},
"import-tree": {
"locked": {
"lastModified": 1778781969,
"narHash": "sha256-Jjuz5CmSkur8KvLDoGa+vylEp+RkQtv4mt/qcMznpH0=",
"lastModified": 1784254960,
"narHash": "sha256-iI88R3wHz8wTKQb5orvpc51L/Xr64AJyxid/0MKa/b8=",
"owner": "vic",
"repo": "import-tree",
"rev": "d321337efd0f23a9eb14a42adb7b2c29313ab274",
"rev": "4ebb10ae17d5f1ad366e7aef5b92cb8eecf24f69",
"type": "github"
},
"original": {
@@ -162,11 +141,11 @@
"nixos-hardware": {
"flake": false,
"locked": {
"lastModified": 1782562157,
"narHash": "sha256-a7+T6QSeowynwZ1ZJJbP8T8ntAytvrui8kFGJmIZt2c=",
"lastModified": 1784310968,
"narHash": "sha256-rkSPTePrKqs4dg+i7ZFCq93+HrClac6oSwXX927SVjA=",
"owner": "NixOS",
"repo": "nixos-hardware",
"rev": "a9cf7546a938c737b079e738de73934a13de9784",
"rev": "779c32a00155994c86cde8213a8dd4df139d4355",
"type": "github"
},
"original": {
@@ -177,11 +156,11 @@
},
"nixpkgs": {
"locked": {
"lastModified": 1782175435,
"narHash": "sha256-EMzXKmnOtBQ2MnvpiNOm7E+kOMvdPrIKaeg52Tip2Uk=",
"lastModified": 1783604885,
"narHash": "sha256-tzMgSkV7kljEkqIjlgV6F+n+xD+/a35Db8bs7a4BFAo=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "89570f24e97e614aa34aa9ab1c927b6578a43775",
"rev": "767b0d3ec98a143ad9ed7dfc0d5553510ac27133",
"type": "github"
},
"original": {
@@ -193,11 +172,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1782948114,
"narHash": "sha256-VGtEDss4T0hPTnlWiiaa29y/lXM9SxuSMVtzPYf3wS0=",
"rev": "9e92285f211dad236540fd617d7e30e0b99bc0e1",
"lastModified": 1784347607,
"narHash": "sha256-oJoPGsmXO7Xm5YagCr0La+dSTu5Lpfx35WN8vNG18BU=",
"rev": "31cd72fdba8fa052e437ce7e6879c4fe62def10f",
"type": "tarball",
"url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1026211.9e92285f211d/nixexprs.tar.xz"
"url": "https://releases.nixos.org/nixpkgs/nixpkgs-26.11pre1036759.31cd72fdba8f/nixexprs.tar.xz"
},
"original": {
"type": "tarball",
@@ -207,19 +186,17 @@
"nvf": {
"inputs": {
"flake-compat": "flake-compat",
"flake-parts": "flake-parts_2",
"mnw": "mnw",
"nixpkgs": [
"nixpkgs"
],
"systems": "systems_2"
]
},
"locked": {
"lastModified": 1783164413,
"narHash": "sha256-7DMamcvS35/tI+KZKXt45bHAq2Vnucl74Xetvp7DR3I=",
"lastModified": 1784320861,
"narHash": "sha256-sPUghbl8wMmESus7KvsmHIUEyD2mi13/xu7/u2H5SZU=",
"owner": "notashelf",
"repo": "nvf",
"rev": "c8386ccfbc7053d454fa2d12d716c6ebb4167d51",
"rev": "43fdcbf2e00290479d3f9b97b7f61edd08c4e584",
"type": "github"
},
"original": {
@@ -278,21 +255,6 @@
"type": "github"
}
},
"systems_2": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"wrapper-modules": {
"inputs": {
"nixpkgs": [
@@ -320,11 +282,11 @@
]
},
"locked": {
"lastModified": 1782375095,
"narHash": "sha256-bRepNpAluz2i0IIk7Tmzw/4BkyOrwABvc66NEgXPEhA=",
"lastModified": 1784213309,
"narHash": "sha256-A9C90KsA6FsRkFPTA1C1sHP13d6AMuGOvsvI7qjHz8g=",
"owner": "lassulus",
"repo": "wrappers",
"rev": "cd780e92c0fa66c2e721e1d91894f3db13b9f2b4",
"rev": "a04c2ee17fb9679198d0a852ad8709bc152dfac2",
"type": "github"
},
"original": {
+26 -26
View File
@@ -11,47 +11,47 @@ sops:
age:
- enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAwWlpYV1o3SVdJdmJ5TWM3
Qmg4WVkvL21aQ2wvMUcxeGIxL2FQRUNOZFhZCkFqT3RtNTZvODJZczVwcEZkMzBp
eFFTVmJLb1ZOQVVVSWl4OVNQWkM4VWcKLS0tIEV4WmhEOGpkUWFBTCtqaldxdXFO
T20rVXNrY0ZBWlBaS0lWdGIrYUFNdm8KL06MsEu0fy6gKX5khZoxaypKDgEEJnTL
hCh4sCmTC3l7vQLv6deWf1Xhc8vSYhhNaWFCZ+KSaUen+6Bm/WrRIg==
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSB5dTVZQ2hFanhqbVJXTmxG
YUFFanBiTzgyek1WZW5YajlaL3hVNElORHpJCm1JN2hxell5dmJVczlBbVI2VktH
Z21lelF6UDBHcXIyUDE0clpxcEV4MGsKLS0tIG0zMktBVEt1SFZ6aGFaNW0wdzlB
QkpQc3lkNmZCd0d6ZVRCc1ZaWjFYaDAK9RXWeW6dCIhYfVGPywsHlRigORVMuVfl
d+Evyp72wV5C1MnhV9jv8O4S8aQkcNae1PALacnFw0GJAI1iXn0bqw==
-----END AGE ENCRYPTED FILE-----
recipient: age1f6drjusg866yscj8029tk4yfpgecklrvezldm02ankm6h8nnwu5s2u6ahy
- enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSAwRGVJTXJtSk9KUFpCdksv
SUJ4YXBSTndhZkVHNlV2TTlyS0MrQXdqOG1jCkk0c3p0ZUlHMzZmR0FTUTMxOTl1
c0dFTW9yZFpuSUdwVUs0dlJiL2d2cFUKLS0tIE1VWldEYmR6cWFoRTkycmllVnpt
TGYxU2J0NzAvMjBMOXVMZEJTYTNkamMK2zfuTeHJ/8I07oNhp3MN1wKlmtVpahke
cz8FVesp/+53HxfQAdnC7l/Cv7P71aVEyr2/oTEd4gt9HsHVVw3O6A==
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBBTWt3MEFDL3JGOUw0LzNa
RmNLMmFRRzh5NEtZWENjNTlrcDg1MHpjWWg0Cjl5THh3ckdyMWVqR0M2Q0Y0czUr
Y0ZNRGVIbS9TNXlCcFo3R3lPZUl4cW8KLS0tIDN4QmhSYjBPMDZLWURhMndsK2hE
WVY1T0JnZ3dmSjNIMDNBYmhMellvMWcKp15FwF7lJnHoZ/tLNQTGvwP7Kffj8hms
6G5ZG2howsNFiRFFdo/uL08ShaycL2PAL/Kge/0pPL1ygiDaDLjGGg==
-----END AGE ENCRYPTED FILE-----
recipient: age1ykcs39e62pz3xu6cedg8ea685kv5d5qsrhgkndygzm8rx30xd5ys5t3qxt
- enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBwR3VEWmZ4REpUN0M5NTRT
U1l1S0k1MnFrYnhRanB4UStOQU0vYXE0TjFZCld2cDBlRXNyRlJWMlZ4TENadURy
cUN0RmpYYld3WlY0TzkyNXlqbFVnKzgKLS0tIHhtSG5VU3RMclMyZFJmbk1DMkV6
elRhVTV6Tk5OTjUybldvUXY3Sk9hdkEKg17Pagk12Pvj6cNr49HN8tImM4w7pnkc
XLCWIHUCe3QpJlgs4USXbyA06PmsNl7PVvCoxmf6tPegt+SFMTuDRQ==
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBwT1FoTDNmRXM4Tk9HZHNu
ZSszMEM1R0Z5bzY1ZzRvR3VGR2srVVdXbDBNCmp2c0tacndoQ3RiZUpNTnk1MTNH
V0Q4ckhWaDBjemYxZEhrSGJHcVlwYzQKLS0tIHNDZkNrNmZvM2plNEp2TTJmVlpT
U1JhN2MrT2NzeURuVzRIZlNEVEd0S0EKBcTG4hWKdXqNfajVZ5DOClOeZsFYktPb
dAauLGwx1zkXbVxopUpH5+vCXp02kvvwgO9kiqJvSf0U+l/5VIp6Ww==
-----END AGE ENCRYPTED FILE-----
recipient: age1gvplss0ddmyf6vpjy363wu3n057vhm0j6n7tc94cxd8kadapypws5mtaj0
- enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBMUUtJWklHTGpLYTJuMkZi
N2YzMlBUU3dxUGZwSUJjRktVYmp4RlowZ0c0CmdWdmFOQndpQWM0a0VOZUtlckhz
SktRclh5ZFZLaCt2RjhIdGU1aUs0c2sKLS0tIGI4UGFUcHhPVis5Z3dhanhiMGwv
OXRWQnNKcU9XRVJRWWdUNTZyZUdETzAKSchzGq3teDdBiyzJEujlxPaoJsVww4JX
3VvsUZLxnV1yWu83X1bp6uZA3YLMdQgPcHezdgmIyixp+ATHh9fgzw==
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA5bTVkK0pQL3kxZzdaN0xq
YU9rVTNvQXE1V1d0Ykx1bEN3cXp4eWdKaWpjCkEzNUs0N1JlMjlrdnA4UUxIRkZ1
aFl2Qk9PeTNTQ0grMjFJMzZvT05adGMKLS0tIEIwd3NyQ0xWWkVBMFl4Z0VUVFBY
eWFlSFYrL1E1aXN2bVp5YTF5VXVOYUEK3NhyHGnY+a/Fj6TJFzljSX+49G9x5F3x
M16Nx7JGsD5IV6GfdiMYSEwgT1pm0/XY8rhvWBO1fArkleMz1HKewg==
-----END AGE ENCRYPTED FILE-----
recipient: age1h0prahyukq4l564yqwgcpg3g6gdrjflk0suklussjjrjstxd9uesws8633
recipient: age1p4gyh5260ewp7t2ctzv5ewj4a06szl389fm4gzy6vltxhjj73ers87u33g
- enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBtOHFwemUyc2pEKzlibVBo
MlI4R0VTMHpwK21MaXZkSUp5dnIwUnVZOFRvCjVsM3FrclFJL0s2a1RwU1F2VXNF
MnRBOVUydFdEWXY3Mk9oTGw5Z05Zb28KLS0tIE9QRFdCVGR1Z0UyeE5KSzgrWnpP
Q25nZWx3bFdlek1OSjJsSk1QREdGRU0K++hDWzoKbBkGkMAkruuEwQKa1Jrc8POs
liN274cEdi1T6nmwBJ05w0alUR2XuYEn9HNKdvz8EntNuKIhCpHing==
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBwWGpwUkRueVhhcVErQ0ZF
RXdxV1lMNzh6VFhubmc3TDBMaSsrYjhlS1Q0CnlZMmJSaXN5d1daRmpUVTlWeU1i
Nkxsd3JoTGpoelhiTXBMclhoL3RKQlEKLS0tIHRyQjk0akN3WnhKKy82T0ZOYTNK
QU5tYkZuTVc2Yzc0bzJrNXd1aWJMVlEKoMHFqDQYmT+q4eSNtmIb6drI/pFt9Z4W
gHI/QxeWQq6BWssk4EAonRXhIE0iJPOsXz2zyT+dRRDqcKBod9h01w==
-----END AGE ENCRYPTED FILE-----
recipient: age1qahhlzeanprtykym9jymk2t95uedr7cwx9sdshx46q2m6u66fucsqua8l3
lastmodified: "2026-03-15T15:06:29Z"
+166 -41
View File
@@ -3,6 +3,18 @@
let
cfg = config.forgejo;
needsPrivilegedPort = cfg.port < 1024;
wrappedForgejo = (inputs.self.wrappers.forgejo.forgejo.apply {
inherit pkgs;
serviceConfig = config.services.forgejo;
}).wrapper;
cleanForgejo = (inputs.self.wrappers.forgejo.clean.apply {
inherit pkgs;
serviceConfig = config.services.forgejo;
}).wrapper;
cleanPostgres = (inputs.self.wrappers.forgejo.clean-postgres.apply {
inherit pkgs;
serviceConfig = config.services.postgresql;
}).wrapper;
in
{
options.forgejo = {
@@ -11,6 +23,23 @@
type = lib.types.str;
};
pocketId = {
enable = lib.mkEnableOption "Configure Pocket ID as a Forgejo OIDC provider";
discoveryUrl = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "https://id.example.com";
description = "OpenID Connect discovery URL for Pocket ID.";
};
name = lib.mkOption {
type = lib.types.str;
default = "pocket-id";
description = "Forgejo external auth source name for Pocket ID.";
};
};
port = lib.mkOption {
type = lib.types.port;
default = 3000;
@@ -27,8 +56,20 @@
};
config = lib.mkIf cfg.enable {
assertions = [
{
assertion = !cfg.pocketId.enable || cfg.pocketId.discoveryUrl != null;
message = "forgejo.pocketId.discoveryUrl must be set when forgejo.pocketId.enable is true.";
}
];
networking.firewall.allowedTCPPorts = lib.optionals cfg.openFirewall [ cfg.port ];
mtls = lib.mkIf cfg.https {
certReaders = lib.mkAfter [ config.services.forgejo.user ];
renew.reloadUnits = lib.mkAfter [ "forgejo.service" ];
};
systemd.services.forgejo.serviceConfig = lib.mkIf needsPrivilegedPort {
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
@@ -40,6 +81,9 @@
"forgejo/internal_token".owner = config.services.forgejo.user;
"forgejo/jwt_secret".owner = config.services.forgejo.user;
"forgejo/lfs_jwt_secret".owner = config.services.forgejo.user;
} // lib.optionalAttrs cfg.pocketId.enable {
"forgejo/pocket_id/client_id".owner = config.services.forgejo.user;
"forgejo/pocket_id/client_secret".owner = config.services.forgejo.user;
};
services = {
@@ -48,9 +92,7 @@
lfs.enable = true;
database.type = "postgres";
settings = {
DEFAULT = {
RUN_MODE = "dev";
};
DEFAULT.RUN_MODE = "dev";
server = lib.mkMerge [
{
HTTP_PORT = cfg.port;
@@ -71,13 +113,9 @@
ACCOUNT_LINKING = "login";
REGISTER_EMAIL_CONFIRM = false;
};
repository = {
ENABLE_PUSH_CREATE_USER = true;
};
repository.ENABLE_PUSH_CREATE_USER = true;
ui.SHOW_USER_EMAIL = false;
markup = {
ENABLED = true;
};
markup.ENABLED = true;
};
secrets = {
@@ -109,39 +147,126 @@
--work-path ${config.services.forgejo.dump.backupDir}
'';
environment.systemPackages =
let
systemctl = lib.getExe' pkgs.systemd "systemctl";
clean-forgejo = (pkgs.writeShellScriptBin "clean-forgejo" ''
set -euo pipefail
sudo ${systemctl} stop forgejo.service
${lib.getExe' pkgs.coreutils "echo"} "Stopped Forgejo"
sudo ${lib.getExe' pkgs.coreutils "rm"} -rf ${config.services.forgejo.stateDir}
${lib.getExe' pkgs.coreutils "echo"} "Removed ${config.services.forgejo.stateDir}"
'');
clean-postgres = (pkgs.writeShellScriptBin "clean-postgres" ''
set -euo pipefail
sudo ${systemctl} stop postgresql.service
${lib.getExe' pkgs.coreutils "echo"} "Stopped PostgreSQL"
sudo ${lib.getExe' pkgs.coreutils "rm"} -rf ${config.services.postgresql.dataDir}
${lib.getExe' pkgs.coreutils "echo"} "Removed ${config.services.postgresql.dataDir}"
'');
in [
clean-forgejo
clean-postgres
(pkgs.writeShellScriptBin "clean-all" ''
set -euo pipefail
GREEN_CHECK="\e[32m\e[0m"
YELLOW_BANG="\e[33m!\e[0m"
${lib.getExe' pkgs.coreutils "echo"} -n -e "$YELLOW_BANG Remove everything related to Forgejo and the PostgreSQL database behind it?"
read -p " (y/n) " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
${lib.getExe clean-forgejo}
${lib.getExe clean-postgres}
${lib.getExe' pkgs.coreutils "echo"} -e "$GREEN_CHECK Removed everything related to forgejo"
fi
'')
systemd.services.forgejo-pocket-id-oidc = lib.mkIf cfg.pocketId.enable {
description = "Ensure Pocket ID OIDC auth source exists in Forgejo";
after = [ "forgejo.service" "network-online.target" ];
wants = [ "network-online.target" ];
requires = [ "forgejo.service" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
User = config.services.forgejo.user;
Group = config.services.forgejo.group;
WorkingDirectory = config.services.forgejo.stateDir;
Restart = "on-failure";
RestartSec = "30s";
StartLimitIntervalSec = 0;
};
script = ''
set -euo pipefail
client_id="$(<${config.sops.secrets."forgejo/pocket_id/client_id".path})"
client_secret="$(<${config.sops.secrets."forgejo/pocket_id/client_secret".path})"
provider_name="${cfg.pocketId.name}"
forgejo_bin="${lib.getExe wrappedForgejo}"
auth_id="$(
"$forgejo_bin" admin auth list \
| ${lib.getExe' pkgs.gawk "awk"} '$2 == "'"$provider_name"'" { print $1; exit }'
)"
if [ -n "$auth_id" ]; then
"$forgejo_bin" admin auth update-oauth \
--id "$auth_id" \
--name "$provider_name" \
--provider openidConnect \
--key "$client_id" \
--secret "$client_secret" \
--auto-discover-url "${cfg.pocketId.discoveryUrl}" \
--scopes openid \
--scopes profile \
--scopes email
else
"$forgejo_bin" admin auth add-oauth \
--name "$provider_name" \
--provider openidConnect \
--key "$client_id" \
--secret "$client_secret" \
--auto-discover-url "${cfg.pocketId.discoveryUrl}" \
--scopes openid \
--scopes profile \
--scopes email
fi
'';
};
environment.systemPackages = [
wrappedForgejo
cleanForgejo
cleanPostgres
];
};
};
flake.wrappers.forgejo = {
forgejo = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
options = {
serviceConfig = lib.mkOption { type = lib.types.attrs; };
};
config = let
cfg = config.serviceConfig;
forgejo_config="${cfg.customDir}/conf/app.ini";
forgejo_work_path="${cfg.stateDir}";
in {
binName = "my-forgejo";
package = cfg.package;
args = [
"--config" forgejo_config
"--work-path" forgejo_work_path
];
};
});
clean = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
options = {
serviceConfig = lib.mkOption { type = lib.types.attrs; };
};
config = let
cfg = config.serviceConfig;
pkgs = config.pkgs;
in {
binName = "forgejo-clean";
package = pkgs.coreutils;
exePath = lib.getExe' pkgs.coreutils "rm";
extraPackages = [ pkgs.systemd ];
preHook = ''
sudo systemctl stop forgejo.service
echo "Stopped Forgejo"
'';
args = [ "-rf" cfg.stateDir ];
postHook = ''echo "Removed ${cfg.stateDir}"'';
};
});
clean-postgres = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
options = {
serviceConfig = lib.mkOption { type = lib.types.attrs; };
};
config = let
cfg = config.serviceConfig;
pkgs = config.pkgs;
in {
binName = "postgres-clean";
package = pkgs.coreutils;
exePath = lib.getExe' pkgs.coreutils "rm";
extraPackages = [ pkgs.systemd ];
preHook = ''
sudo systemctl stop postgresql.service
echo "Stopped Postgres"
'';
args = [ "-rf" cfg.dataDir ];
postHook = ''echo "Removed ${cfg.dataDir}"'';
};
});
};
}
-504
View File
@@ -1,504 +0,0 @@
{ self, inputs, lib, ... }:
let
# Options that will be in common between the nixos module and the home-manager module.
mkOpts = config: let cfg = config.mtls; in {
enable = lib.mkEnableOption "Enable mTLS";
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.";
type = lib.types.str;
};
certDir = lib.mkOption {
description = "String path to the directory where the certs will be stored";
type = lib.types.str;
};
caFile = lib.mkOption {
description = "String path for the root CA file";
type = lib.types.str;
default = "${cfg.certDir}/root_ca.crt";
};
keyFile = lib.mkOption {
description = "String path for the private key";
type = lib.types.str;
default = "${cfg.certDir}/key.pem";
};
certFile = lib.mkOption {
description = "String path for the public cert";
type = lib.types.str;
default = "${cfg.certDir}/cert.pem";
};
bundleFile = lib.mkOption {
description = "String path for the mTLS key bundle";
type = lib.types.str;
default = "${cfg.certDir}/mtls.pem";
};
san = lib.mkOption {
description = "List of SAN to give the mTLS cert";
type = lib.types.listOf lib.types.str;
default = [ ];
};
provisioner = lib.mkOption {
type = lib.types.str;
default = "admin";
};
lifetime = lib.mkOption {
type = lib.types.str;
default = "24h";
};
renew = {
enable = lib.mkOption {
description = "Enable automatic mTLS certificate renewal using a systemd timer.";
type = lib.types.bool;
default = cfg.enable;
};
onCalendar = lib.mkOption {
description = "systemd OnCalendar schedule for mTLS certificate renewal checks.";
type = lib.types.str;
default = "*:1/15";
};
randomizedDelaySec = lib.mkOption {
description = "Randomized delay added to renewal timer runs to avoid synchronized renewals.";
type = lib.types.str;
default = "5m";
};
user = lib.mkOption {
description = "User account to run the mTLS renewal service as.";
type = lib.types.str;
default = "root";
};
group = lib.mkOption {
description = "Group to run the mTLS renewal service as. Defaults to the configured renewal user.";
type = lib.types.nullOr lib.types.str;
default = "mtls";
};
reloadUnits = lib.mkOption {
description = "systemd units to try-reload-or-restart after a successful certificate renewal.";
type = lib.types.listOf lib.types.str;
default = [ ];
};
postCommands = lib.mkOption {
description = "Shell commands to run after a successful certificate renewal.";
type = lib.types.listOf lib.types.lines;
default = [ ];
};
};
};
mkMtlsGenerateScript = {
pkgs,
subject,
provisioner,
san,
certFile,
keyFile,
bundleFile,
lifetime,
user,
group,
}:
let
sanArgs = lib.concatMapStringsSep " " (s: "--san \"${s}\"") san;
in
pkgs.writeShellApplication {
name = "mtls-generate";
runtimeInputs = with pkgs; [ coreutils step-cli ];
text = ''
set -euo pipefail
step ca certificate ${subject} ${certFile} ${keyFile} \
--provisioner ${provisioner} \
--not-before=-5m --not-after=${lifetime} \
${sanArgs} \
"$@"
(umask 077; cat ${certFile} ${keyFile} > ${bundleFile})
chown ${user}:${group} ${certFile} ${keyFile} ${bundleFile}
chmod 640 ${certFile} ${keyFile} ${bundleFile}
printf '\033[32m\033[0m \033[1mmTLS Bundle:\033[0m %s\n' ${lib.escapeShellArg bundleFile}
'';
};
in
{
flake.modules.nixos.mtls = { config, lib, pkgs, ... }:
let
cfg = config.mtls;
mtlsRenewWrapper = inputs.self.wrappers.mtlsRenew.apply {
inherit pkgs;
inherit (cfg) certDir keyFile certFile bundleFile;
inherit (cfg.renew) user group reloadUnits postCommands;
systemd = {
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig = {
Type = "oneshot";
User = cfg.renew.user;
Group = cfg.renew.group;
};
} // lib.optionalAttrs cfg.renew.enable {
startAt = cfg.renew.onCalendar;
};
};
in
{
options.mtls = (mkOpts config) // {
certDir = lib.mkOption {
description = "String path to where the mtls certs will be stored.";
type = lib.types.str;
default = "/etc/step-ca/certs";
};
bootstrap = {
enable = lib.mkOption {
description = "Enable initial mTLS issuance when cert material is missing or invalid.";
type = lib.types.bool;
default = false;
};
wantedBy = lib.mkOption {
description = "systemd targets that should pull in mtls-bootstrap.service.";
type = with lib.types; listOf str;
default = [ "multi-user.target" ];
};
after = lib.mkOption {
description = "systemd units/targets that mtls-bootstrap.service should run after.";
type = with lib.types; listOf str;
default = [ "network-online.target" ];
};
wants = lib.mkOption {
description = "systemd units/targets that mtls-bootstrap.service should pull in.";
type = with lib.types; listOf str;
default = [ "network-online.target" ];
};
provisionerPasswordFile = lib.mkOption {
description = "Optional path passed to mtls-generate as --provisioner-password-file for noninteractive issuance.";
type = lib.types.nullOr lib.types.str;
default = null;
};
};
certReaders = lib.mkOption {
description = "";
type = lib.types.listOf lib.types.str;
default = [ ];
};
};
config = lib.mkIf cfg.enable {
users.groups.certReaders = {
name = cfg.renew.group;
members = cfg.certReaders;
};
environment.systemPackages = with pkgs; lib.optionals cfg.enable [
# step-cli
(mkMtlsGenerateScript {
inherit pkgs;
inherit (cfg) subject provisioner san certFile keyFile bundleFile lifetime;
inherit (cfg.renew) user group;
})
(inputs.self.wrappers.mtlsCheck.apply {
inherit pkgs;
inherit (cfg) bundleFile;
}).wrapper
mtlsRenewWrapper.wrapper
];
systemd.tmpfiles.rules = [
"d ${cfg.certDir} 0750 ${cfg.renew.user} ${cfg.renew.group} -"
];
systemd.packages = lib.mkIf cfg.renew.enable [
mtlsRenewWrapper.outputs.systemd-system
];
systemd.services.mtls-bootstrap = lib.mkIf cfg.bootstrap.enable {
description = "Issue initial mTLS certificate if missing or invalid";
wantedBy = cfg.bootstrap.wantedBy;
after = cfg.bootstrap.after;
wants = cfg.bootstrap.wants;
path = with pkgs; [ coreutils step-cli ];
serviceConfig = {
Type = "oneshot";
User = cfg.renew.user;
Group = cfg.renew.group;
};
script = ''
set -euo pipefail
if [ -s "${cfg.certFile}" ] \
&& [ -s "${cfg.keyFile}" ] \
&& [ -s "${cfg.bundleFile}" ] \
&& step certificate inspect "${cfg.certFile}" >/dev/null 2>&1; then
echo "mTLS certificate already exists"
exit 0
fi
echo "Issuing initial mTLS certificate"
cmd=(/run/current-system/sw/bin/mtls-generate)
${lib.optionalString (cfg.bootstrap.provisionerPasswordFile != null) ''
cmd+=(--provisioner-password-file "${cfg.bootstrap.provisionerPasswordFile}")
''}
"''${cmd[@]}"
'';
};
systemd.timers.mtls-renew = lib.mkIf cfg.renew.enable {
wantedBy = [ "timers.target" ];
timerConfig = {
Persistent = true;
AccuracySec = "1us";
RandomizedDelaySec = cfg.renew.randomizedDelaySec;
};
};
};
};
flake.modules.homeManager.mtls = { config, lib, pkgs, ... }:
let
cfg = config.mtls;
mtlsRenewWrapper = inputs.self.wrappers.mtlsRenew.apply {
inherit pkgs;
inherit (cfg) certDir keyFile certFile bundleFile;
inherit (cfg.renew) reloadUnits postCommands;
systemctlArgs = [ "--user" ];
systemd = lib.optionalAttrs cfg.renew.enable {
startAt = cfg.renew.onCalendar;
};
};
in
{
options.mtls = (mkOpts config) // {
certDir = lib.mkOption {
description = "String path to where the mtls certs will be stored.";
type = lib.types.str;
default = "${config.home.homeDirectory}/.step/certs";
};
};
config = {
home.packages = with pkgs; lib.optionals cfg.enable [
# step-cli
(mkMtlsGenerateScript {
inherit pkgs;
inherit (cfg) keyFile certFile bundleFile;
inherit (cfg) subject provisioner san lifetime;
inherit (cfg.renew) user group;
})
(inputs.self.wrappers.mtlsCheck.apply {
inherit pkgs;
inherit (cfg) bundleFile;
}).wrapper
];
systemd.user.tmpfiles.rules = lib.mkIf cfg.enable [
"d ${cfg.certDir} 0700 - - -" # Ensure the cert directory exists and is writable by the user
];
# Create the systemd service files for the user.
xdg.configFile = lib.mkIf cfg.renew.enable {
"systemd/user/mtls-renew.service".source =
"${mtlsRenewWrapper.outputs.systemd-user}/systemd/user/mtls-renew.service";
"systemd/user/mtls-renew.timer".source =
"${mtlsRenewWrapper.outputs.systemd-user}/systemd/user/mtls-renew.timer";
"systemd/user/mtls-renew.timer.d/override.conf".text = ''
[Timer]
Persistent=true
AccuracySec=1us
RandomizedDelaySec=${cfg.renew.randomizedDelaySec}
'';
};
# Ensure the timer gets started
home.activation.mtlsRenewTimer = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
if [ -n "$XDG_RUNTIME_DIR" ] && [ -S "$XDG_RUNTIME_DIR/systemd/private" ]; then
if [ "${lib.boolToString (cfg.enable && cfg.renew.enable)}" = "true" ]; then
run ${pkgs.systemd}/bin/systemctl --user daemon-reload
if ${pkgs.systemd}/bin/systemctl --user cat mtls-renew.timer >/dev/null 2>&1; then
run ${pkgs.systemd}/bin/systemctl --user enable --now mtls-renew.timer
else
verboseEcho "mtls-renew.timer unit file is not available; skipping enable"
fi
else
run ${pkgs.systemd}/bin/systemctl --user disable --now mtls-renew.timer || true
run ${pkgs.systemd}/bin/systemctl --user daemon-reload || true
fi
fi
'';
};
};
flake.wrappers = {
mtlsCheck = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
options = {
bundleFile = lib.mkOption {
description = "String path for the mTLS key bundle";
type = lib.types.str;
};
};
config = {
binName = "mtls-check";
# This pattern is necessary to wrap packages like openssl that provide more than one binary
package = config.pkgs.symlinkJoin {
name = "openssl";
paths = [ config.pkgs.openssl.bin config.pkgs.openssl.man ];
meta.mainProgram = "openssl";
};
args = [
"x509"
"-noout"
"-in" config.bundleFile
"-subject"
"-issuer"
"-ext" "subjectAltName,extendedKeyUsage"
"-enddate"
];
};
});
mtlsNeedsRenewal = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
options = {
certFile = lib.mkOption {
description = "String path for the public cert";
type = lib.types.str;
};
};
config = {
binName = "mtls-needs-renewal";
package = config.pkgs.step-cli;
preHook = ''
echo "Checking renewal status..."
'';
args = [ "certificate" "needs-renewal" "${config.certFile}" ];
};
});
mtlsRenew = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
imports = [ wlib.modules.systemd ];
options = {
certDir = lib.mkOption {
description = "String path to the directory where the certs will be stored";
type = lib.types.str;
};
keyFile = lib.mkOption {
description = "String path for the private key";
type = lib.types.str;
default = "${config.certDir}/key.pem";
};
certFile = lib.mkOption {
description = "String path for the public cert";
type = lib.types.str;
default = "${config.certDir}/cert.pem";
};
bundleFile = lib.mkOption {
description = "String path for the mTLS key bundle";
type = lib.types.str;
default = "${config.certDir}/mtls.pem";
};
user = lib.mkOption {
description = "User that should own the renewed certificate files.";
type = lib.types.nullOr lib.types.str;
default = null;
};
group = lib.mkOption {
description = "Group that should own the renewed certificate files.";
type = lib.types.nullOr lib.types.str;
default = null;
};
reloadUnits = lib.mkOption {
description = "systemd units to try-reload-or-restart after a successful renewal.";
type = lib.types.listOf lib.types.str;
default = [ ];
};
postCommands = lib.mkOption {
description = "Shell commands to run after a successful renewal.";
type = lib.types.listOf lib.types.lines;
default = [ ];
};
systemctlArgs = lib.mkOption {
description = "Additional arguments to pass to systemctl when reloading units.";
type = lib.types.listOf lib.types.str;
default = [ ];
};
};
config = {
binName = "mtls-renew";
package = let
systemctlCmd = "systemctl ${lib.escapeShellArgs config.systemctlArgs}";
hasReloadUnits = config.reloadUnits != [ ];
renewReloadScript = lib.concatMapStringsSep "\n" (unit: ''
if ${systemctlCmd} --quiet is-active "${unit}"; then
${systemctlCmd} try-reload-or-restart "${unit}"
fi
'') config.reloadUnits;
hasPostCommands = config.postCommands != [ ];
renewPostCommands = lib.concatStringsSep "\n" config.postCommands;
hasOwnership = config.user != null && config.group != null;
in
config.pkgs.writeShellApplication {
name = "mtls-renew";
runtimeInputs = with config.pkgs; [ coreutils step-cli systemd ];
text = ''
set -euo pipefail
YELLOW_BANG="\e[33m!\e[0m"
force=0
while [[ $# -gt 0 ]]; do
case $1 in
--force)
force=1
shift
;;
*)
echo -e "$YELLOW_BANG Warning: ignoring unrecognized argument '$1'"
exit 1
;;
esac
done
if [[ $force -eq 0 ]] && ! step certificate needs-renewal "${config.certFile}"; then
echo "Skipping renew"
exit 0
fi
echo "Renewing mTLS certificate"
step ca renew --force "${config.certFile}" "${config.keyFile}"
(umask 077; cat "${config.certFile}" "${config.keyFile}" > "${config.bundleFile}")
${lib.optionalString hasOwnership ''
chown ${config.user}:${config.group} ${config.certFile} ${config.keyFile} ${config.bundleFile}
chmod 640 ${config.certFile} ${config.keyFile} ${config.bundleFile}
''}
${lib.optionalString hasReloadUnits ''
echo "Reloading units: ${lib.concatStringsSep ", " config.reloadUnits}"
${renewReloadScript}
''}
${lib.optionalString hasPostCommands ''
echo "Running post commands"
${renewPostCommands}
''}
'';
};
extraPackages = [
config.pkgs.step-cli
];
systemd = {
description = "Renew the mTLS certificate when Smallstep marks it ready";
documentation = [
"https://smallstep.com/docs/step-ca/certificate-authority-server-production"
];
startLimitIntervalSec = 0;
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig.Type = lib.mkDefault "oneshot";
# serviceConfig.ExecCondition = "";
};
};
});
};
}
+54
View File
@@ -0,0 +1,54 @@
{ lib, ... }: {
options.optionModules.mtls = lib.mkOption {
type = lib.types.deferredModule;
description = "Shared mTLS certificate option definitions, imported by the mTLS wrapper modules.";
};
config.optionModules.mtls = { config, lib, pkgs, ... }: {
key = "mtls-config";
_file = "modules/features/mtls/config.nix";
options = {
certDir = lib.mkOption {
description = "String path to the directory where the certs will be stored";
type = lib.types.str;
default = "/etc/mtls";
};
keyFile = lib.mkOption {
description = "String path for the private key";
type = lib.types.str;
default = "${config.certDir}/key.pem";
};
certFile = lib.mkOption {
description = "String path for the public cert";
type = lib.types.str;
default = "${config.certDir}/cert.pem";
};
bundleFile = lib.mkOption {
description = "String path for the mTLS key bundle";
type = lib.types.str;
default = "${config.certDir}/mtls.pem";
};
certGroup = lib.mkOption {
description = "Group that should be granted read access to generated certificate material.";
type = lib.types.str;
default = "mtls";
};
subject = lib.mkOption {
description = "Subject for the cert";
type = lib.types.str;
};
provisioner = lib.mkOption {
type = lib.types.nullOr lib.types.str;
};
provisionerPasswordFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
};
overwrite = lib.mkEnableOption "Overwrite existing cert file?";
SANs = lib.mkOption {
description = "A list of Subject Alternative Names";
type = lib.types.listOf lib.types.str;
default = [ ];
};
};
};
}
+167
View File
@@ -0,0 +1,167 @@
{ self, inputs, lib, ... }:
let
# Options that will be in common between the nixos module and the home-manager module.
mkOpts = config: let cfg = config.mtls; in {
enable = lib.mkEnableOption "Enable mTLS";
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.";
type = lib.types.str;
};
certDir = lib.mkOption {
description = "String path to the directory where the certs will be stored";
type = lib.types.str;
};
caFile = lib.mkOption {
description = "String path for the root CA file";
type = lib.types.str;
default = "${cfg.certDir}/root_ca.crt";
};
keyFile = lib.mkOption {
description = "String path for the private key";
type = lib.types.str;
default = "${cfg.certDir}/key.pem";
};
certFile = lib.mkOption {
description = "String path for the public cert";
type = lib.types.str;
default = "${cfg.certDir}/cert.pem";
};
bundleFile = lib.mkOption {
description = "String path for the mTLS key bundle";
type = lib.types.str;
default = "${cfg.certDir}/mtls.pem";
};
san = lib.mkOption {
description = "List of SAN to give the mTLS cert";
type = lib.types.listOf lib.types.str;
default = [ ];
};
provisioner = lib.mkOption {
type = lib.types.str;
default = "admin";
};
lifetime = lib.mkOption {
type = lib.types.str;
default = "24h";
};
renew = {
enable = lib.mkOption {
description = "Enable automatic mTLS certificate renewal using a systemd timer.";
type = lib.types.bool;
default = cfg.enable;
};
onCalendar = lib.mkOption {
description = "systemd OnCalendar schedule for mTLS certificate renewal checks.";
type = lib.types.str;
default = "*:1/15";
};
randomizedDelaySec = lib.mkOption {
description = "Randomized delay added to renewal timer runs to avoid synchronized renewals.";
type = lib.types.str;
default = "5m";
};
user = lib.mkOption {
description = "User account to run the mTLS renewal service as.";
type = lib.types.str;
default = "root";
};
group = lib.mkOption {
description = "Group to run the mTLS renewal service as. Defaults to the configured renewal user.";
type = lib.types.nullOr lib.types.str;
default = "mtls";
};
reloadUnits = lib.mkOption {
description = "systemd units to try-reload-or-restart after a successful certificate renewal.";
type = lib.types.listOf lib.types.str;
default = [ ];
};
postCommands = lib.mkOption {
description = "Shell commands to run after a successful certificate renewal.";
type = lib.types.listOf lib.types.lines;
default = [ ];
};
};
};
in
{
flake.modules.nixos.mtls = { config, lib, pkgs, ... }:
let
cfg = config.mtls;
mtlsWrappers = inputs.self.wrappers.mtls;
mtlsGenerate = mtlsWrappers.generate.apply {
inherit pkgs;
inherit (cfg) subject;
SANs = cfg.san;
provisioner = "admin";
provisionerPasswordFile = config.sops.secrets."janus/admin_jwk".path;
};
mtlsRenew = mtlsWrappers.renew.apply {
inherit pkgs;
};
mtlsCheck = mtlsWrappers.check.apply {
inherit pkgs;
};
in
{
options.mtls = (mkOpts config) // {
certDir = lib.mkOption {
description = "String path to where the mtls certs will be stored.";
type = lib.types.str;
default = "/etc/step-ca/certs";
};
bootstrap = {
enable = lib.mkOption {
description = "Enable initial mTLS issuance when cert material is missing or invalid.";
type = lib.types.bool;
default = false;
};
wantedBy = lib.mkOption {
description = "systemd targets that should pull in mtls-bootstrap.service.";
type = with lib.types; listOf str;
default = [ "multi-user.target" ];
};
after = lib.mkOption {
description = "systemd units/targets that mtls-bootstrap.service should run after.";
type = with lib.types; listOf str;
default = [ "network-online.target" ];
};
wants = lib.mkOption {
description = "systemd units/targets that mtls-bootstrap.service should pull in.";
type = with lib.types; listOf str;
default = [ "network-online.target" ];
};
provisionerPasswordFile = lib.mkOption {
description = "Optional path passed to mtls-generate as --provisioner-password-file for noninteractive issuance.";
type = lib.types.nullOr lib.types.str;
default = null;
};
};
certReaders = lib.mkOption {
description = "";
type = lib.types.listOf lib.types.str;
default = [ ];
};
};
config = lib.mkIf cfg.enable {
users.groups.certReaders = {
name = cfg.renew.group;
members = cfg.certReaders;
};
environment.systemPackages = [
mtlsGenerate.wrapper
mtlsCheck.wrapper
mtlsRenew.wrapper
];
systemd = {
packages = [ mtlsRenew.outputs.systemd-system ];
# Timer-driven oneshot: only the timer is enabled. NixOS does not
# honor the unit's [Install] section for systemd.packages, so the
# wantedBy must be set explicitly here.
timers.mtls-renew.wantedBy = [ "timers.target" ];
};
};
};
}
+102
View File
@@ -0,0 +1,102 @@
{ self, inputs, lib, config, ... }:
let
mtlsConfigModule = config.optionModules.mtls;
mkSANArgs = sans: builtins.concatLists (map (name: [ "--san" name ]) sans);
in
{
flake.wrappers.mtls = {
generate = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
imports = [ mtlsConfigModule ];
config = {
binName = "mtls-generate";
package = config.pkgs.step-cli;
extraPackages = with config.pkgs; [ coreutils step-cli systemd ];
preHook = ''
mkdir -p "${config.certDir}"
chgrp "${config.certGroup}" "${config.certDir}"
chmod 0750 "${config.certDir}"
'';
args = [
"ca" "certificate"
"${config.subject}" "${config.certFile}" "${config.keyFile}"
"--not-before" "-5m"
"--not-after" "24h"
]
++ lib.optionals (config.provisioner != null) [ "--provisioner" "${config.provisioner}" ]
++ lib.optionals (config.provisionerPasswordFile != null) [
"--provisioner-password-file" "${config.provisionerPasswordFile}"
]
++ lib.optionals config.overwrite [ "-f" ]
++ mkSANArgs config.SANs;
postHook = ''
chgrp "${config.certGroup}" "${config.certFile}" "${config.keyFile}"
chmod 0640 "${config.certFile}" "${config.keyFile}"
(umask 077; cat "${config.certFile}" "${config.keyFile}" > "${config.bundleFile}")
chgrp "${config.certGroup}" "${config.bundleFile}"
chmod 0640 "${config.bundleFile}"
'';
};
});
renew = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
# https://github.com/Lassulus/wrappers#generating-systemd-services
imports = [
wlib.modules.systemd mtlsConfigModule
mtlsConfigModule
];
config = {
binName = "mtls-renew";
package = config.pkgs.step-cli;
extraPackages = with config.pkgs; [ coreutils step-cli systemd ];
args = [
"ca" "renew"
"${config.certFile}" "${config.keyFile}"
];
postHook = ''
chgrp "${config.certGroup}" "${config.certFile}" "${config.keyFile}"
chmod 0640 "${config.certFile}" "${config.keyFile}"
(umask 077; cat "${config.certFile}" "${config.keyFile}" > "${config.bundleFile}")
chgrp "${config.certGroup}" "${config.bundleFile}"
chmod 0640 "${config.bundleFile}"
'';
systemd = {
description = "Renew the mTLS certificate when Smallstep marks it ready";
documentation = [
"https://smallstep.com/docs/step-ca/certificate-authority-server-production"
];
startLimitIntervalSec = 0;
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
serviceConfig = {
Type = lib.mkDefault "oneshot";
ExecCondition = "${lib.getExe config.pkgs.step-cli} certificate needs-renewal ${config.certFile}";
};
startAt = "hourly";
};
};
});
check = inputs.wrappers.lib.wrapModule ({ config, lib, wlib, ... }: {
imports = [ mtlsConfigModule ];
config = {
binName = "mtls-check";
# This pattern is necessary to wrap packages like openssl that provide more than one binary
package = config.pkgs.symlinkJoin {
name = "openssl";
paths = [ config.pkgs.openssl.bin config.pkgs.openssl.man ];
meta.mainProgram = "openssl";
};
args = [
"x509"
"-noout"
"-in" config.bundleFile
"-subject"
"-issuer"
"-ext" "subjectAltName,extendedKeyUsage"
"-enddate"
];
};
});
};
}
-100
View File
@@ -1,100 +0,0 @@
{ self, inputs, ... }:
let
mkPrincipalArgs = principals:
builtins.concatLists (map (principal: [ "--principal" principal ]) principals);
in
{
perSystem = { system, self', pkgs, lib, ... }: {
packages.ssh-certs = inputs.wrappers.lib.wrapPackage {
inherit pkgs;
package = (pkgs.symlinkJoin {
name = "ssh-certs";
meta.mainProgram = "sign-ssh-user-cert";
paths = [
(inputs.self.wrappers.signUserWrapper.apply {
inherit pkgs;
provisioner = "admin";
overwrite = true;
validUsers = [ "john" "root" "appdaemon" ];
}).wrapper
(inputs.self.wrappers.signHostWrapper.apply {
inherit pkgs;
provisioner = "admin";
overwrite = true;
# extraPrincipals = [ "home-pc" ];
}).wrapper
];
});
};
};
flake.wrappers.signHostWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
options = {
provisioner = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = "admin";
};
extraPrincipals = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ ];
};
overwrite = lib.mkEnableOption "Overwrite existing cert file?";
};
config = {
binName = "sign-ssh-host-cert";
package = config.pkgs.step-cli;
extraPackages = with config.pkgs; [ hostname iproute2 systemd ];
preHook = ''
HOSTNAME=$(hostname -s)
IP_ADDRESS=$(ip -4 -o addr show scope global | while read -r _ _ _ addr _; do
case "$addr" in
192.168.1.*/*)
printf '%s\n' "''${addr%%/*}"
break
;;
esac
done)
echo "Signing SSH host cert for $HOSTNAME at $IP_ADDRESS"
'';
args =
[
"ssh" "certificate"
"--host" "--sign"
"--principal" "$HOSTNAME"
"--principal" "$IP_ADDRESS"
]
++ lib.optionals (config.provisioner != null) [ "--provisioner" "${config.provisioner}" ]
++ lib.optionals config.overwrite [ "-f" ]
++ mkPrincipalArgs config.extraPrincipals;
postHook = ''
systemctl reload-or-restart sshd
'';
};
});
flake.wrappers.signUserWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
options = {
provisioner = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = "admin";
};
validUsers = lib.mkOption {
description = "A list of the user names that this cert will be valid for";
type = lib.types.listOf lib.types.str;
default = [ ];
};
overwrite = lib.mkEnableOption "Overwrite existing cert file?";
};
config = {
binName = "sign-ssh-user-cert";
package = config.pkgs.step-cli;
args = [ "ssh" "certificate" "--sign" ]
++ lib.optionals (config.provisioner != null) [ "--provisioner" "${config.provisioner}" ]
++ lib.optionals config.overwrite [ "-f" ]
++ mkPrincipalArgs config.validUsers;
};
});
}
+79
View File
@@ -0,0 +1,79 @@
{ lib, ... }: {
options.optionModules.ssh-certs = lib.mkOption {
type = lib.types.deferredModule;
description = "SSH certificate options";
};
config.optionModules.ssh-certs = { config, lib, pkgs, ... }: {
# Needed for some kind of de-duping when this module is used more than once?
key = "ssh-cert-config";
_file = "modules/features/ssh/config.nix";
options.ssh-new = {
user = {
keyFile = lib.mkOption {
type = lib.types.str;
default = "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 = { };
};
enable-scripts = lib.mkEnableOption "Enable SSH host cert management scripts";
};
certificates = {
provisioner = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
provisionerPasswordFile = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
};
overwrite = lib.mkEnableOption "Overwrite existing certificate files";
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 = [ "root" "john" "appdaemon" ];
};
};
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 = [ ];
};
expires-in = lib.mkOption {
description = "Duration passed to step ssh needs-renewal --expires-in.";
type = lib.types.str;
default = "4h";
};
};
};
};
};
}
+258
View File
@@ -0,0 +1,258 @@
# New attempt at consolidating SSH config that wraps the step client, SSH certs, and all that in a top-level module
{ self, inputs, lib, config, ... }:
let
sshHostCAPath = ../../hosts/janus/public/ssh_host_ca_key.pub;
caPatterns = [ "*.john-stream.com" "192.168.1.*" "fded:fb16:653e:25da:be24:11ff:*" ];
wrappers = inputs.self.wrappers;
sshCertConfig = config.optionModules.ssh-certs;
mkHostScripts = { cfg, pkgs, provisionerPasswordFile ? null }: let
hostKeyFile = "${cfg.host.configDir}/${cfg.host.keyFile}";
hostCertFile = "${hostKeyFile}-cert.pub";
wrapperCfg = cfg // {
certificates = cfg.certificates // {
provisionerPasswordFile = provisionerPasswordFile;
overwrite = true;
};
};
in {
inherit hostKeyFile hostCertFile;
sign = (wrappers.signHostWrapper.apply {
inherit pkgs;
ssh-new = wrapperCfg;
}).wrapper;
renew = (wrappers.renewHostWrapper.apply {
inherit pkgs;
ssh-new = wrapperCfg;
}).wrapper;
check = (wrappers.hostCheckWrapper.apply {
inherit pkgs;
ssh-new = wrapperCfg;
}).wrapper;
renewalCheck = (wrappers.renewalCheck.apply {
inherit pkgs;
ssh-new = wrapperCfg;
}).wrapper;
};
mkUserScripts = { cfg, pkgs, provisionerPasswordFile ? null }: {
sign = let
wrapperCfg = cfg // {
certificates = cfg.certificates // {
provisionerPasswordFile = provisionerPasswordFile;
overwrite = true;
};
};
in (wrappers.signUserWrapper.apply {
inherit pkgs;
ssh-new = wrapperCfg;
}).wrapper;
check = (wrappers.userCheckWrapper.apply {
inherit pkgs;
ssh-new = cfg;
}).wrapper;
};
in
{
flake.modules.nixos.ssh-new = { config, pkgs, lib, ... }:
let
cfg = config.ssh-new;
hasAdminJwk = lib.hasAttrByPath [ "sops" "secrets" "janus/admin_jwk" ] config;
adminJwkPath = if hasAdminJwk then config.sops.secrets."janus/admin_jwk".path else null;
hostScripts = mkHostScripts {
inherit cfg pkgs;
provisionerPasswordFile = if cfg.certificates.host.autoRenew
then adminJwkPath
else null;
};
CAknownHosts = (lib.genAttrs caPatterns (_: {
certAuthority = true;
publicKey = lib.removeSuffix "\n" (builtins.readFile sshHostCAPath);
}));
in
{
imports = [ sshCertConfig ];
config = {
services.openssh = {
enable = true;
openFirewall = true;
hostKeys = [
{
path = hostScripts.hostKeyFile;
type = cfg.host.keyType;
}
];
settings = lib.mkMerge [
{
PasswordAuthentication = false;
KbdInteractiveAuthentication = false;
}
cfg.host.extraSettings
(lib.mkIf cfg.certificates.host.enable {
HostCertificate = hostScripts.hostCertFile;
})
(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 [
hostScripts.sign
hostScripts.renew
hostScripts.renewalCheck
hostScripts.check
]
);
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 hostScripts.renewalCheck;
ExecStart = lib.getExe hostScripts.renew;
};
};
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 = [ inputs.self.modules.homeManager.ssh-new ];
ssh-new.certificates.user.enable = true;
};
};
};
flake.modules.homeManager.ssh-new = { config, pkgs, lib, ... }:
let
cfg = config.ssh-new;
userKeyPath =
if lib.hasPrefix "/" cfg.user.keyFile || lib.hasPrefix "~/" cfg.user.keyFile
then cfg.user.keyFile
else "${config.home.homeDirectory}/.ssh/${cfg.user.keyFile}";
hasAdminJwk = lib.hasAttrByPath [ "sops" "secrets" "janus/admin_jwk" ] config;
adminJwkPath = if hasAdminJwk then config.sops.secrets."janus/admin_jwk".path else null;
hostScripts = mkHostScripts { inherit cfg pkgs; };
sshHostCAContent = lib.removeSuffix "\n" (builtins.readFile sshHostCAPath);
knownHostsText = lib.concatMapStrings
(pattern: "@cert-authority ${pattern} ${sshHostCAContent}\n")
caPatterns;
userScripts = mkUserScripts {
inherit cfg pkgs;
provisionerPasswordFile = adminJwkPath;
};
in
{
imports = [ sshCertConfig ];
config = {
home.file.".ssh/known_hosts" = lib.mkIf cfg.certificates.user.enable {
text = knownHostsText;
force = true;
};
home.packages = lib.optionals cfg.certificates.user.enable [
userScripts.sign
userScripts.check
];
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 = userKeyPath;
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.user.enable [
{
CertificateFile = "${userKeyPath}-cert.pub";
}
]
);
"john-pc" = {
HostName = "192.168.1.85";
User = "john";
};
"gitea" = {
HostName = "192.168.1.104";
User = "john";
};
"janus" = {
HostName = "fded:fb16:653e:25da:be24:11ff:fe6b:4d57";
User = "root";
};
"soteria" = {
HostName = "fded:fb16:653e:25da:be24:11ff:fe54:aa39";
User = "root";
};
"hermes" = {
HostName = "192.168.1.150";
User = "root";
};
"jdl-docker" = {
HostName = "jdl-docker.tailcf205.ts.net";
User = "john";
};
};
};
};
};
}
+121
View File
@@ -0,0 +1,121 @@
{ self, inputs, config, ... }:
let
sshCertConfig = config.optionModules.ssh-certs;
mkHostKeyFile = cfg: "${cfg.host.configDir}/${cfg.host.keyFile}";
mkPrincipalArgs = principals:
builtins.concatLists (map (principal: [ "--principal" principal ]) principals);
in
{
flake.wrappers.signHostWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
imports = [ sshCertConfig ];
config = let cfg = config.ssh-new; in {
binName = "ssh-host-cert-sign";
package = config.pkgs.step-cli;
extraPackages = with config.pkgs; [ hostname iproute2 systemd ];
preHook = ''
HOSTNAME=$(hostname -s)
IP_ADDRESS=$(ip -4 -o addr show scope global | while read -r _ _ _ addr _; do
case "$addr" in
192.168.1.*/*)
printf '%s\n' "''${addr%%/*}"
break
;;
esac
done)
echo "Signing SSH host cert for $HOSTNAME at $IP_ADDRESS"
'';
args =
[
"ssh" "certificate"
"--host" "--sign"
"--principal" "$HOSTNAME"
"--principal" "$IP_ADDRESS"
]
++ lib.optionals (cfg.certificates.provisioner != null) [
"--provisioner" "${cfg.certificates.provisioner}"
]
++ lib.optionals (cfg.certificates.provisionerPasswordFile != null) [
"--provisioner-password-file" "${cfg.certificates.provisionerPasswordFile}"
]
++ lib.optionals cfg.certificates.overwrite [ "-f" ]
++ mkPrincipalArgs cfg.certificates.host.extraPrincipals;
};
});
flake.wrappers.renewHostWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
imports = [ sshCertConfig ];
config = {
binName = "ssh-host-cert-renew";
package = config.pkgs.step-cli;
extraPackages = with config.pkgs; [ systemd ];
args =
let hostKeyFile = mkHostKeyFile config.ssh-new;
in [ "ssh" "renew" "${hostKeyFile}-cert.pub" "${hostKeyFile}" ]
++ lib.optionals config.ssh-new.certificates.overwrite [ "-f" ];
};
});
flake.wrappers.hostCheckWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
imports = [ sshCertConfig ];
config = {
binName = "ssh-host-cert-check";
package = config.pkgs.openssh;
exePath = lib.getExe' config.pkgs.openssh "ssh-keygen";
args = [ "-Lf" "${mkHostKeyFile config.ssh-new}-cert.pub" ];
};
});
flake.wrappers.signUserWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
imports = [ sshCertConfig ];
config =
let
cfg = config.ssh-new;
in {
binName = "ssh-user-cert-sign";
package = config.pkgs.step-cli;
args = [ "ssh" "certificate" "--sign" ]
++ lib.optionals (cfg.certificates.provisioner != null) [
"--provisioner" "${cfg.certificates.provisioner}"
]
++ lib.optionals (cfg.certificates.provisionerPasswordFile != null) [
"--provisioner-password-file" "${cfg.certificates.provisionerPasswordFile}"
]
++ lib.optionals cfg.certificates.overwrite [ "-f" ]
++ mkPrincipalArgs cfg.certificates.user.extraPrincipals;
};
});
flake.wrappers.userCheckWrapper = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
imports = [ sshCertConfig ];
config =
let
cfg = config.ssh-new;
in {
binName = "ssh-user-cert-check";
package = config.pkgs.openssh;
exePath = lib.getExe' config.pkgs.openssh "ssh-keygen";
args = [ "-Lf" "$HOME/.ssh/${config.ssh-new.user.keyFile}-cert.pub" ];
};
});
flake.wrappers.renewalCheck = inputs.wrappers.lib.wrapModule ({config, lib, wlib, ... }: {
imports = [ sshCertConfig ];
config =
let
cfg = config.ssh-new;
hostKeyFile = mkHostKeyFile cfg;
hostCertFile = "${hostKeyFile}-cert.pub";
in
{
binName = "ssh-renewal-check";
package = config.pkgs.step-cli;
preHook = ''
echo "Checking SSH cert at ${hostCertFile}"
'';
args = [
"ssh" "needs-renewal" hostCertFile
"--expires-in" "${cfg.certificates.host.expires-in}"
];
};
});
}
+1 -1
View File
@@ -2,7 +2,7 @@
let
defaultCaUrl = "https://janus.john-stream.com/";
defaultFingerprint = "2036c44f7b5901566ff7611ea6c927291ecc6d2dd00779c0eead70ec77fa10d6";
defaultRoot = ../hosts/janus/root_ca.crt;
defaultRoot = ../hosts/janus/public/root_ca.crt;
mkStepBootstrap = { pkgs, caUrl, fingerprint, install ? false }:
(inputs.self.wrappers.stepBootstrap.apply {
+5 -5
View File
@@ -34,18 +34,18 @@ If rotating provisioner password, also set:
Secret source-of-truth after this split:
- `modules/hosts/janus/secrets.yaml`: Janus runtime CA secrets (`ca_password`, `intermediate_ca_key`, `ssh_host_ca_key`, `ssh_user_ca_key`, `admin_provisioner_encrypted_key`)
- `keys/secrets.yaml`: shared Janus provisioner secret (`janus.admin_jwk`) consumed by `ssh-certs` across hosts
- `keys/secrets.yaml`: shared Janus provisioner secret (`janus.admin_jwk`) consumed across hosts
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/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/root_ca.crt` from `/tmp/janus-step-ca-bootstrap/step/certs/root_ca.crt`
- `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:
```shell
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/ssh_host_ca_key.pub` from `/tmp/janus-step-ca-bootstrap/step/certs/ssh_host_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/public/ssh_host_ca_key.pub` from `/tmp/janus-step-ca-bootstrap/step/certs/ssh_host_ca_key.pub`
## First boot checks
+18 -38
View File
@@ -4,19 +4,19 @@ let
hostname = "janus";
ipv4 = "192.168.1.32";
ipv6 = "fded:fb16:653e:25da:be24:11ff:fe6b:4d57";
names = [ "${hostname}.john-stream.com" ipv4 ipv6 ];
in
{
flake.nixosConfigurations."${hostname}" = inputs.nixpkgs.lib.nixosSystem {
modules = with inputs.self.modules; [
nixos.lxc
nixos.mysops
nixos.ssh-certs
nixos.step-client
nixos.step-ca
nixos.login-text
inputs.home-manager.nixosModules.home-manager
nixos."${username}"
nixos.docker
nixos.login-text
nixos.ssh-new
nixos.mysops
nixos.step-ca # Runs the step-ca server
nixos.step-client # Uses the step-ca server as a client
nixos.mtls
({ config, lib, pkgs, ... }: {
networking.hostName = hostname;
@@ -24,18 +24,19 @@ in
"Step-CA" = "step-ca";
};
sops.defaultSopsFile = ./secrets.yaml;
ssh-certs = {
hostname = hostname;
extraPrincipals = [ ipv4 ipv6 ];
ssh-new.certificates = {
provisioner = "admin";
host = {
enable = true;
extraPrincipals = names;
autoRenew = true;
};
user.enable = true;
};
step-ca = {
rootCertPath = ./root_ca.crt;
intermediateCertPath = ./intermediate_ca.crt;
dnsNames = [
"${hostname}.john-stream.com"
ipv4
ipv6
];
rootCertPath = ./public/root_ca.crt;
intermediateCertPath = ./public/intermediate_ca.crt;
dnsNames = names;
secrets = {
sopsFile = ./secrets.yaml;
caPassword = "janus/ca_password";
@@ -49,10 +50,7 @@ in
mtls = {
enable = true;
subject = hostname;
san = [
"${hostname}.john-stream.com"
ipv4
];
san = names;
bootstrap = {
enable = true;
after = [ "sops-nix.service" "step-ca.service" ];
@@ -60,24 +58,6 @@ in
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;
};
})
];
};
-1
View File
@@ -33,7 +33,6 @@ in
home.packages = with pkgs; [
selfPkgs.jsl-zsh
selfPkgs.my-neovim
selfPkgs.ssh-certs
# selfPkgs.step-bootstrap
# selfPkgs.wg-platform
# self'.packages.myWrappedPackage
+28 -35
View File
@@ -3,11 +3,8 @@ let
username = "john";
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
testTarget = "test-nix";
in
{
flake.modules.homeManager."${hostname}" = { config, pkgs, lib, ... }:
@@ -20,8 +17,8 @@ in
imports = with inputs.self.modules.homeManager; [
rebuild
john
mtls
restic
# mtls
# restic
docker
desktop
step-client
@@ -36,16 +33,12 @@ in
targets.genericLinux.enable = true;
homeManagerFlakeDir = flakeDir;
home.username = "${username}";
home.homeDirectory = "/home/${username}";
home.packages = with pkgs; [
nil # Nix language server
selfPkgs.jsl-zsh
# selfPkgs.my-neovim
selfPkgs.ssh-certs
# selfPkgs.step-bootstrap
# selfPkgs.wg-platform
# self'.packages.myWrappedPackage
(inputs.self.wrappers.test-push.apply {
inherit pkgs flakeDir;
host = testHost;
@@ -53,22 +46,22 @@ in
}).wrapper
];
homeManagerFlakeDir = flakeDir;
docker.enable = true;
ssh = {
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-new = {
certificates = {
provisioner = "admin";
user.enable = 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
sops.defaultSopsFile = ../../../keys/secrets.yaml;
@@ -81,18 +74,18 @@ in
mode = "0400";
sopsFile = ./secrets.yaml;
};
restic = {
passwordFile = resticPasswordFile;
OnCalendar = "*:0/15";
paths = [ "${config.xdg.userDirs.documents}" "/conf" ];
exclude = [
"/home/*/Pictures"
"/home/*/Videos"
"/home/*/go"
"/home/*/snap"
"/home/john/john-nas"
];
};
# restic = {
# passwordFile = resticPasswordFile;
# OnCalendar = "*:0/15";
# paths = [ "${config.xdg.userDirs.documents}" "/conf" ];
# exclude = [
# "/home/*/Pictures"
# "/home/*/Videos"
# "/home/*/go"
# "/home/*/snap"
# "/home/john/john-nas"
# ];
# };
# mtls = {
# enable = true;
# subject = hostname;
+46 -42
View File
@@ -3,17 +3,23 @@
let
username = "john";
hostname = "soteria";
forgejoDomain = "forgejo.john-stream.com";
ipv4 = "192.168.1.233";
ipv6 = "fded:fb16:653e:25da:be24:11ff:fe54:aa39";
sshNames = [ "${hostname}.john-stream.com" ipv4 ipv6 ];
mtlsNames = sshNames ++ [ forgejoDomain ];
in
{
flake.nixosConfigurations."${hostname}" = inputs.nixpkgs.lib.nixosSystem {
modules = with inputs.self.modules; [
nixos.lxc
nixos.mysops
nixos."${username}"
nixos.ssh-certs
nixos.login-text
nixos.docker
inputs.home-manager.nixosModules.home-manager
nixos."${username}"
nixos.ssh-new
nixos.mtls
nixos.mysops
nixos.docker
nixos.step-client
nixos.forgejo
nixos.restic-server
@@ -34,54 +40,61 @@ in
}
];
users.users."${username}".extraGroups = [ "mtls" ];
# users.users."${username}".extraGroups = [ "mtls" ];
mtls = {
enable = true;
subject = hostname;
san = [
"${hostname}.john-stream.com"
# "192.168.1.142"
"forgejo.john-stream.com"
"192.168.1.244"
];
lifetime = "12h";
renew.onCalendar = "*:3/15";
renew.reloadUnits = [ "forgejo.service" "restic-rest-server.service" ];
certReaders = [ config.services.forgejo.user "restic" ];
san = mtlsNames;
certDir = "/etc/mtls";
# lifetime = "12h";
# renew.onCalendar = "*:3/15";
# renew.reloadUnits = [ "forgejo.service" "restic-rest-server.service" ];
# certReaders = [ config.services.forgejo.user "restic" ];
};
forgejo = {
enable = true;
root_url = "https://forgejo.john-stream.com";
https = true;
port = 443;
};
resticServer = {
enable = true;
dataDir = "/mnt/restic";
privateRepos = true;
listenAddress = "0.0.0.0:8000";
tls = {
certFile = config.mtls.certFile;
keyFile = config.mtls.keyFile;
pocketId = {
enable = true;
discoveryUrl = "https://pocketid.john-stream.com/.well-known/openid-configuration";
};
};
# resticServer = {
# enable = true;
# dataDir = "/mnt/restic";
# privateRepos = true;
# listenAddress = "0.0.0.0:8000";
# tls = {
# certFile = config.mtls.certFile;
# keyFile = config.mtls.keyFile;
# };
# };
loginText.extraServiceStatus = {
Docker = "docker";
"mTLS Renewal" = "mtls-renew.timer";
Forgejo = "forgejo.service";
"Forgejo" = "forgejo.service";
"Forgejo Backup" = "forgejo-dump.timer";
"Restic REST Server" = "restic-rest-server.service";
};
ssh-certs.hostname = hostname;
ssh-new.certificates = {
provisioner = "admin";
host = {
enable = true;
extraPrincipals = sshNames;
autoRenew = true;
};
user.enable = true;
};
# This provides the secrets at install time
sops.defaultSopsFile = ./secrets.yaml;
# programs.zsh.enable = true;
home-manager.users."${username}".imports = [ inputs.self.modules.homeManager.soteria ];
environment.systemPackages = [
@@ -93,10 +106,10 @@ in
};
flake.modules.homeManager.soteria = { config, pkgs, lib, ... }: {
imports = [
inputs.self.modules.homeManager.rebuild
inputs.self.modules.homeManager.mysops
inputs.self.modules.homeManager.step-client
imports = with inputs.self.modules.homeManager; [
rebuild
mysops
step-client
({ config, pkgs, lib, ... }: {
homeManagerFlakeDir = "${config.xdg.configHome}/home-manager";
docker.enable = true;
@@ -106,13 +119,4 @@ in
})
];
};
flake.homeConfigurations.soteria = withSystem "x86_64-linux" (ctx@{ config, inputs', ...}:
inputs.home-manager.lib.homeManagerConfiguration {
pkgs = inputs'.nixpkgs.legacyPackages;
modules = [
inputs.self.modules.homeManager."${username}"
inputs.self.modules.homeManager.soteria
];
});
}
+35 -32
View File
@@ -1,42 +1,45 @@
forgejo:
#ENC[AES256_GCM,data:/wtm0uXbiWFoGNWtlTzVuNxBR7CPm2FMB98t3AxSj5V5rltLvzF9BjgWoJCiX3ltzmU=,iv:xaZXbUIGJHxPrLRQzEQI7hgRgc0y061jIhoE3zlcMaA=,tag:fQGheCIdBKm6wE+vtj7g6A==,type:comment]
secret_key: ENC[AES256_GCM,data:/jcyeDcsryLqu9Q3VnNaENb71/Tl5JUr0zDzxt8L5UCtnJ/YHA6MKItrQ9ZHFv1XROtnSfZl9D5kKomeM8EVqA==,iv:HxMKAMVQ08gkq6SWENj0/d8i9PhcgPCp5eqbztj9bSg=,tag:nO2dFWT/vfgGc/9JIDZrGw==,type:str]
#ENC[AES256_GCM,data:TADqVsZwXpH/zfrXNclavH8Sv++jX081UjK/Mkys5x52gU5fU0ikk478EmwzeergsHpmxxon,iv:v9HsIsud+eiko7F0u622MBrTVDsIxlpqru0Viifvqow=,tag:FLgNTW0EcGhHT6iI9I6Bsg==,type:comment]
internal_token: ENC[AES256_GCM,data:7eZM+misgHZz1p6HH9VzCAPIIFjp2vT0kyc9B1KllE+x2URyrgs5IR9SZ+T5vNdMdnlNzF25pUhKzjbak8tVN554rYWp06SczzqhLyaoHKs8iGBohMqfJkoZxxIVSB7g7GC+/SAsb719,iv:XbBXqXh/PqjEcAj0qsajR7Ij56KGT/9Spdp5T549p9I=,tag:o4ONucOkIE2VJ6VjOlPb6w==,type:str]
#ENC[AES256_GCM,data:ZqwgnKjaolJtjcy287fnDOkb/oSLnBpfWfsTeVPwbIE8YLRSoPP4gbCnHJBLq+TJNNI=,iv:zTvw4ZS6C1ifUwOijNLuTfUQ3JM+5gj1X2f/s8MwWXc=,tag:Y1yKlL+jIRHVBulGlSErog==,type:comment]
jwt_secret: ENC[AES256_GCM,data:e59MlATOorsTIQjtTUKfX5Yo3CVsbbfuKczp1gh1m2D1kkZK3ORFztYpjg==,iv:JH3PVUmXToiThEKDkDJ8MGVMAPlIEgPSWhru+9WgNjk=,tag:FfDpaCPejpw6kGDkxJwDWw==,type:str]
lfs_jwt_secret: ENC[AES256_GCM,data:xi9PEKFUGRyc3YOg3JM3KrrENi9xsbeBjiz4R16SK5WDafoGFLazN6KRJQ==,iv:1IhPyQDwA8tZ22pfZJiU8TRTCLCHC/HAnKdmSGDfvcM=,tag:rLdREVSKBm67rt8ayN16Vw==,type:str]
restic_password: ENC[AES256_GCM,data:u7QOZXJkxVG4J75K5nphb2uJGdz6jbWuVSsKKu+41fshp7cVoRijtr/Cs02LjVse,iv:bt1W2FeBTG6ypBFYzMPXPIkYTSn0uHURY2ui6MRgYY8=,tag:DObAMws/zQcM+UKUe9EECA==,type:str]
#ENC[AES256_GCM,data:H3xdtb9TA/VStpOzLxboPTck0iasvAAS77hVFQOI1hmIwwYNYuRXTWb9N0M9kBEv/ho=,iv:PkLd3iHLzjnsPZtfQq/LJcwHQDm+gyxQJX/jWrpRmUw=,tag:qHtHvotCqr4IGs0vi5AOhw==,type:comment]
secret_key: ENC[AES256_GCM,data:h1TOZGnV4yBX/wFVlpyxP/KhtKbjqpvxWL7/bxONfoi3PQMtkQfwWbjd/FTC72XyCAHO/yDsCtHRQjPQcyeXmw==,iv:XgdO/i8FKBCYsRfFc5JAg+9yA3TbreIJw4J8p0xif0s=,tag:TgrJREyZuc7cdUcru1Qk0w==,type:str]
#ENC[AES256_GCM,data:43sjaBcdtJol6ySQKUuhZfSM4TvS6HLrjI/CLSlFcBfIYIe8UoPK6ZSsG7u3knVc58u8YreH,iv:aHaCmk5lr05PbXAKASPy22t88f//LOEVgSRzbZ6KKow=,tag:U3wsAmEwbaKUzjwdp6ekcg==,type:comment]
internal_token: ENC[AES256_GCM,data:tFzyCj02HXauxCqKFsZD0CB/W4FAxv4t0KSIZPPXV6a2N6PdDuL0W5+Wdd9O17E/Pa8mrourwjpqipON+FUNARp4bLsFp1bgBPeq52BLS1neSXC1YrxsO3W9/12Y5wpXI5mz7WwVJUvt,iv:uyxZlZ8vVnwkQBwNvPLgbeomyhx/lfSgi5xJyB2LLb8=,tag:oXfWY1wGL3NvlpfeGyIWxg==,type:str]
#ENC[AES256_GCM,data:8sFQ0j8jmDAmnl5FD6FFtHv6t34rFVu9O658hlGktKKFDpgXnj/IIaelvqSrsSlS6nA=,iv:HWYldmocbK/auGAXB/01zmC/vC58Z/2UYla6CFoaAL8=,tag:3dhcO0ip/w54Cf2pHwXqiQ==,type:comment]
jwt_secret: ENC[AES256_GCM,data:uIIHBk3m5DNHXRJ7pyg0Xvz1cxUFqfxUzFtBZGY59E4dPj9qHHe3RC7jEg==,iv:krZHjrU3QziSuHihpVLHaSIzHU5VZ1UUBeLBd3kWW3Y=,tag:3Z0UCV9+9nc+FU9vXFutbQ==,type:str]
lfs_jwt_secret: ENC[AES256_GCM,data:LGemlQqpCwy1HlQI3BfW6Qir8cjYgtpoyFkoKhYgGR5x+F3shCaiUNEwFA==,iv:3C3S4gUpk1szU/7Dg9RObpv3/DMpzCpFg3qyrfFMot0=,tag:dwIRfA6PoQo09+YEs6o8fg==,type:str]
pocket_id:
client_id: ENC[AES256_GCM,data:0aju1RTsGGpKRWHoBIydKUzijX5iHYWlAW/q5Ykam1WUs+py,iv:pkcZrlE1OZnEUZPnveWWkShA225tinm0eDIpmg1YbWY=,tag:vz168jIJzbJ7+DrZzn4BmA==,type:str]
client_secret: ENC[AES256_GCM,data:dXqdSqwc6aDmWOD3sYla0KWdk3CUQxLpKaQ0b5uozRI=,iv:N/LHumamZMqtqOdx3Mmj25zlsvYfriYahdxtd/goCAk=,tag:kYjcXzwrsnTN5pBGfDi1Yw==,type:str]
restic_password: ENC[AES256_GCM,data:4OOYu5+BabBtRkGjvXwIAxb+L5H3ADkqTWZFwSKIV0eOhRvNfBTlL7HBvvMCFXcP,iv:wBmht7AbnZwcKV3vBygrcuV02KoCStVn3AYt3iLOBpI=,tag:cMcCqwb6wPMm9ZKk59me4A==,type:str]
sops:
age:
- recipient: age1ykcs39e62pz3xu6cedg8ea685kv5d5qsrhgkndygzm8rx30xd5ys5t3qxt
enc: |
- enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSA5QThHOFdVQ0F6ZDE3QXdL
QVF0WW5yRkNtNXIyRm1LeEhwY2dRRWo0WENZCmZoWmlXZDh4ZGlUR2JYOUxuaVAx
WjhXVHBMNWdrdkgvTENJR2RpWldkNTAKLS0tIEF1bS9JSnFTbytBa1U5RjVzWkd3
S0pKVVI2RFN5a1BMYXBEY3VOUUM5QTAKNarYZm9DKRQhosSJBn9yryFxDkmFTV/o
i8b/tZ1ZybjEXX+X1EsgylM5u8iKkbEyUzqKO0E0gpg4qXSsJaMMYQ==
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBVV2FrSURwdEozZ0l6MjRJ
VWU4YTVVMmN1OHNEWWJ1RmJrU1ltcFhGVW00CkFTWDRtYWtKSFRBcVRKZXZtUCtQ
Zi9pa21BcGJaMmJTa3Jab1VRUW5LVUUKLS0tIHlUY2d3OXVVTDY4UDhOamYrSnNW
R1orWGIwUFpPVnpQRUFuNm00OEZ5MWsKwH1QahhZWw4aUbAcST+fL2HefrJdKktD
G5sLmNPa3aEKx0Y3CSIvgww23iQYw31iXJS9sVcPyMVt99YP21KbvA==
-----END AGE ENCRYPTED FILE-----
- recipient: age1h0prahyukq4l564yqwgcpg3g6gdrjflk0suklussjjrjstxd9uesws8633
enc: |
recipient: age1p4gyh5260ewp7t2ctzv5ewj4a06szl389fm4gzy6vltxhjj73ers87u33g
- enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBhdEN2M1lkMFoyQzg3bCsz
cVB0NUlkV1JPRjQ1TW5RSVFHUjdNMERoRXlzCk9tc25iMG00TkZjWjk2S2cyVE1J
cUFITDh2SkZGN0lpeWJVcWM3V3JrTTQKLS0tIENOWVBzTFYrdHRsMERwV0RKS01j
QVI5TVl4L0dwOWpoQ1I2THZ6cWovWGMKIo1x1ZbdTyr/dNlPhvuomfk2MoPLsHyU
N3CP3Scu3aZ7vqVua7uwtv4xQqyQI/yOnFjwxrVYPJ+N5Y/b4wsC6A==
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBReFNXY3c0UnZ3cGZnbnFO
K3dZS2w4S0UzeFE4YXg0V3BjbzNISm8xdWdZCkc4NUdBMktMbStSZkFtTFBHcGNQ
eDdlQXRXb3NKaUtLWXlqN0txOGxoMTgKLS0tIEZPV1BCWUFRaldIMDlSRXZzMmtN
aW14MnNtZVM0M0M0ajk2UElCWklhaVUKZewlYVMefFqC+ddzrgmAXVTiuBqhhxEL
Q3cUhxGk5DUhCn30ia/ztQIb79kVBrdhY6zA2bKcBdYH4HSzV+rNAA==
-----END AGE ENCRYPTED FILE-----
- recipient: age1gvplss0ddmyf6vpjy363wu3n057vhm0j6n7tc94cxd8kadapypws5mtaj0
enc: |
recipient: age1ykcs39e62pz3xu6cedg8ea685kv5d5qsrhgkndygzm8rx30xd5ys5t3qxt
- enc: |
-----BEGIN AGE ENCRYPTED FILE-----
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBGSGQvL2ZYM2dtV1JWaDR1
RjJnN0YwWFM4d1IwTElqUnZQQkVDTmdydUJjCjdCUWxCVDNXUHVLd2ZHcDA5L0Mw
cEVxVE84L2xmQnRoYmsxVEdMSEZjdGcKLS0tIHViRVJyTWt4Q3JrMWtYaS9QdHlS
Yjd0MUcxcExvWVpCOUR3MkdZdGQyWUkKnru0Y2A98+0Mps7EtVK7ct3vPqIGveUt
E5fzpcKvdefzObrx7BPTwJ19t2fZg/dSi7HKwx3vmKZSzyQaqJOzsg==
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBhbVRyNmN3WU5SbTNtbzZV
cGoybXo0dWtpRDNkR2drZTN0VFhoQ0REQ0ZvCkNSSm9hbmZDNUsxTjBGWm5QL3M2
VElMSi8ybFRVM3hpNUlYdVAyME1RTUEKLS0tIGJVRis5WkRDRkxCVVdJVENlZ3Ru
aGw3cW51Vno4emFMckxqRTVGcGhoemcK4WBC2EZEx7hVlUQnsD4V5QH9peNjUoWE
XjCvw0twhPRi9uXd4HmHqlDpxdGMk0oFQ77O7h7Q3z2uqsJ2v8p/SA==
-----END AGE ENCRYPTED FILE-----
lastmodified: "2026-04-04T23:18:43Z"
mac: ENC[AES256_GCM,data:qBgeli5lHb4pyA8nAADBuRBAaq8VbAIsFI37OZtgnbnoHW2crxo3YC+EknaIYnZpZ48kwVhQS5lGRjI6JsWWhTH3+LVAhTmS2Qj/pZTD/JDLK6XJGXS4U9nB7m9aGYyW8gFCy9/DfoJWGsS//+ZmUikKPfd5kMZgh1zGoYCIGug=,iv:h+2fA+bO2SMCNrEslP36x3BPRaIy25cU/DNX8CYSC6A=,tag:RvVyUZ4ONRaKaqGiT31eUQ==,type:str]
recipient: age1gvplss0ddmyf6vpjy363wu3n057vhm0j6n7tc94cxd8kadapypws5mtaj0
lastmodified: "2026-07-10T04:31:57Z"
mac: ENC[AES256_GCM,data:uytG0nhJ/Gp0KbOovD1SVXx0G27e12gMPwmpkU0lPW01cAXNe0rv4SjhHGP0FOR6vLimcPAmekVjVqiKxie8Zevo/Jf9ZRTkQ6ixWLvhH2NMHra4T5TWtUjfMdFM8tiilwcvjsXpqAoaJDZ0HHY5NYhXG/khobAwBRc26RtICVw=,iv:6gB28VE17+NoM/tR9lIlJoMPD91Aud+kH95Vo+fWLjs=,tag:QMUQPsCnr1TUsQE66GVBBg==,type:str]
unencrypted_suffix: _unencrypted
version: 3.12.2
version: 3.13.1
-31
View File
@@ -1,31 +0,0 @@
{ inputs, ... }:
let
username = "john";
hostname = "test-nix";
in
{
flake.nixosConfigurations."${hostname}" = inputs.nixpkgs.lib.nixosSystem {
modules = with inputs.self.modules; [
nixos.lxc
nixos.mysops
nixos.step-ssh-host
inputs.home-manager.nixosModules.home-manager
nixos."${username}"
nixos.docker
{
step-ssh-host.hostname = hostname;
sops.defaultSopsFile = ../../keys/secrets.yaml;
home-manager.users."${username}" = {
imports = with inputs.self.modules.homeManager; [
mysops
];
docker.enable = true;
ssh.matchSets = {
certs = true;
homelab = true;
};
};
}
];
};
}
+15 -3
View File
@@ -9,14 +9,18 @@
# homeImports ? [ ],
# homePackages ? [ ],
}: {
nixos."${username}" = { config, lib, pkgs, ... }: {
nixos."${username}" = { config, lib, pkgs, ... }:
let
jslZsh = inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.jsl-zsh;
jslZshExe = lib.getExe' jslZsh "jsl-zsh";
in {
imports = [
inputs.home-manager.nixosModules.home-manager
];
environment.shells = [
"${lib.getExe pkgs.zsh}"
"${lib.getExe inputs.self.packages.${pkgs.stdenv.hostPlatform.system}.jsl-zsh}"
jslZshExe
];
users.groups."${username}" = {};
@@ -25,7 +29,7 @@
isNormalUser = true;
group = username;
home = "/home/${username}";
shell = pkgs.zsh;
shell = jslZshExe;
extraGroups = [ "input" "networkmanager" "video" "render" ]
++ lib.optional isAdmin "wheel"
++ lib.optional config.virtualisation.docker.enable "docker"
@@ -38,6 +42,14 @@
security.sudo-rs.enable = lib.mkIf isAdmin true;
home-manager.useGlobalPkgs = true;
# DetNix warns when HM generates options.json for manuals; disable manual outputs.
home-manager.sharedModules = [
{
manual.manpages.enable = false;
manual.html.enable = false;
manual.json.enable = false;
}
];
# https://github.com/Doc-Steve/dendritic-design-with-flake-parts/wiki/Dendritic_Aspects#multi-context-aspect
home-manager.users."${username}" = {
imports = [ self.modules.homeManager."${username}" ];
+1 -1
View File
@@ -2,7 +2,7 @@
flake.modules.nixos.login-text = { config, lib, ... }:
let
defaultServiceStatus = {
SSH = "sshd.socket";
"SSH Socket" = "sshd.socket";
"SSH Cert Renewal" = "ssh-certs-renew.timer";
};
in {
+4 -4
View File
@@ -15,14 +15,14 @@
nix.settings.experimental-features = [ "nix-command" "flakes" ];
environment.systemPackages = with pkgs; [
git
zsh
selfPackages.jsl-zsh-tty
];
environment.shells = lib.mkAfter [
rootShellPath
];
environment.shells = lib.mkAfter [ rootShellPath ];
users.users.root.shell = lib.mkForce rootShellPath;
networking.nameservers = [ "192.168.1.150" ];
networking.dhcpcd.extraConfig = "nohook resolv.conf";
# security.sudo-rs.enable = true;
programs.nix-ld.enable = true;
nix.optimise.automatic = true;
+4
View File
@@ -16,5 +16,9 @@
[[ssh-keys]]
vault = "Private"
'';
programs.ssh.settings."*" = {
IdentityAgent = "${config.home.homeDirectory}/.1password/agent.sock";
};
};
}
+3 -2
View File
@@ -35,9 +35,10 @@ in
config =
let
identityFile = "${config.home.homeDirectory}/.ssh/${config.ssh-new.user.keyFile}";
my-sops = (inputs.self.wrappers.mySops.apply {
inherit pkgs;
sshKey = config.ssh.identityFile;
sshKey = identityFile;
}).wrapper;
in
{
@@ -46,7 +47,7 @@ in
sops = {
defaultSopsFile = ../../keys/secrets.yaml;
defaultSopsFormat = "yaml";
age.sshKeyPaths = [ "${config.ssh.identityFile}" ];
age.sshKeyPaths = [ identityFile ];
};
home.packages = with pkgs; [
-249
View File
@@ -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";
};
})
];
};
};
};
}
+28 -69
View File
@@ -2,41 +2,33 @@
flake.modules.nixos.ssh-certs = { config, pkgs, lib, ... }:
let
cfg = config.ssh-certs;
provisionerPasswordPath = config.sops.secrets."janus/admin_jwk".path;
wrappers = inputs.self.wrappers;
sshKeyPath = "/etc/ssh/ssh_host_ed25519_key";
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
${lib.getExe' pkgs.openssh "ssh-keygen"} -y -f "${sshKeyPath}" > "${sshKeyPath}.pub"
chmod 0644 "${sshKeyPath}.pub"
fi
${lib.getExe pkgs.step-cli} ssh certificate \
--host --sign \
--provisioner "${cfg.provisioner}" \
--provisioner-password-file "${provisionerPasswordPath}" \
${principalArgs} \
"${cfg.hostname}" "${sshKeyPath}.pub"
'';
sshHostCertCheck = pkgs.writeShellScriptBin "ssh-host-cert-check" ''
${lib.getExe' pkgs.openssh "ssh-keygen"} -Lf ${sshCertPath}
'';
sshHostCertSign = (wrappers.signHostWrapper.apply {
inherit pkgs;
inherit (cfg) provisioner extraPrincipals;
provisionerPasswordFile = config.sops.secrets."janus/admin_jwk".path;
}).wrapper;
sshHostCertRenew = (wrappers.renewHostWrapper.apply {
inherit pkgs;
sshHostKeyFile = sshKeyPath;
overwrite = true;
}).wrapper;
sshHostCertCheck = (wrappers.hostCheckWrapper.apply {
inherit pkgs;
certPath = sshCertPath;
}).wrapper;
sshHostRenewalCheck = (wrappers.renewalCheck.apply {
inherit pkgs;
certPath = sshCertPath;
expires-in = "4h";
}).wrapper;
in
{
# NixOS Options
options.ssh-certs = {
hostname = lib.mkOption {
description = "Networking host name to register with the CA";
type = lib.types.str;
};
provisioner = lib.mkOption {
description = "Provisioner inside Step CA to use for the SSH certificates";
type = lib.types.str;
@@ -49,11 +41,11 @@
};
};
imports = with inputs.self.modules.nixos; [ ssh ];
# imports = with inputs.self.modules.nixos; [ ssh ];
# NixOS Config
config = {
ssh.certificates.enable = true;
# ssh.certificates.enable = true;
sops.secrets."janus/admin_jwk" = {
# Shared provisioner credential is intentionally centralized.
sopsFile = ../../../keys/secrets.yaml;
@@ -64,59 +56,30 @@
networking.nameservers = [ "192.168.1.150" ];
networking.dhcpcd.extraConfig = "nohook resolv.conf";
environment.systemPackages = [
sshHostCertSign
sshHostCertRenew
sshHostRenewalCheck
sshHostCertCheck
];
systemd.services.ssh-certs-renew = {
description = "Renew Step SSH host certificate if needed";
description = "SSH host certificate renewal";
wantedBy = [ "multi-user.target" ];
before = [ "sshd.service" ];
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
path = with pkgs; [ coreutils systemd step-cli openssh ];
path = with pkgs; [ step-cli systemd ];
serviceConfig = {
Type = "oneshot";
User = "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 = {
description = "Periodic Step SSH host certificate renewal";
wantedBy = [ "timers.target" ];
timerConfig = {
OnBootSec = "5m";
OnUnitActiveSec = "4h";
@@ -125,10 +88,6 @@
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" ];
};
};
}
+28 -26
View File
@@ -16,44 +16,46 @@ in
authorizedKeys = [
# Shared keys for every host can go here.
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIIAUa4dcg1TWc4pW++uodyhX4eOqrX/QYIxFWtEP7HFJ john@john-pc-ubuntu"
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFn5ilhqaeDsOWSk7y29se2NvxGm8djlfL3RGLokj0q6 john@john-p14s"
];
};
flake.modules = {
nixos."${username}" = { config, pkgs, ... }: {
nixos."${username}" = { config, pkgs, ... }: let
selfMeta = inputs.self.meta.users."${username}";
in {
imports = [
baseUserModules.nixos."${username}"
];
users.users."${username}" = {
openssh.authorizedKeys.keys = inputs.self.meta.users."${username}".authorizedKeys;
openssh.authorizedKeys.keys = selfMeta.authorizedKeys;
};
};
# This module will be imported by the user factory
homeManager."${username}" = { pkgs, ... }:
with inputs.self.meta.users."${username}";
let
selfPkgs = inputs.self.packages.${pkgs.stdenv.hostPlatform.system};
in {
home.stateVersion = "25.11";
imports = [
inputs.self.modules.homeManager.shell-tools
inputs.self.modules.homeManager.ssh
inputs.self.modules.homeManager.git
];
xdg.enable = true;
home.packages = [
selfPkgs.neovim-min
];
home.sessionVariables = {
EDITOR = "nvim";
VISUAL = "nvim";
GIT_EDITOR = "nvim";
SOPS_EDITOR = "nvim";
};
programs.git.settings.user.name = name;
programs.git.settings.user.email = email;
programs.git.settings.core.editor = "nvim";
homeManager."${username}" = { pkgs, ... }: let
selfMeta = inputs.self.meta.users."${username}";
selfPkgs = inputs.self.packages.${pkgs.stdenv.hostPlatform.system};
in {
home.stateVersion = "25.11";
imports = with inputs.self.modules.homeManager; [
ssh-new
shell-tools
git
];
xdg.enable = true;
home.packages = [
selfPkgs.neovim-min
];
home.sessionVariables = {
EDITOR = "nvim";
VISUAL = "nvim";
GIT_EDITOR = "nvim";
SOPS_EDITOR = "nvim";
};
programs.git.settings.user.name = selfMeta.name;
programs.git.settings.user.email = selfMeta.email;
programs.git.settings.core.editor = "nvim";
};
};
}