2014-04-14 16:26:48 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
2013-05-13 15:13:06 +02:00
|
|
|
|
2012-07-17 01:47:41 +02:00
|
|
|
let
|
2015-03-12 10:11:25 +01:00
|
|
|
inherit (lib) mkIf mkOption types concatMapStrings;
|
2012-07-17 01:47:41 +02:00
|
|
|
cfg = config.security.apparmor;
|
|
|
|
in
|
2015-03-12 10:11:25 +01:00
|
|
|
|
2012-07-17 01:47:41 +02:00
|
|
|
{
|
2015-03-12 10:11:25 +01:00
|
|
|
options = {
|
|
|
|
security.apparmor = {
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = "Enable the AppArmor Mandatory Access Control system.";
|
|
|
|
};
|
|
|
|
profiles = mkOption {
|
|
|
|
type = types.listOf types.path;
|
|
|
|
default = [];
|
|
|
|
description = "List of files containing AppArmor profiles.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2015-03-17 11:04:31 +01:00
|
|
|
environment.systemPackages = [ pkgs.apparmor-utils ];
|
2015-03-12 10:11:25 +01:00
|
|
|
|
|
|
|
systemd.services.apparmor = {
|
|
|
|
wantedBy = [ "local-fs.target" ];
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = "yes";
|
|
|
|
ExecStart = concatMapStrings (p:
|
|
|
|
''${pkgs.apparmor-parser}/bin/apparmor_parser -rKv -I ${pkgs.apparmor-profiles}/etc/apparmor.d "${p}" ; ''
|
|
|
|
) cfg.profiles;
|
|
|
|
ExecStop = concatMapStrings (p:
|
|
|
|
''${pkgs.apparmor-parser}/bin/apparmor_parser -Rv "${p}" ; ''
|
|
|
|
) cfg.profiles;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
security.pam.services.apparmor.text = ''
|
2015-03-17 11:04:31 +01:00
|
|
|
## AppArmor changes hats according to `order`: first try user, then
|
|
|
|
## group, and finally fall back to a hat called "DEFAULT"
|
2015-03-12 10:11:25 +01:00
|
|
|
##
|
|
|
|
## For now, enable debugging as this is an experimental feature.
|
|
|
|
session optional ${pkgs.apparmor-pam}/lib/security/pam_apparmor.so order=user,group,default debug
|
|
|
|
'';
|
|
|
|
};
|
2012-07-17 01:47:41 +02:00
|
|
|
}
|