diff options
author | Julien Moutinho <julm+nixpkgs@sourcephile.fr> | 2020-08-08 02:01:35 +0200 |
---|---|---|
committer | Julien Moutinho <julm+nixpkgs@sourcephile.fr> | 2020-09-06 07:43:03 +0200 |
commit | fb6d63f3fdd95a5468d43a0693c8ca7c1894363f (patch) | |
tree | 44edb88b751700b3e611999eb2998b6b518adb71 /pkgs/os-specific | |
parent | 539ae5c93299cadc0664cfff2ffc69a9386caf6d (diff) | |
download | nixpkgs-fb6d63f3fdd95a5468d43a0693c8ca7c1894363f.tar nixpkgs-fb6d63f3fdd95a5468d43a0693c8ca7c1894363f.tar.gz nixpkgs-fb6d63f3fdd95a5468d43a0693c8ca7c1894363f.tar.bz2 nixpkgs-fb6d63f3fdd95a5468d43a0693c8ca7c1894363f.tar.lz nixpkgs-fb6d63f3fdd95a5468d43a0693c8ca7c1894363f.tar.xz nixpkgs-fb6d63f3fdd95a5468d43a0693c8ca7c1894363f.tar.zst nixpkgs-fb6d63f3fdd95a5468d43a0693c8ca7c1894363f.zip |
apparmor: fix and improve the service
Diffstat (limited to 'pkgs/os-specific')
-rw-r--r-- | pkgs/os-specific/linux/apparmor/default.nix | 54 | ||||
-rw-r--r-- | pkgs/os-specific/linux/apparmor/fix-rc.apparmor.functions.sh | 32 | ||||
-rw-r--r-- | pkgs/os-specific/linux/iputils/default.nix | 22 |
3 files changed, 106 insertions, 2 deletions
diff --git a/pkgs/os-specific/linux/apparmor/default.nix b/pkgs/os-specific/linux/apparmor/default.nix index 0e10add5561..8806f6c50d3 100644 --- a/pkgs/os-specific/linux/apparmor/default.nix +++ b/pkgs/os-specific/linux/apparmor/default.nix @@ -10,6 +10,13 @@ , pam , libnotify , buildPackages +, coreutils +, gnugrep +, gnused +, kmod +, writeShellScript +, closureInfo +, runCommand }: let @@ -38,6 +45,12 @@ let sha256 = "0xw028iqp69j9mxv0kbwraplgkj5i5djdlgf0anpkc5cdbsf96r9"; }; + aa-teardown = writeShellScript "aa-teardown" '' + PATH="${lib.makeBinPath [coreutils gnused gnugrep]}:$PATH" + . ${apparmor-parser}/lib/apparmor/rc.apparmor.functions + remove_profiles + ''; + prePatchCommon = '' patch -p1 < ${gnumake43Patch} chmod a+x ./common/list_capabilities.sh ./common/list_af_names.sh @@ -149,6 +162,15 @@ let # aa-notify checks its name and does not work named ".aa-notify-wrapped" mv $out/bin/aa-notify $out/bin/aa-notify-wrapped makeWrapper ${perl}/bin/perl $out/bin/aa-notify --set PERL5LIB ${libapparmor}/${perl.libPrefix} --add-flags $out/bin/aa-notify-wrapped + + substituteInPlace $out/bin/aa-remove-unknown \ + --replace "/usr/bin/aa-status" "$out/bin/aa-status" \ + --replace "/sbin/modprobe" "${kmod}/bin/modprobe" \ + --replace "/lib/apparmor/rc.apparmor.functions" "${apparmor-parser}/lib/apparmor/rc.apparmor.functions" + wrapProgram $out/bin/aa-remove-unknown \ + --prefix PATH : ${lib.makeBinPath [gawk]} + + ln -s ${aa-teardown} $out/bin/aa-teardown ''; inherit doCheck; @@ -197,6 +219,9 @@ let substituteInPlace ./parser/Makefile --replace "/usr/include/linux/capability.h" "${linuxHeaders}/include/linux/capability.h" ## techdoc.pdf still doesn't build ... substituteInPlace ./parser/Makefile --replace "manpages htmlmanpages pdf" "manpages htmlmanpages" + substituteInPlace parser/rc.apparmor.functions \ + --replace "/sbin/apparmor_parser" "$out/bin/apparmor_parser" + sed -i parser/rc.apparmor.functions -e '2i . ${./fix-rc.apparmor.functions.sh}' ''; inherit patches; postPatch = "cd ./parser"; @@ -258,8 +283,32 @@ let meta = apparmor-meta "kernel patches"; }; + # Generate generic AppArmor rules in a file, + # from the closure of given rootPaths. + # To be included in an AppArmor profile like so: + # include "$(apparmorRulesFromClosure {} [pkgs.hello]}" + apparmorRulesFromClosure = + { # The store path of the derivation is given in $path + additionalRules ? [] + # TODO: factorize here some other common paths + # that may emerge from use cases. + , baseRules ? [ + "r $path" + "r $path/etc/**" + "r $path/share/**" + # Note that not all libraries are prefixed with "lib", + # eg. glibc-2.30/lib/ld-2.30.so + "mr $path/lib/**.so*" + # eg. glibc-2.30/lib/gconv/gconv-modules + "r $path/lib/**" + ] + }: rootPaths: runCommand "apparmor-closure-rules" {} '' + touch $out + while read -r path + do printf >>$out "%s,\n" ${lib.concatMapStringsSep " " (x: "\"${x}\"") (baseRules ++ additionalRules)} + done <${closureInfo {inherit rootPaths;}}/store-paths + ''; in - { inherit libapparmor @@ -268,5 +317,6 @@ in apparmor-parser apparmor-pam apparmor-profiles - apparmor-kernel-patches; + apparmor-kernel-patches + apparmorRulesFromClosure; } diff --git a/pkgs/os-specific/linux/apparmor/fix-rc.apparmor.functions.sh b/pkgs/os-specific/linux/apparmor/fix-rc.apparmor.functions.sh new file mode 100644 index 00000000000..ebc1baaa92d --- /dev/null +++ b/pkgs/os-specific/linux/apparmor/fix-rc.apparmor.functions.sh @@ -0,0 +1,32 @@ +aa_action() { + STRING=$1 + shift + $* + rc=$? + if [ $rc -eq 0 ] ; then + aa_log_success_msg $"$STRING " + else + aa_log_failure_msg $"$STRING " + fi + return $rc +} + +aa_log_success_msg() { + [ -n "$1" ] && echo -n $1 + echo ": done." +} + +aa_log_warning_msg() { + [ -n "$1" ] && echo -n $1 + echo ": Warning." +} + +aa_log_failure_msg() { + [ -n "$1" ] && echo -n $1 + echo ": Failed." +} + +aa_log_skipped_msg() { + [ -n "$1" ] && echo -n $1 + echo ": Skipped." +} diff --git a/pkgs/os-specific/linux/iputils/default.nix b/pkgs/os-specific/linux/iputils/default.nix index e12c44888a0..b005c65684d 100644 --- a/pkgs/os-specific/linux/iputils/default.nix +++ b/pkgs/os-specific/linux/iputils/default.nix @@ -1,6 +1,7 @@ { stdenv, fetchFromGitHub , meson, ninja, pkgconfig, gettext, libxslt, docbook_xsl_ns , libcap, systemd, libidn2 +, apparmorRulesFromClosure }: with stdenv.lib; @@ -22,6 +23,8 @@ in stdenv.mkDerivation rec { sha256 = "1jhbcz75a4ij1myyyi110ma1d8d5hpm3scz9pyw7js6qym50xvh4"; }; + outputs = ["out" "apparmor"]; + mesonFlags = [ "-DBUILD_RARPD=true" "-DBUILD_TRACEROUTE6=true" @@ -35,6 +38,25 @@ in stdenv.mkDerivation rec { nativeBuildInputs = [ meson ninja pkgconfig gettext libxslt.bin docbook_xsl_ns ]; buildInputs = [ libcap systemd ] ++ optional (!stdenv.hostPlatform.isMusl) libidn2; + postInstall = '' + install -D /dev/stdin $apparmor/bin.ping <<EOF + include <tunables/global> + $out/bin/ping { + include <abstractions/base> + include <abstractions/consoles> + include <abstractions/nameservice> + include "${apparmorRulesFromClosure {} + ([libcap] ++ optional (!stdenv.hostPlatform.isMusl) libidn2)}" + include <local/bin.ping> + capability net_raw, + network inet raw, + network inet6 raw, + mr $out/bin/ping, + r $out/share/locale/**, + r @{PROC}/@{pid}/environ, + } + EOF + ''; meta = { description = "A set of small useful utilities for Linux networking"; |