2018-08-28 23:20:43 +01:00
|
|
|
{ stdenv, lib, fetchurl, fetchpatch, makeWrapper, autoreconfHook
|
2021-01-19 06:50:56 +00:00
|
|
|
, pkg-config, which
|
2016-04-17 20:43:48 +01:00
|
|
|
, flex, bison
|
|
|
|
, linuxHeaders ? stdenv.cc.libc.linuxHeaders
|
2018-01-20 08:29:03 +00:00
|
|
|
, gawk
|
2021-02-25 16:21:13 +00:00
|
|
|
, withPerl ? stdenv.hostPlatform == stdenv.buildPlatform && lib.meta.availableOn stdenv.hostPlatform perl, perl
|
|
|
|
, withPython ? stdenv.hostPlatform == stdenv.buildPlatform && lib.meta.availableOn stdenv.hostPlatform python, python
|
2016-04-17 20:43:48 +01:00
|
|
|
, swig
|
2018-01-20 08:29:03 +00:00
|
|
|
, ncurses
|
2016-04-17 20:43:48 +01:00
|
|
|
, pam
|
2018-12-15 03:50:31 +00:00
|
|
|
, libnotify
|
2018-02-25 14:38:55 +00:00
|
|
|
, buildPackages
|
2020-10-18 14:36:24 +01:00
|
|
|
, coreutils
|
|
|
|
, gnugrep
|
|
|
|
, gnused
|
|
|
|
, kmod
|
|
|
|
, writeShellScript
|
|
|
|
, closureInfo
|
|
|
|
, runCommand
|
2015-04-12 08:43:23 +01:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
2020-12-25 14:40:02 +00:00
|
|
|
apparmor-version = "3.0.1";
|
2015-04-12 08:43:23 +01:00
|
|
|
|
2021-01-15 14:45:37 +00:00
|
|
|
apparmor-meta = component: with lib; {
|
2020-03-27 23:05:50 +00:00
|
|
|
homepage = "https://apparmor.net/";
|
2016-04-17 20:43:48 +01:00
|
|
|
description = "A mandatory access control system - ${component}";
|
2015-04-12 08:43:23 +01:00
|
|
|
license = licenses.gpl2;
|
2020-12-25 14:40:02 +00:00
|
|
|
maintainers = with maintainers; [ joachifm julm phreedom thoughtpolice ];
|
2015-04-12 08:43:23 +01:00
|
|
|
platforms = platforms.linux;
|
2012-02-29 13:30:10 +00:00
|
|
|
};
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
apparmor-sources = fetchurl {
|
2020-12-25 14:40:02 +00:00
|
|
|
url = "https://launchpad.net/apparmor/${lib.versions.majorMinor apparmor-version}/${apparmor-version}/+download/apparmor-${apparmor-version}.tar.gz";
|
|
|
|
sha256 = "096zbg3v7b51x7f1ly61mzd3iy9alad6sd4lam98j2d6v5ragbcg";
|
2020-07-16 22:46:00 +01:00
|
|
|
};
|
|
|
|
|
2020-10-18 14:36:24 +01:00
|
|
|
aa-teardown = writeShellScript "aa-teardown" ''
|
|
|
|
PATH="${lib.makeBinPath [coreutils gnused gnugrep]}:$PATH"
|
|
|
|
. ${apparmor-parser}/lib/apparmor/rc.apparmor.functions
|
|
|
|
remove_profiles
|
|
|
|
'';
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
prePatchCommon = ''
|
2020-07-18 16:50:42 +01:00
|
|
|
chmod a+x ./common/list_capabilities.sh ./common/list_af_names.sh
|
|
|
|
patchShebangs ./common/list_capabilities.sh ./common/list_af_names.sh
|
2018-02-25 14:38:55 +00:00
|
|
|
substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2man" "${buildPackages.perl}/bin/pod2man"
|
|
|
|
substituteInPlace ./common/Make.rules --replace "/usr/bin/pod2html" "${buildPackages.perl}/bin/pod2html"
|
2016-04-17 20:43:48 +01:00
|
|
|
substituteInPlace ./common/Make.rules --replace "/usr/include/linux/capability.h" "${linuxHeaders}/include/linux/capability.h"
|
2015-04-12 08:43:23 +01:00
|
|
|
substituteInPlace ./common/Make.rules --replace "/usr/share/man" "share/man"
|
2012-02-29 13:30:10 +00:00
|
|
|
'';
|
2014-12-10 15:08:48 +00:00
|
|
|
|
2021-01-15 14:45:37 +00:00
|
|
|
patches = lib.optionals stdenv.hostPlatform.isMusl [
|
2017-08-25 14:39:03 +01:00
|
|
|
(fetchpatch {
|
2020-05-15 16:58:27 +01:00
|
|
|
url = "https://git.alpinelinux.org/aports/plain/testing/apparmor/0003-Added-missing-typedef-definitions-on-parser.patch?id=74b8427cc21f04e32030d047ae92caa618105b53";
|
2017-08-25 14:39:03 +01:00
|
|
|
name = "0003-Added-missing-typedef-definitions-on-parser.patch";
|
|
|
|
sha256 = "0yyaqz8jlmn1bm37arggprqz0njb4lhjni2d9c8qfqj0kll0bam0";
|
|
|
|
})
|
2019-06-29 12:17:21 +01:00
|
|
|
];
|
2018-04-25 04:20:18 +01:00
|
|
|
|
|
|
|
# Set to `true` after the next FIXME gets fixed or this gets some
|
|
|
|
# common derivation infra. Too much copy-paste to fix one by one.
|
|
|
|
doCheck = false;
|
2017-08-25 14:39:03 +01:00
|
|
|
|
2016-09-01 16:51:21 +01:00
|
|
|
# FIXME: convert these to a single multiple-outputs package?
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
libapparmor = stdenv.mkDerivation {
|
|
|
|
name = "libapparmor-${apparmor-version}";
|
|
|
|
src = apparmor-sources;
|
|
|
|
|
2016-04-17 20:43:48 +01:00
|
|
|
nativeBuildInputs = [
|
2015-07-15 08:31:40 +01:00
|
|
|
autoreconfHook
|
2015-04-12 08:43:23 +01:00
|
|
|
bison
|
|
|
|
flex
|
2021-01-19 06:50:56 +00:00
|
|
|
pkg-config
|
2015-04-12 08:43:23 +01:00
|
|
|
swig
|
2018-01-20 08:29:03 +00:00
|
|
|
ncurses
|
2015-04-12 08:43:23 +01:00
|
|
|
which
|
2018-02-25 14:38:55 +00:00
|
|
|
perl
|
2015-04-12 08:43:23 +01:00
|
|
|
];
|
|
|
|
|
2018-07-29 21:48:24 +01:00
|
|
|
buildInputs = []
|
2021-01-15 14:45:37 +00:00
|
|
|
++ lib.optional withPerl perl
|
|
|
|
++ lib.optional withPython python;
|
2016-04-17 20:43:48 +01:00
|
|
|
|
2015-07-15 08:31:40 +01:00
|
|
|
# required to build apparmor-parser
|
|
|
|
dontDisableStatic = true;
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
prePatch = prePatchCommon + ''
|
2018-12-15 03:50:31 +00:00
|
|
|
substituteInPlace ./libraries/libapparmor/swig/perl/Makefile.am --replace install_vendor install_site
|
|
|
|
substituteInPlace ./libraries/libapparmor/swig/perl/Makefile.in --replace install_vendor install_site
|
2021-01-15 14:45:37 +00:00
|
|
|
substituteInPlace ./libraries/libapparmor/src/Makefile.am --replace "/usr/include/netinet/in.h" "${lib.getDev stdenv.cc.libc}/include/netinet/in.h"
|
|
|
|
substituteInPlace ./libraries/libapparmor/src/Makefile.in --replace "/usr/include/netinet/in.h" "${lib.getDev stdenv.cc.libc}/include/netinet/in.h"
|
2016-04-17 20:43:48 +01:00
|
|
|
'';
|
2017-08-25 14:39:03 +01:00
|
|
|
inherit patches;
|
|
|
|
|
2015-07-15 08:31:40 +01:00
|
|
|
postPatch = "cd ./libraries/libapparmor";
|
2018-02-25 14:38:55 +00:00
|
|
|
# https://gitlab.com/apparmor/apparmor/issues/1
|
2018-07-29 21:48:24 +01:00
|
|
|
configureFlags = [
|
2021-01-15 14:45:37 +00:00
|
|
|
(lib.withFeature withPerl "perl")
|
|
|
|
(lib.withFeature withPython "python")
|
2018-07-29 21:48:24 +01:00
|
|
|
];
|
2015-04-12 08:43:23 +01:00
|
|
|
|
2021-01-15 14:45:37 +00:00
|
|
|
outputs = [ "out" ] ++ lib.optional withPython "python";
|
2016-09-01 16:51:21 +01:00
|
|
|
|
2021-01-15 14:45:37 +00:00
|
|
|
postInstall = lib.optionalString withPython ''
|
2016-09-01 16:51:21 +01:00
|
|
|
mkdir -p $python/lib
|
|
|
|
mv $out/lib/python* $python/lib/
|
|
|
|
'';
|
|
|
|
|
2018-04-25 04:20:18 +01:00
|
|
|
inherit doCheck;
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
meta = apparmor-meta "library";
|
|
|
|
};
|
2012-02-29 13:30:10 +00:00
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
apparmor-utils = stdenv.mkDerivation {
|
|
|
|
name = "apparmor-utils-${apparmor-version}";
|
|
|
|
src = apparmor-sources;
|
|
|
|
|
2016-04-17 20:43:48 +01:00
|
|
|
nativeBuildInputs = [ makeWrapper which ];
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
buildInputs = [
|
2015-07-15 08:45:22 +01:00
|
|
|
perl
|
2018-01-20 08:29:03 +00:00
|
|
|
python
|
2015-04-12 08:43:23 +01:00
|
|
|
libapparmor
|
2016-09-01 16:51:21 +01:00
|
|
|
libapparmor.python
|
2015-04-12 08:43:23 +01:00
|
|
|
];
|
|
|
|
|
2020-10-18 14:36:24 +01:00
|
|
|
prePatch = prePatchCommon +
|
|
|
|
# Do not build vim file
|
|
|
|
lib.optionalString stdenv.hostPlatform.isMusl ''
|
|
|
|
sed -i ./utils/Makefile -e "/\<vim\>/d"
|
|
|
|
'' + ''
|
2020-08-23 19:42:59 +01:00
|
|
|
substituteInPlace ./utils/apparmor/easyprof.py --replace "/sbin/apparmor_parser" "${apparmor-parser}/bin/apparmor_parser"
|
|
|
|
substituteInPlace ./utils/apparmor/aa.py --replace "/sbin/apparmor_parser" "${apparmor-parser}/bin/apparmor_parser"
|
|
|
|
substituteInPlace ./utils/logprof.conf --replace "/sbin/apparmor_parser" "${apparmor-parser}/bin/apparmor_parser"
|
|
|
|
'';
|
2017-08-25 14:39:03 +01:00
|
|
|
inherit patches;
|
2015-07-15 08:31:40 +01:00
|
|
|
postPatch = "cd ./utils";
|
2019-10-28 09:17:49 +00:00
|
|
|
makeFlags = [ "LANGS=" ];
|
|
|
|
installFlags = [ "DESTDIR=$(out)" "BINDIR=$(out)/bin" "VIM_INSTALL_PATH=$(out)/share" "PYPREFIX=" ];
|
2015-04-12 08:43:23 +01:00
|
|
|
|
2015-07-15 08:45:22 +01:00
|
|
|
postInstall = ''
|
2020-10-18 14:36:24 +01:00
|
|
|
sed -i $out/bin/aa-unconfined -e "/my_env\['PATH'\]/d"
|
2020-12-01 16:35:56 +00:00
|
|
|
for prog in aa-audit aa-autodep aa-cleanprof aa-complain aa-disable aa-enforce aa-genprof aa-logprof aa-mergeprof aa-unconfined ; do
|
2018-01-20 08:29:03 +00:00
|
|
|
wrapProgram $out/bin/$prog --prefix PYTHONPATH : "$out/lib/${python.libPrefix}/site-packages:$PYTHONPATH"
|
2015-07-15 08:45:22 +01:00
|
|
|
done
|
|
|
|
|
2021-02-24 19:53:45 +00:00
|
|
|
substituteInPlace $out/bin/aa-notify \
|
|
|
|
--replace /usr/bin/notify-send ${libnotify}/bin/notify-send \
|
|
|
|
--replace /usr/bin/perl "${perl}/bin/perl -I ${libapparmor}/${perl.libPrefix}"
|
2020-10-18 14:36:24 +01:00
|
|
|
|
|
|
|
substituteInPlace $out/bin/aa-remove-unknown \
|
|
|
|
--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
|
2015-07-15 08:45:22 +01:00
|
|
|
'';
|
|
|
|
|
2018-04-25 04:20:18 +01:00
|
|
|
inherit doCheck;
|
|
|
|
|
2018-07-29 21:48:24 +01:00
|
|
|
meta = apparmor-meta "user-land utilities" // {
|
|
|
|
broken = !(withPython && withPerl);
|
|
|
|
};
|
2015-04-12 08:43:23 +01:00
|
|
|
};
|
|
|
|
|
2018-01-20 08:29:03 +00:00
|
|
|
apparmor-bin-utils = stdenv.mkDerivation {
|
|
|
|
name = "apparmor-bin-utils-${apparmor-version}";
|
|
|
|
src = apparmor-sources;
|
|
|
|
|
|
|
|
nativeBuildInputs = [
|
2021-01-19 06:50:56 +00:00
|
|
|
pkg-config
|
2018-01-20 08:29:03 +00:00
|
|
|
libapparmor
|
|
|
|
gawk
|
|
|
|
which
|
|
|
|
];
|
|
|
|
|
|
|
|
buildInputs = [
|
|
|
|
libapparmor
|
|
|
|
];
|
|
|
|
|
|
|
|
prePatch = prePatchCommon;
|
|
|
|
postPatch = "cd ./binutils";
|
2019-10-28 09:17:49 +00:00
|
|
|
makeFlags = [ "LANGS=" "USE_SYSTEM=1" ];
|
2020-12-01 16:35:56 +00:00
|
|
|
installFlags = [ "DESTDIR=$(out)" "BINDIR=$(out)/bin" "SBINDIR=$(out)/bin" ];
|
2018-01-20 08:29:03 +00:00
|
|
|
|
2018-04-25 04:20:18 +01:00
|
|
|
inherit doCheck;
|
|
|
|
|
2018-01-20 08:29:03 +00:00
|
|
|
meta = apparmor-meta "binary user-land utilities";
|
|
|
|
};
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
apparmor-parser = stdenv.mkDerivation {
|
|
|
|
name = "apparmor-parser-${apparmor-version}";
|
|
|
|
src = apparmor-sources;
|
|
|
|
|
2016-04-17 20:43:48 +01:00
|
|
|
nativeBuildInputs = [ bison flex which ];
|
|
|
|
|
|
|
|
buildInputs = [ libapparmor ];
|
2015-04-12 08:43:23 +01:00
|
|
|
|
2020-07-18 16:50:42 +01:00
|
|
|
prePatch = prePatchCommon + ''
|
2015-04-12 08:43:23 +01:00
|
|
|
substituteInPlace ./parser/Makefile --replace "/usr/bin/bison" "${bison}/bin/bison"
|
|
|
|
substituteInPlace ./parser/Makefile --replace "/usr/bin/flex" "${flex}/bin/flex"
|
2016-04-17 20:43:48 +01:00
|
|
|
substituteInPlace ./parser/Makefile --replace "/usr/include/linux/capability.h" "${linuxHeaders}/include/linux/capability.h"
|
2015-04-12 08:43:23 +01:00
|
|
|
## techdoc.pdf still doesn't build ...
|
|
|
|
substituteInPlace ./parser/Makefile --replace "manpages htmlmanpages pdf" "manpages htmlmanpages"
|
2020-10-18 14:36:24 +01:00
|
|
|
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}'
|
2015-04-12 08:43:23 +01:00
|
|
|
'';
|
2017-08-25 14:39:03 +01:00
|
|
|
inherit patches;
|
2015-07-15 08:31:40 +01:00
|
|
|
postPatch = "cd ./parser";
|
2019-10-28 09:17:49 +00:00
|
|
|
makeFlags = [
|
|
|
|
"LANGS=" "USE_SYSTEM=1" "INCLUDEDIR=${libapparmor}/include"
|
|
|
|
"AR=${stdenv.cc.bintools.targetPrefix}ar"
|
|
|
|
];
|
|
|
|
installFlags = [ "DESTDIR=$(out)" "DISTRO=unknown" ];
|
2015-04-12 08:43:23 +01:00
|
|
|
|
2018-04-25 04:20:18 +01:00
|
|
|
inherit doCheck;
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
meta = apparmor-meta "rule parser";
|
2012-02-29 13:30:10 +00:00
|
|
|
};
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
apparmor-pam = stdenv.mkDerivation {
|
|
|
|
name = "apparmor-pam-${apparmor-version}";
|
|
|
|
src = apparmor-sources;
|
|
|
|
|
2021-01-19 06:50:56 +00:00
|
|
|
nativeBuildInputs = [ pkg-config which ];
|
2016-04-17 20:43:48 +01:00
|
|
|
|
|
|
|
buildInputs = [ libapparmor pam ];
|
2015-04-12 08:43:23 +01:00
|
|
|
|
2015-07-15 08:31:40 +01:00
|
|
|
postPatch = "cd ./changehat/pam_apparmor";
|
2019-10-28 09:17:49 +00:00
|
|
|
makeFlags = [ "USE_SYSTEM=1" ];
|
|
|
|
installFlags = [ "DESTDIR=$(out)" ];
|
2015-04-12 08:43:23 +01:00
|
|
|
|
2018-04-25 04:20:18 +01:00
|
|
|
inherit doCheck;
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
meta = apparmor-meta "PAM service";
|
|
|
|
};
|
|
|
|
|
|
|
|
apparmor-profiles = stdenv.mkDerivation {
|
|
|
|
name = "apparmor-profiles-${apparmor-version}";
|
|
|
|
src = apparmor-sources;
|
|
|
|
|
2016-04-17 20:43:48 +01:00
|
|
|
nativeBuildInputs = [ which ];
|
2015-04-12 08:43:23 +01:00
|
|
|
|
2015-07-15 08:31:40 +01:00
|
|
|
postPatch = "cd ./profiles";
|
2019-10-28 09:17:49 +00:00
|
|
|
installFlags = [ "DESTDIR=$(out)" "EXTRAS_DEST=$(out)/share/apparmor/extra-profiles" ];
|
2015-04-12 08:43:23 +01:00
|
|
|
|
2018-04-25 04:20:18 +01:00
|
|
|
inherit doCheck;
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
meta = apparmor-meta "profiles";
|
|
|
|
};
|
|
|
|
|
|
|
|
apparmor-kernel-patches = stdenv.mkDerivation {
|
|
|
|
name = "apparmor-kernel-patches-${apparmor-version}";
|
|
|
|
src = apparmor-sources;
|
|
|
|
|
2021-01-24 09:19:10 +00:00
|
|
|
phases = "unpackPhase installPhase";
|
2015-04-12 08:43:23 +01:00
|
|
|
|
|
|
|
installPhase = ''
|
|
|
|
mkdir "$out"
|
2016-04-17 20:43:48 +01:00
|
|
|
cp -R ./kernel-patches/* "$out"
|
2015-04-12 08:43:23 +01:00
|
|
|
'';
|
|
|
|
|
2018-04-25 04:20:18 +01:00
|
|
|
inherit doCheck;
|
|
|
|
|
2015-04-12 08:43:23 +01:00
|
|
|
meta = apparmor-meta "kernel patches";
|
|
|
|
};
|
|
|
|
|
2020-10-18 14:36:24 +01:00
|
|
|
# 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/**"
|
|
|
|
]
|
|
|
|
, name ? ""
|
|
|
|
}: rootPaths: runCommand
|
|
|
|
( "apparmor-closure-rules"
|
2021-02-27 20:26:47 +00:00
|
|
|
+ lib.optionalString (name != "") "-${name}" ) {} ''
|
2020-10-18 14:36:24 +01:00
|
|
|
touch $out
|
|
|
|
while read -r path
|
|
|
|
do printf >>$out "%s,\n" ${lib.concatMapStringsSep " " (x: "\"${x}\"") (baseRules ++ additionalRules)}
|
|
|
|
done <${closureInfo {inherit rootPaths;}}/store-paths
|
|
|
|
'';
|
2015-04-12 08:43:23 +01:00
|
|
|
in
|
|
|
|
{
|
2018-01-20 08:29:03 +00:00
|
|
|
inherit
|
|
|
|
libapparmor
|
|
|
|
apparmor-utils
|
|
|
|
apparmor-bin-utils
|
|
|
|
apparmor-parser
|
|
|
|
apparmor-pam
|
|
|
|
apparmor-profiles
|
2020-10-18 14:36:24 +01:00
|
|
|
apparmor-kernel-patches
|
|
|
|
apparmorRulesFromClosure;
|
2015-04-12 08:43:23 +01:00
|
|
|
}
|