@@ -47,6 +47,9 @@ let
|
|||||||
|
|
||||||
mkSocatService =
|
mkSocatService =
|
||||||
port: proto:
|
port: proto:
|
||||||
|
let
|
||||||
|
isPrivileged = port < 1024;
|
||||||
|
in
|
||||||
lib.nameValuePair "socat-${proto}-${toString port}" {
|
lib.nameValuePair "socat-${proto}-${toString port}" {
|
||||||
description = "Socat ${proto} proxy for port ${toString port}";
|
description = "Socat ${proto} proxy for port ${toString port}";
|
||||||
after = [
|
after = [
|
||||||
@@ -63,7 +66,12 @@ let
|
|||||||
"${pkgs.socat}/bin/socat TCP-LISTEN:${toString port},fork,reuseaddr TCP:${upstream}:${toString port}";
|
"${pkgs.socat}/bin/socat TCP-LISTEN:${toString port},fork,reuseaddr TCP:${upstream}:${toString port}";
|
||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
RestartSec = "5s";
|
RestartSec = "5s";
|
||||||
|
}
|
||||||
|
// lib.optionalAttrs (!isPrivileged) {
|
||||||
DynamicUser = true;
|
DynamicUser = true;
|
||||||
|
}
|
||||||
|
// lib.optionalAttrs isPrivileged {
|
||||||
|
User = "nobody";
|
||||||
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
|
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
|
||||||
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
|
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user