1 { config, lib, pkgs, ... }:
6 cfg = config.services.endlessh-go;
9 options.services.endlessh-go = {
10 enable = mkEnableOption "endlessh-go service";
12 package = mkPackageOption pkgs "endlessh-go" { };
14 listenAddress = mkOption {
19 Interface address to bind the endlessh-go daemon to SSH connections.
28 Specifies on which port the endlessh-go daemon listens for SSH
31 Setting this to `22` may conflict with {option}`services.openssh`.
36 enable = mkEnableOption "Prometheus integration";
38 listenAddress = mkOption {
43 Interface address to bind the endlessh-go daemon to answer Prometheus
53 Specifies on which port the endlessh-go daemon listens for Prometheus
59 extraOptions = mkOption {
60 type = with types; listOf str;
62 example = [ "-conn_type=tcp4" "-max_clients=8192" ];
64 Additional command line options to pass to the endlessh-go daemon.
68 openFirewall = mkOption {
72 Whether to open a firewall port for the SSH listener.
77 config = mkIf cfg.enable {
78 systemd.services.endlessh-go = {
79 description = "SSH tarpit";
80 requires = [ "network.target" ];
81 wantedBy = [ "multi-user.target" ];
84 needsPrivileges = cfg.port < 1024 || cfg.prometheus.port < 1024;
85 capabilities = [ "" ] ++ optionals needsPrivileges [ "CAP_NET_BIND_SERVICE" ];
86 rootDirectory = "/run/endlessh-go";
90 ExecStart = with cfg; concatStringsSep " " ([
91 (lib.getExe cfg.package)
93 "-host=${listenAddress}"
94 "-port=${toString port}"
95 ] ++ optionals prometheus.enable [
97 "-prometheus_host=${prometheus.listenAddress}"
98 "-prometheus_port=${toString prometheus.port}"
101 RootDirectory = rootDirectory;
102 BindReadOnlyPaths = [ builtins.storeDir ];
103 InaccessiblePaths = [ "-+${rootDirectory}" ];
104 RuntimeDirectory = baseNameOf rootDirectory;
105 RuntimeDirectoryMode = "700";
106 AmbientCapabilities = capabilities;
107 CapabilityBoundingSet = capabilities;
109 LockPersonality = true;
110 MemoryDenyWriteExecute = true;
111 NoNewPrivileges = true;
112 PrivateDevices = true;
114 PrivateUsers = !needsPrivileges;
116 ProtectControlGroups = true;
118 ProtectHostname = true;
119 ProtectKernelLogs = true;
120 ProtectKernelModules = true;
121 ProtectKernelTunables = true;
122 ProtectSystem = "strict";
123 ProtectProc = "noaccess";
126 RestrictAddressFamilies = [ "AF_INET" "AF_INET6" ];
127 RestrictNamespaces = true;
128 RestrictRealtime = true;
129 RestrictSUIDSGID = true;
130 SystemCallArchitectures = "native";
131 SystemCallFilter = [ "@system-service" "~@privileged" ];
135 networking.firewall.allowedTCPPorts = with cfg;
136 optionals openFirewall [ port ];
139 meta.maintainers = with maintainers; [ azahi ];