1 { config, lib, pkgs, ... }:
6 cfg = config.services.endlessh;
9 options.services.endlessh = {
10 enable = mkEnableOption "endlessh service";
17 Specifies on which port the endlessh daemon listens for SSH
20 Setting this to `22` may conflict with {option}`services.openssh`.
24 extraOptions = mkOption {
25 type = with types; listOf str;
27 example = [ "-6" "-d 9000" "-v" ];
29 Additional command line options to pass to the endlessh daemon.
33 openFirewall = mkOption {
37 Whether to open a firewall port for the SSH listener.
42 config = mkIf cfg.enable {
43 systemd.services.endlessh = {
44 description = "SSH tarpit";
45 requires = [ "network.target" ];
46 wantedBy = [ "multi-user.target" ];
49 needsPrivileges = cfg.port < 1024;
50 capabilities = [ "" ] ++ optionals needsPrivileges [ "CAP_NET_BIND_SERVICE" ];
51 rootDirectory = "/run/endlessh";
55 ExecStart = with cfg; concatStringsSep " " ([
56 "${pkgs.endlessh}/bin/endlessh"
60 RootDirectory = rootDirectory;
61 BindReadOnlyPaths = [ builtins.storeDir ];
62 InaccessiblePaths = [ "-+${rootDirectory}" ];
63 RuntimeDirectory = baseNameOf rootDirectory;
64 RuntimeDirectoryMode = "700";
65 AmbientCapabilities = capabilities;
66 CapabilityBoundingSet = capabilities;
68 LockPersonality = true;
69 MemoryDenyWriteExecute = true;
70 NoNewPrivileges = true;
71 PrivateDevices = true;
73 PrivateUsers = !needsPrivileges;
75 ProtectControlGroups = true;
77 ProtectHostname = true;
78 ProtectKernelLogs = true;
79 ProtectKernelModules = true;
80 ProtectKernelTunables = true;
81 ProtectSystem = "strict";
82 ProtectProc = "noaccess";
85 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
86 RestrictNamespaces = true;
87 RestrictRealtime = true;
88 RestrictSUIDSGID = true;
89 SystemCallArchitectures = "native";
90 SystemCallFilter = [ "@system-service" "~@resources" "~@privileged" ];
94 networking.firewall.allowedTCPPorts = with cfg;
95 optionals openFirewall [ port ];
98 meta.maintainers = with maintainers; [ azahi ];