Merge pull request #253764 from linj-fork/fix-ping-wrapper

nixos/network-interfaces: stop wrapping ping with cap_net_raw
This commit is contained in:
Martin Weinelt 2023-10-20 00:57:55 +02:00 committed by GitHub
commit d042a29613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 9 additions and 34 deletions

View File

@ -69,4 +69,4 @@ do:
`/etc/group` and `/etc/shadow`. This also creates home directories `/etc/group` and `/etc/shadow`. This also creates home directories
- `usrbinenv` creates `/usr/bin/env` - `usrbinenv` creates `/usr/bin/env`
- `var` creates some directories in `/var` that are not service-specific - `var` creates some directories in `/var` that are not service-specific
- `wrappers` creates setuid wrappers like `ping` and `sudo` - `wrappers` creates setuid wrappers like `sudo`

View File

@ -2,10 +2,4 @@
let apparmor = config.security.apparmor; in let apparmor = config.security.apparmor; in
{ {
config.security.apparmor.packages = [ pkgs.apparmor-profiles ]; config.security.apparmor.packages = [ pkgs.apparmor-profiles ];
config.security.apparmor.policies."bin.ping".profile = lib.mkIf apparmor.policies."bin.ping".enable ''
include "${pkgs.iputils.apparmor}/bin.ping"
include "${pkgs.inetutils.apparmor}/bin.ping"
# Note that including those two profiles in the same profile
# would not work if the second one were to re-include <tunables/global>.
'';
} }

View File

@ -588,11 +588,12 @@ in {
"~@privileged" "~@privileged"
] ++ optionals (any useComponent componentsUsingPing) [ ] ++ optionals (any useComponent componentsUsingPing) [
"capset" "capset"
"setuid"
]; ];
UMask = "0077"; UMask = "0077";
}; };
path = [ path = [
"/run/wrappers" # needed for ping pkgs.unixtools.ping # needed for ping
]; ];
}; };

View File

@ -1406,28 +1406,6 @@ in
val = tempaddrValues.${opt}.sysctl; val = tempaddrValues.${opt}.sysctl;
in nameValuePair "net.ipv6.conf.${replaceStrings ["."] ["/"] i.name}.use_tempaddr" val)); in nameValuePair "net.ipv6.conf.${replaceStrings ["."] ["/"] i.name}.use_tempaddr" val));
security.wrappers = {
ping = {
owner = "root";
group = "root";
capabilities = "cap_net_raw+p";
source = "${pkgs.iputils.out}/bin/ping";
};
};
security.apparmor.policies."bin.ping".profile = lib.mkIf config.security.apparmor.policies."bin.ping".enable (lib.mkAfter ''
/run/wrappers/bin/ping {
include <abstractions/base>
include <nixos/security.wrappers/ping>
rpx /run/wrappers/wrappers.*/ping,
}
/run/wrappers/wrappers.*/ping {
include <abstractions/base>
include <nixos/security.wrappers/ping>
capability net_raw,
capability setpcap,
}
'');
# Set the host and domain names in the activation script. Don't # Set the host and domain names in the activation script. Don't
# clear it if it's not configured in the NixOS configuration, # clear it if it's not configured in the NixOS configuration,
# since it may have been set by dhcpcd in the meantime. # since it may have been set by dhcpcd in the meantime.

View File

@ -169,7 +169,7 @@ import ./make-test-python.nix ({ pkgs, ... }: {
# Do some IP traffic # Do some IP traffic
output_ping = machine.succeed( output_ping = machine.succeed(
"systemd-run --wait -- /run/wrappers/bin/ping -c 1 127.0.0.1 2>&1" "systemd-run --wait -- ping -c 1 127.0.0.1 2>&1"
) )
with subtest("systemd reports accounting data on system.slice"): with subtest("systemd reports accounting data on system.slice"):

View File

@ -21,6 +21,7 @@
, openldap , openldap
, procps , procps
, runtimeShell , runtimeShell
, unixtools
}: }:
let let
@ -33,6 +34,7 @@ let
lm_sensors lm_sensors
net-snmp net-snmp
procps procps
unixtools.ping
]; ];
mailq = runCommand "mailq-wrapper" { preferLocalBuild = true; } '' mailq = runCommand "mailq-wrapper" { preferLocalBuild = true; } ''
@ -58,7 +60,7 @@ stdenv.mkDerivation rec {
sha256 = "sha256-yLhHOSrPFRjW701aOL8LPe4OnuJxL6f+dTxNqm0evIg="; sha256 = "sha256-yLhHOSrPFRjW701aOL8LPe4OnuJxL6f+dTxNqm0evIg=";
}; };
# TODO: Awful hack. Grrr... this of course only works on NixOS. # TODO: Awful hack. Grrr...
# Anyway the check that configure performs to figure out the ping # Anyway the check that configure performs to figure out the ping
# syntax is totally impure, because it runs an actual ping to # syntax is totally impure, because it runs an actual ping to
# localhost (which won't work for ping6 if IPv6 support isn't # localhost (which won't work for ping6 if IPv6 support isn't
@ -74,8 +76,8 @@ stdenv.mkDerivation rec {
-e 's|^DEFAULT_PATH=.*|DEFAULT_PATH=\"${binPath}\"|' -e 's|^DEFAULT_PATH=.*|DEFAULT_PATH=\"${binPath}\"|'
configureFlagsArray+=( configureFlagsArray+=(
--with-ping-command='/run/wrappers/bin/ping -4 -n -U -w %d -c %d %s' --with-ping-command='ping -4 -n -U -w %d -c %d %s'
--with-ping6-command='/run/wrappers/bin/ping -6 -n -U -w %d -c %d %s' --with-ping6-command='ping -6 -n -U -w %d -c %d %s'
) )
install -Dm555 ${share} $out/share install -Dm555 ${share} $out/share