Skip to content

Commit

Permalink
treewide: Remove ineffective capability grants. (#333533)
Browse files Browse the repository at this point in the history
  • Loading branch information
fpletz authored Nov 6, 2024
2 parents 9c87fcc + cb10fe8 commit 0fc41ad
Show file tree
Hide file tree
Showing 12 changed files with 2 additions and 27 deletions.
8 changes: 2 additions & 6 deletions nixos/modules/services/misc/mollysocket.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }:

let
inherit (lib) getExe mkIf mkOption mkEnableOption optionals types;
inherit (lib) getExe mkIf mkOption mkEnableOption types;

cfg = config.services.mollysocket;
configuration = format.generate "mollysocket.conf" cfg.settings;
Expand Down Expand Up @@ -85,9 +85,7 @@ in {
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
environment.RUST_LOG = cfg.logLevel;
serviceConfig = let
capabilities = [ "" ] ++ optionals (cfg.settings.port < 1024) [ "CAP_NET_BIND_SERVICE" ];
in {
serviceConfig = {
EnvironmentFile = cfg.environmentFile;
ExecStart = "${getExe package} server";
KillSignal = "SIGINT";
Expand All @@ -97,8 +95,6 @@ in {
WorkingDirectory = "/var/lib/mollysocket";

# hardening
AmbientCapabilities = capabilities;
CapabilityBoundingSet = capabilities;
DevicePolicy = "closed";
DynamicUser = true;
LockPersonality = true;
Expand Down
3 changes: 0 additions & 3 deletions nixos/modules/services/misc/paperless.nix
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,6 @@ in
SystemCallFilter = defaultServiceConfig.SystemCallFilter ++ [ "@setuid mbind" ];
# Needs to serve web page
PrivateNetwork = false;
} // lib.optionalAttrs (cfg.port < 1024) {
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
};
environment = env // {
PYTHONPATH = "${cfg.package.python.pkgs.makePythonPath cfg.package.propagatedBuildInputs}:${cfg.package}/lib/paperless-ngx/src";
Expand Down
3 changes: 0 additions & 3 deletions nixos/modules/services/misc/tandoor-recipes.nix
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,6 @@ in
# gunicorn needs setuid
SystemCallFilter = [ "@system-service" "~@privileged" "@resources" "@setuid" "@keyring" ];
UMask = "0066";
} // lib.optionalAttrs (cfg.port < 1024) {
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
};

wantedBy = [ "multi-user.target" ];
Expand Down
1 change: 0 additions & 1 deletion nixos/modules/services/misc/transfer-sh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ in
wantedBy = [ "multi-user.target" ];
environment = mapAttrs (_: v: if isBool v then boolToString v else toString v) cfg.settings;
serviceConfig = {
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
DevicePolicy = "closed";
DynamicUser = true;
ExecStart = "${getExe cfg.package} --provider ${cfg.provider}";
Expand Down
1 change: 0 additions & 1 deletion nixos/modules/services/misc/wastebin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ in
wantedBy = [ "multi-user.target" ];
environment = mapAttrs (_: v: if isBool v then boolToString v else toString v) cfg.settings;
serviceConfig = {
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
DevicePolicy = "closed";
DynamicUser = true;
ExecStart = "${getExe cfg.package}";
Expand Down
2 changes: 0 additions & 2 deletions nixos/modules/services/monitoring/prometheus/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -1834,8 +1834,6 @@ in
StateDirectory = cfg.stateDir;
StateDirectoryMode = "0700";
# Hardening
AmbientCapabilities = lib.mkIf (cfg.port < 1024) [ "CAP_NET_BIND_SERVICE" ];
CapabilityBoundingSet = if (cfg.port < 1024) then [ "CAP_NET_BIND_SERVICE" ] else [ "" ];
DeviceAllow = [ "/dev/null rw" ];
DevicePolicy = "strict";
LockPersonality = true;
Expand Down
2 changes: 0 additions & 2 deletions nixos/modules/services/web-apps/dex.nix
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ in
];

RuntimeDirectory = "dex";
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
BindReadOnlyPaths = [
"/nix/store"
"-/etc/dex"
Expand All @@ -91,7 +90,6 @@ in
"-/etc/ssl/certs/ca-certificates.crt"
];
BindPaths = optional (cfg.settings.storage.type == "postgres") "/var/run/postgresql";
CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
# ProtectClock= adds DeviceAllow=char-rtc r
DeviceAllow = "";
DynamicUser = true;
Expand Down
1 change: 0 additions & 1 deletion nixos/modules/services/web-apps/freshrss.nix
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ in
let
defaultServiceConfig = {
ReadWritePaths = "${cfg.dataDir}";
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
DeviceAllow = "";
LockPersonality = true;
NoNewPrivileges = true;
Expand Down
1 change: 0 additions & 1 deletion nixos/modules/services/web-apps/microbin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ in
wantedBy = [ "multi-user.target" ];
environment = lib.mapAttrs (_: v: if lib.isBool v then lib.boolToString v else toString v) cfg.settings;
serviceConfig = {
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
DevicePolicy = "closed";
DynamicUser = true;
EnvironmentFile = lib.optional (cfg.passwordFile != null) cfg.passwordFile;
Expand Down
4 changes: 0 additions & 4 deletions nixos/modules/services/web-apps/photoprism.nix
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ in
LoadCredential = lib.optionalString (cfg.passwordFile != null)
"PHOTOPRISM_ADMIN_PASSWORD:${cfg.passwordFile}";

CapabilityBoundingSet = "";
LockPersonality = true;
PrivateDevices = true;
PrivateUsers = true;
Expand All @@ -126,9 +125,6 @@ in
SystemCallArchitectures = "native";
SystemCallFilter = [ "@system-service" "~@setuid @keyring" ];
UMask = "0066";
} // lib.optionalAttrs (cfg.port < 1024) {
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
CapabilityBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
};

wantedBy = [ "multi-user.target" ];
Expand Down
2 changes: 0 additions & 2 deletions nixos/modules/services/web-apps/powerdns-admin.nix
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ in
User = "powerdnsadmin";
Group = "powerdnsadmin";

AmbientCapabilities = "CAP_NET_BIND_SERVICE";
BindReadOnlyPaths = [
"/nix/store"
"-/etc/resolv.conf"
Expand All @@ -97,7 +96,6 @@ in
]
++ (optional (cfg.secretKeyFile != null) cfg.secretKeyFile)
++ (optional (cfg.saltFile != null) cfg.saltFile);
CapabilityBoundingSet = "CAP_NET_BIND_SERVICE";
# ProtectClock= adds DeviceAllow=char-rtc r
DeviceAllow = "";
# Implies ProtectSystem=strict, which re-mounts all paths
Expand Down
1 change: 0 additions & 1 deletion nixos/modules/services/web-apps/shiori.nix
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ in {
"/var/run/mysqld";

CapabilityBoundingSet = "";
AmbientCapabilities = "CAP_NET_BIND_SERVICE";

DeviceAllow = "";

Expand Down

0 comments on commit 0fc41ad

Please sign in to comment.