···15151515 </listitem>
15161516 <listitem>
15171517 <para>
15181518+ The <literal>security.apparmor</literal> module,
15191519+ for the <link xlink:href="https://gitlab.com/apparmor/apparmor/-/wikis/Documentation">AppArmor</link>
15201520+ Mandatory Access Control system,
15211521+ has been substantialy improved along with related tools,
15221522+ so that module maintainers can now more easily write AppArmor profiles for NixOS.
15231523+ The most notable change on the user-side is the new option <xref linkend="opt-security.apparmor.policies"/>,
15241524+ replacing the previous <literal>profiles</literal> option
15251525+ to provide a way to disable a profile
15261526+ and to select whether to confine in enforce mode (default)
15271527+ or in complain mode (see <literal>journalctl -b --grep apparmor</literal>).
15281528+ Before enabling this module, either directly
15291529+ or by importing <literal><nixpkgs/nixos/modules/profiles/hardened.nix></literal>,
15301530+ please be sure to read the documentation of <link linkend="opt-security.apparmor.enable">security.apparmor.enable</link>,
15311531+ and especially the part about <xref linkend="opt-security.apparmor.killUnconfinedConfinables"/>.
15321532+ </para>
15331533+ </listitem>
15341534+ <listitem>
15351535+ <para>
15181536 With this release <literal>systemd-networkd</literal> (when enabled through <xref linkend="opt-networking.useNetworkd"/>)
15191537 has it's netlink socket created through a <literal>systemd.socket</literal> unit. This gives us control over
15201538 socket buffer sizes and other parameters. For larger setups where networkd has to create a lot of (virtual)
···11{ config, lib, pkgs, ... }:
2233let
44- inherit (lib) mkIf mkOption types concatMapStrings;
44+ inherit (builtins) attrNames head map match readFile;
55+ inherit (lib) types;
66+ inherit (config.environment) etc;
57 cfg = config.security.apparmor;
88+ mkDisableOption = name: lib.mkEnableOption name // {
99+ default = true;
1010+ example = false;
1111+ };
1212+ enabledPolicies = lib.filterAttrs (n: p: p.enable) cfg.policies;
613in
714815{
99- options = {
1010- security.apparmor = {
1111- enable = mkOption {
1212- type = types.bool;
1313- default = false;
1414- description = "Enable the AppArmor Mandatory Access Control system.";
1515- };
1616- profiles = mkOption {
1717- type = types.listOf types.path;
1818- default = [];
1919- description = "List of files containing AppArmor profiles.";
2020- };
2121- packages = mkOption {
2222- type = types.listOf types.package;
2323- default = [];
2424- description = "List of packages to be added to apparmor's include path";
2525- };
2626- };
2727- };
1616+ imports = [
1717+ (lib.mkRenamedOptionModule [ "security" "virtualization" "flushL1DataCache" ] [ "security" "virtualisation" "flushL1DataCache" ])
1818+ (lib.mkRemovedOptionModule [ "security" "apparmor" "confineSUIDApplications" ] "Please use the new options: `security.apparmor.policies.<policy>.enable'.")
1919+ (lib.mkRemovedOptionModule [ "security" "apparmor" "profiles" ] "Please use the new option: `security.apparmor.policies'.")
2020+ apparmor/includes.nix
2121+ apparmor/profiles.nix
2222+ ];
2323+2424+ options = {
2525+ security.apparmor = {
2626+ enable = lib.mkEnableOption ''the AppArmor Mandatory Access Control system.
2727+2828+ If you're enabling this module on a running system,
2929+ note that a reboot will be required to activate AppArmor in the kernel.
3030+3131+ Also, beware that enabling this module will by default
3232+ try to kill unconfined but confinable running processes,
3333+ in order to obtain a confinement matching what is declared in the NixOS configuration.
3434+ This will happen when upgrading to a NixOS revision
3535+ introducing an AppArmor profile for the executable of a running process.
3636+ This is because enabling an AppArmor profile for an executable
3737+ can only confine new or already confined processes of that executable,
3838+ but leaves already running processes unconfined.
3939+ Set <link linkend="opt-security.apparmor.killUnconfinedConfinables">killUnconfinedConfinables</link>
4040+ to <literal>false</literal> if you prefer to leave those processes running'';
4141+ policies = lib.mkOption {
4242+ description = ''
4343+ AppArmor policies.
4444+ '';
4545+ type = types.attrsOf (types.submodule ({ name, config, ... }: {
4646+ options = {
4747+ enable = mkDisableOption "loading of the profile into the kernel";
4848+ enforce = mkDisableOption "enforcing of the policy or only complain in the logs";
4949+ profile = lib.mkOption {
5050+ description = "The policy of the profile.";
5151+ type = types.lines;
5252+ apply = pkgs.writeText name;
5353+ };
5454+ };
5555+ }));
5656+ default = {};
5757+ };
5858+ includes = lib.mkOption {
5959+ type = types.attrsOf types.lines;
6060+ default = {};
6161+ description = ''
6262+ List of paths to be added to AppArmor's searched paths
6363+ when resolving <literal>include</literal> directives.
6464+ '';
6565+ apply = lib.mapAttrs pkgs.writeText;
6666+ };
6767+ packages = lib.mkOption {
6868+ type = types.listOf types.package;
6969+ default = [];
7070+ description = "List of packages to be added to AppArmor's include path";
7171+ };
7272+ enableCache = lib.mkEnableOption ''caching of AppArmor policies
7373+ in <literal>/var/cache/apparmor/</literal>.
7474+7575+ Beware that AppArmor policies almost always contain Nix store paths,
7676+ and thus produce at each change of these paths
7777+ a new cached version accumulating in the cache'';
7878+ killUnconfinedConfinables = mkDisableOption ''killing of processes
7979+ which have an AppArmor profile enabled
8080+ (in <link linkend="opt-security.apparmor.policies">policies</link>)
8181+ but are not confined (because AppArmor can only confine new processes).
8282+ Beware that due to a current limitation of AppArmor,
8383+ only profiles with exact paths (and no name) can enable such kills'';
8484+ };
8585+ };
8686+8787+ config = lib.mkIf cfg.enable {
8888+ assertions = map (policy:
8989+ { assertion = match ".*/.*" policy == null;
9090+ message = "`security.apparmor.policies.\"${policy}\"' must not contain a slash.";
9191+ # Because, for instance, aa-remove-unknown uses profiles_names_list() in rc.apparmor.functions
9292+ # which does not recurse into sub-directories.
9393+ }
9494+ ) (attrNames cfg.policies);
9595+9696+ environment.systemPackages = [ pkgs.apparmor-utils ];
9797+ environment.etc."apparmor.d".source = pkgs.linkFarm "apparmor.d" (
9898+ # It's important to put only enabledPolicies here and not all cfg.policies
9999+ # because aa-remove-unknown reads profiles from all /etc/apparmor.d/*
100100+ lib.mapAttrsToList (name: p: {inherit name; path=p.profile;}) enabledPolicies ++
101101+ lib.mapAttrsToList (name: path: {inherit name path;}) cfg.includes
102102+ );
103103+ environment.etc."apparmor/parser.conf".text = ''
104104+ ${if cfg.enableCache then "write-cache" else "skip-cache"}
105105+ cache-loc /var/cache/apparmor
106106+ Include /etc/apparmor.d
107107+ '' +
108108+ lib.concatMapStrings (p: "Include ${p}/etc/apparmor.d\n") cfg.packages;
109109+ # For aa-logprof
110110+ environment.etc."apparmor/apparmor.conf".text = ''
111111+ '';
112112+ # For aa-logprof
113113+ environment.etc."apparmor/severity.db".source = pkgs.apparmor-utils + "/etc/apparmor/severity.db";
114114+ environment.etc."apparmor/logprof.conf".text = ''
115115+ [settings]
116116+ # /etc/apparmor.d/ is read-only on NixOS
117117+ profiledir = /var/cache/apparmor/logprof
118118+ inactive_profiledir = /etc/apparmor.d/disable
119119+ # Use: journalctl -b --since today --grep audit: | aa-logprof
120120+ logfiles = /dev/stdin
121121+122122+ parser = ${pkgs.apparmor-parser}/bin/apparmor_parser
123123+ ldd = ${pkgs.glibc.bin}/bin/ldd
124124+ logger = ${pkgs.utillinux}/bin/logger
125125+126126+ # customize how file ownership permissions are presented
127127+ # 0 - off
128128+ # 1 - default of what ever mode the log reported
129129+ # 2 - force the new permissions to be user
130130+ # 3 - force all perms on the rule to be user
131131+ default_owner_prompt = 1
132132+133133+ custom_includes = /etc/apparmor.d ${lib.concatMapStringsSep " " (p: "${p}/etc/apparmor.d") cfg.packages}
134134+135135+ [qualifiers]
136136+ ${pkgs.runtimeShell} = icnu
137137+ ${pkgs.bashInteractive}/bin/sh = icnu
138138+ ${pkgs.bashInteractive}/bin/bash = icnu
139139+ '' + head (match "^.*\\[qualifiers](.*)" # Drop the original [settings] section.
140140+ (readFile "${pkgs.apparmor-utils}/etc/apparmor/logprof.conf"));
281412929- config = mkIf cfg.enable {
3030- environment.systemPackages = [ pkgs.apparmor-utils ];
142142+ boot.kernelParams = [ "apparmor=1" "security=apparmor" ];
311433232- boot.kernelParams = [ "apparmor=1" "security=apparmor" ];
144144+ systemd.services.apparmor = {
145145+ after = [
146146+ "local-fs.target"
147147+ "systemd-journald-audit.socket"
148148+ ];
149149+ before = [ "sysinit.target" ];
150150+ wantedBy = [ "multi-user.target" ];
151151+ unitConfig = {
152152+ Description="Load AppArmor policies";
153153+ DefaultDependencies = "no";
154154+ ConditionSecurity = "apparmor";
155155+ };
156156+ # Reloading instead of restarting enables to load new AppArmor profiles
157157+ # without necessarily restarting all services which have Requires=apparmor.service
158158+ reloadIfChanged = true;
159159+ restartTriggers = [
160160+ etc."apparmor/parser.conf".source
161161+ etc."apparmor.d".source
162162+ ];
163163+ serviceConfig = let
164164+ killUnconfinedConfinables = pkgs.writeShellScript "apparmor-kill" ''
165165+ set -eu
166166+ ${pkgs.apparmor-utils}/bin/aa-status --json |
167167+ ${pkgs.jq}/bin/jq --raw-output '.processes | .[] | .[] | select (.status == "unconfined") | .pid' |
168168+ xargs --verbose --no-run-if-empty --delimiter='\n' \
169169+ kill
170170+ '';
171171+ commonOpts = p: "--verbose --show-cache ${lib.optionalString (!p.enforce) "--complain "}${p.profile}";
172172+ in {
173173+ Type = "oneshot";
174174+ RemainAfterExit = "yes";
175175+ ExecStartPre = "${pkgs.apparmor-utils}/bin/aa-teardown";
176176+ ExecStart = lib.mapAttrsToList (n: p: "${pkgs.apparmor-parser}/bin/apparmor_parser --add ${commonOpts p}") enabledPolicies;
177177+ ExecStartPost = lib.optional cfg.killUnconfinedConfinables killUnconfinedConfinables;
178178+ ExecReload =
179179+ # Add or replace into the kernel profiles in enabledPolicies
180180+ # (because AppArmor can do that without stopping the processes already confined).
181181+ lib.mapAttrsToList (n: p: "${pkgs.apparmor-parser}/bin/apparmor_parser --replace ${commonOpts p}") enabledPolicies ++
182182+ # Remove from the kernel any profile whose name is not
183183+ # one of the names within the content of the profiles in enabledPolicies
184184+ # (indirectly read from /etc/apparmor.d/*, without recursing into sub-directory).
185185+ # Note that this does not remove profiles dynamically generated by libvirt.
186186+ [ "${pkgs.apparmor-utils}/bin/aa-remove-unknown" ] ++
187187+ # Optionaly kill the processes which are unconfined but now have a profile loaded
188188+ # (because AppArmor can only start to confine new processes).
189189+ lib.optional cfg.killUnconfinedConfinables killUnconfinedConfinables;
190190+ ExecStop = "${pkgs.apparmor-utils}/bin/aa-teardown";
191191+ CacheDirectory = [ "apparmor" "apparmor/logprof" ];
192192+ CacheDirectoryMode = "0700";
193193+ };
194194+ };
195195+ };
331963434- systemd.services.apparmor = let
3535- paths = concatMapStrings (s: " -I ${s}/etc/apparmor.d")
3636- ([ pkgs.apparmor-profiles ] ++ cfg.packages);
3737- in {
3838- after = [ "local-fs.target" ];
3939- before = [ "sysinit.target" ];
4040- wantedBy = [ "multi-user.target" ];
4141- unitConfig = {
4242- DefaultDependencies = "no";
4343- };
4444- serviceConfig = {
4545- Type = "oneshot";
4646- RemainAfterExit = "yes";
4747- ExecStart = map (p:
4848- ''${pkgs.apparmor-parser}/bin/apparmor_parser -rKv ${paths} "${p}"''
4949- ) cfg.profiles;
5050- ExecStop = map (p:
5151- ''${pkgs.apparmor-parser}/bin/apparmor_parser -Rv "${p}"''
5252- ) cfg.profiles;
5353- ExecReload = map (p:
5454- ''${pkgs.apparmor-parser}/bin/apparmor_parser --reload ${paths} "${p}"''
5555- ) cfg.profiles;
5656- };
5757- };
5858- };
197197+ meta.maintainers = with lib.maintainers; [ julm ];
59198}
+301
nixos/modules/security/apparmor/includes.nix
···11+{ config, lib, pkgs, ... }:
22+let
33+ inherit (builtins) attrNames hasAttr isAttrs;
44+ inherit (lib) getLib;
55+ inherit (config.environment) etc;
66+ etcRule = arg:
77+ let go = {path ? null, mode ? "r", trail ? ""}:
88+ lib.optionalString (hasAttr path etc)
99+ "${mode} ${config.environment.etc.${path}.source}${trail},";
1010+ in if isAttrs arg
1111+ then go arg
1212+ else go {path=arg;};
1313+in
1414+{
1515+# FIXME: most of the etcRule calls below have been
1616+# written systematically by converting from apparmor-profiles's profiles
1717+# without testing nor deep understanding of their uses,
1818+# and thus may need more rules or can have less rules;
1919+# this remains to be determined case by case,
2020+# some may even be completely useless.
2121+config.security.apparmor.includes = {
2222+ # This one is included by <tunables/global>
2323+ # which is usualy included before any profile.
2424+ "abstractions/tunables/alias" = ''
2525+ alias /bin -> /run/current-system/sw/bin,
2626+ alias /lib/modules -> /run/current-system/kernel/lib/modules,
2727+ alias /sbin -> /run/current-system/sw/sbin,
2828+ alias /usr -> /run/current-system/sw,
2929+ '';
3030+ "abstractions/audio" = ''
3131+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/audio"
3232+ ${etcRule "asound.conf"}
3333+ ${etcRule "esound/esd.conf"}
3434+ ${etcRule "libao.conf"}
3535+ ${etcRule {path="pulse"; trail="/";}}
3636+ ${etcRule {path="pulse"; trail="/**";}}
3737+ ${etcRule {path="sound"; trail="/";}}
3838+ ${etcRule {path="sound"; trail="/**";}}
3939+ ${etcRule {path="alsa/conf.d"; trail="/";}}
4040+ ${etcRule {path="alsa/conf.d"; trail="/*";}}
4141+ ${etcRule "openal/alsoft.conf"}
4242+ ${etcRule "wildmidi/wildmidi.conf"}
4343+ '';
4444+ "abstractions/authentication" = ''
4545+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/authentication"
4646+ # Defined in security.pam
4747+ include <abstractions/pam>
4848+ ${etcRule "nologin"}
4949+ ${etcRule "securetty"}
5050+ ${etcRule {path="security"; trail="/*";}}
5151+ ${etcRule "shadow"}
5252+ ${etcRule "gshadow"}
5353+ ${etcRule "pwdb.conf"}
5454+ ${etcRule "default/passwd"}
5555+ ${etcRule "login.defs"}
5656+ '';
5757+ "abstractions/base" = ''
5858+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/base"
5959+ r ${pkgs.stdenv.cc.libc}/share/locale/**,
6060+ r ${pkgs.stdenv.cc.libc}/share/locale.alias,
6161+ ${lib.optionalString (pkgs.glibcLocales != null) "r ${pkgs.glibcLocales}/lib/locale/locale-archive,"}
6262+ ${etcRule "localtime"}
6363+ r ${pkgs.tzdata}/share/zoneinfo/**,
6464+ r ${pkgs.stdenv.cc.libc}/share/i18n/**,
6565+ '';
6666+ "abstractions/bash" = ''
6767+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/bash"
6868+ # system-wide bash configuration
6969+ ${etcRule "profile.dos"}
7070+ ${etcRule "profile"}
7171+ ${etcRule "profile.d"}
7272+ ${etcRule {path="profile.d"; trail="/*";}}
7373+ ${etcRule "bashrc"}
7474+ ${etcRule "bash.bashrc"}
7575+ ${etcRule "bash.bashrc.local"}
7676+ ${etcRule "bash_completion"}
7777+ ${etcRule "bash_completion.d"}
7878+ ${etcRule {path="bash_completion.d"; trail="/*";}}
7979+ # bash relies on system-wide readline configuration
8080+ ${etcRule "inputrc"}
8181+ # bash inspects filesystems at startup
8282+ # and /etc/mtab is linked to /proc/mounts
8383+ @{PROC}/mounts
8484+8585+ # run out of /etc/bash.bashrc
8686+ ${etcRule "DIR_COLORS"}
8787+ '';
8888+ "abstractions/cups-client" = ''
8989+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/cpus-client"
9090+ ${etcRule "cups/cups-client.conf"}
9191+ '';
9292+ "abstractions/consoles" = ''
9393+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/consoles"
9494+ '';
9595+ "abstractions/dbus-session-strict" = ''
9696+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/dbus-session-strict"
9797+ ${etcRule "machine-id"}
9898+ '';
9999+ "abstractions/dconf" = ''
100100+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/dconf"
101101+ ${etcRule {path="dconf"; trail="/**";}}
102102+ '';
103103+ "abstractions/dri-common" = ''
104104+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/dri-common"
105105+ ${etcRule "drirc"}
106106+ '';
107107+ # The config.fonts.fontconfig NixOS module adds many files to /etc/fonts/
108108+ # by symlinking them but without exporting them outside of its NixOS module,
109109+ # those are therefore added there to this "abstractions/fonts".
110110+ "abstractions/fonts" = ''
111111+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/fonts"
112112+ ${etcRule {path="fonts"; trail="/**";}}
113113+ '';
114114+ "abstractions/gnome" = ''
115115+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/gnome"
116116+ ${etcRule {path="gnome"; trail="/gtkrc*";}}
117117+ ${etcRule {path="gtk"; trail="/*";}}
118118+ ${etcRule {path="gtk-2.0"; trail="/*";}}
119119+ ${etcRule {path="gtk-3.0"; trail="/*";}}
120120+ ${etcRule "orbitrc"}
121121+ include <abstractions/fonts>
122122+ ${etcRule {path="pango"; trail="/*";}}
123123+ ${etcRule {path="/etc/gnome-vfs-2.0"; trail="/modules/";}}
124124+ ${etcRule {path="/etc/gnome-vfs-2.0"; trail="/modules/*";}}
125125+ ${etcRule "papersize"}
126126+ ${etcRule {path="cups"; trail="/lpoptions";}}
127127+ ${etcRule {path="gnome"; trail="/defaults.list";}}
128128+ ${etcRule {path="xdg"; trail="/{,*-}mimeapps.list";}}
129129+ ${etcRule "xdg/mimeapps.list"}
130130+ '';
131131+ "abstractions/kde" = ''
132132+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/kde"
133133+ ${etcRule {path="qt3"; trail="/kstylerc";}}
134134+ ${etcRule {path="qt3"; trail="/qt_plugins_3.3rc";}}
135135+ ${etcRule {path="qt3"; trail="/qtrc";}}
136136+ ${etcRule "kderc"}
137137+ ${etcRule {path="kde3"; trail="/*";}}
138138+ ${etcRule "kde4rc"}
139139+ ${etcRule {path="xdg"; trail="/kdeglobals";}}
140140+ ${etcRule {path="xdg"; trail="/Trolltech.conf";}}
141141+ '';
142142+ "abstractions/kerberosclient" = ''
143143+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/kerberosclient"
144144+ ${etcRule {path="krb5.keytab"; mode="rk";}}
145145+ ${etcRule "krb5.conf"}
146146+ ${etcRule "krb5.conf.d"}
147147+ ${etcRule {path="krb5.conf.d"; trail="/*";}}
148148+149149+ # config files found via strings on libs
150150+ ${etcRule "krb.conf"}
151151+ ${etcRule "krb.realms"}
152152+ ${etcRule "srvtab"}
153153+ '';
154154+ "abstractions/ldapclient" = ''
155155+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/ldapclient"
156156+ ${etcRule "ldap.conf"}
157157+ ${etcRule "ldap.secret"}
158158+ ${etcRule {path="openldap"; trail="/*";}}
159159+ ${etcRule {path="openldap"; trail="/cacerts/*";}}
160160+ ${etcRule {path="sasl2"; trail="/*";}}
161161+ '';
162162+ "abstractions/likewise" = ''
163163+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/likewise"
164164+ '';
165165+ "abstractions/mdns" = ''
166166+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/mdns"
167167+ ${etcRule "nss_mdns.conf"}
168168+ '';
169169+ "abstractions/nameservice" = ''
170170+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/nameservice"
171171+172172+ # Many programs wish to perform nameservice-like operations, such as
173173+ # looking up users by name or id, groups by name or id, hosts by name
174174+ # or IP, etc. These operations may be performed through files, dns,
175175+ # NIS, NIS+, LDAP, hesiod, wins, etc. Allow them all here.
176176+ ${etcRule "group"}
177177+ ${etcRule "host.conf"}
178178+ ${etcRule "hosts"}
179179+ ${etcRule "nsswitch.conf"}
180180+ ${etcRule "gai.conf"}
181181+ ${etcRule "passwd"}
182182+ ${etcRule "protocols"}
183183+184184+ # libtirpc (used for NIS/YP login) needs this
185185+ ${etcRule "netconfig"}
186186+187187+ ${etcRule "resolv.conf"}
188188+189189+ ${etcRule {path="samba"; trail="/lmhosts";}}
190190+ ${etcRule "services"}
191191+192192+ ${etcRule "default/nss"}
193193+194194+ # libnl-3-200 via libnss-gw-name
195195+ ${etcRule {path="libnl"; trail="/classid";}}
196196+ ${etcRule {path="libnl-3"; trail="/classid";}}
197197+198198+ mr ${getLib pkgs.nss}/lib/libnss_*.so*,
199199+ mr ${getLib pkgs.nss}/lib64/libnss_*.so*,
200200+ '';
201201+ "abstractions/nis" = ''
202202+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/nis"
203203+ '';
204204+ "abstractions/nvidia" = ''
205205+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/nvidia"
206206+ ${etcRule "vdpau_wrapper.cfg"}
207207+ '';
208208+ "abstractions/opencl-common" = ''
209209+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/opencl-common"
210210+ ${etcRule {path="OpenCL"; trail="/**";}}
211211+ '';
212212+ "abstractions/opencl-mesa" = ''
213213+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/opencl-mesa"
214214+ ${etcRule "default/drirc"}
215215+ '';
216216+ "abstractions/openssl" = ''
217217+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/openssl"
218218+ ${etcRule {path="ssl"; trail="/openssl.cnf";}}
219219+ '';
220220+ "abstractions/p11-kit" = ''
221221+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/p11-kit"
222222+ ${etcRule {path="pkcs11"; trail="/";}}
223223+ ${etcRule {path="pkcs11"; trail="/pkcs11.conf";}}
224224+ ${etcRule {path="pkcs11"; trail="/modules/";}}
225225+ ${etcRule {path="pkcs11"; trail="/modules/*";}}
226226+ '';
227227+ "abstractions/perl" = ''
228228+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/perl"
229229+ ${etcRule {path="perl"; trail="/**";}}
230230+ '';
231231+ "abstractions/php" = ''
232232+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/php"
233233+ ${etcRule {path="php"; trail="/**/";}}
234234+ ${etcRule {path="php5"; trail="/**/";}}
235235+ ${etcRule {path="php7"; trail="/**/";}}
236236+ ${etcRule {path="php"; trail="/**.ini";}}
237237+ ${etcRule {path="php5"; trail="/**.ini";}}
238238+ ${etcRule {path="php7"; trail="/**.ini";}}
239239+ '';
240240+ "abstractions/postfix-common" = ''
241241+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/postfix-common"
242242+ ${etcRule "mailname"}
243243+ ${etcRule {path="postfix"; trail="/*.cf";}}
244244+ ${etcRule "postfix/main.cf"}
245245+ ${etcRule "postfix/master.cf"}
246246+ '';
247247+ "abstractions/python" = ''
248248+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/python"
249249+ '';
250250+ "abstractions/qt5" = ''
251251+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/qt5"
252252+ ${etcRule {path="xdg"; trail="/QtProject/qtlogging.ini";}}
253253+ ${etcRule {path="xdg/QtProject"; trail="/qtlogging.ini";}}
254254+ ${etcRule "xdg/QtProject/qtlogging.ini"}
255255+ '';
256256+ "abstractions/samba" = ''
257257+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/samba"
258258+ ${etcRule {path="samba"; trail="/*";}}
259259+ '';
260260+ "abstractions/ssl_certs" = ''
261261+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/ssl_certs"
262262+ ${etcRule "ssl/certs/ca-certificates.crt"}
263263+ ${etcRule "ssl/certs/ca-bundle.crt"}
264264+ ${etcRule "pki/tls/certs/ca-bundle.crt"}
265265+266266+ ${etcRule {path="ssl/trust"; trail="/";}}
267267+ ${etcRule {path="ssl/trust"; trail="/*";}}
268268+ ${etcRule {path="ssl/trust/anchors"; trail="/";}}
269269+ ${etcRule {path="ssl/trust/anchors"; trail="/**";}}
270270+ ${etcRule {path="pki/trust"; trail="/";}}
271271+ ${etcRule {path="pki/trust"; trail="/*";}}
272272+ ${etcRule {path="pki/trust/anchors"; trail="/";}}
273273+ ${etcRule {path="pki/trust/anchors"; trail="/**";}}
274274+275275+ # security.acme NixOS module
276276+ r /var/lib/acme/*/cert.pem,
277277+ r /var/lib/acme/*/chain.pem,
278278+ r /var/lib/acme/*/fullchain.pem,
279279+ '';
280280+ "abstractions/ssl_keys" = ''
281281+ # security.acme NixOS module
282282+ r /var/lib/acme/*/full.pem,
283283+ r /var/lib/acme/*/key.pem,
284284+ '';
285285+ "abstractions/vulkan" = ''
286286+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/vulkan"
287287+ ${etcRule {path="vulkan/icd.d"; trail="/";}}
288288+ ${etcRule {path="vulkan/icd.d"; trail="/*.json";}}
289289+ '';
290290+ "abstractions/winbind" = ''
291291+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/winbind"
292292+ ${etcRule {path="samba"; trail="/smb.conf";}}
293293+ ${etcRule {path="samba"; trail="/dhcp.conf";}}
294294+ '';
295295+ "abstractions/X" = ''
296296+ include "${pkgs.apparmor-profiles}/etc/apparmor.d/abstractions/X"
297297+ ${etcRule {path="X11/cursors"; trail="/";}}
298298+ ${etcRule {path="X11/cursors"; trail="/**";}}
299299+ '';
300300+};
301301+}
+11
nixos/modules/security/apparmor/profiles.nix
···11+{ config, lib, pkgs, ... }:
22+let apparmor = config.security.apparmor; in
33+{
44+config.security.apparmor.packages = [ pkgs.apparmor-profiles ];
55+config.security.apparmor.policies."bin.ping".profile = lib.mkIf apparmor.policies."bin.ping".enable ''
66+ include "${pkgs.iputils.apparmor}/bin.ping"
77+ include "${pkgs.inetutils.apparmor}/bin.ping"
88+ # Note that including those two profiles in the same profile
99+ # would not work if the second one were to re-include <tunables/global>.
1010+'';
1111+}