mirror of
https://github.com/ryan4yin/nix-config.git
synced 2026-09-09 19:32:05 +02:00
security: enable AppArmor (complain) on all Linux hosts
This commit is contained in:
@@ -4,56 +4,50 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
|
# AppArmor: activate the LSM + load policies. Roll out in complain mode first
|
||||||
|
# (log violations, never block) so nothing can break; promote profiles to
|
||||||
|
# "enforce" individually once stable.
|
||||||
services.dbus.apparmor = "enabled";
|
services.dbus.apparmor = "enabled";
|
||||||
|
|
||||||
security.apparmor = {
|
security.apparmor = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
||||||
# kill process that are not confined but have apparmor profiles enabled
|
# Do not SIGTERM running unconfined-but-confinable processes yet.
|
||||||
killUnconfinedConfinables = true;
|
# Safe to flip to true later now that no global default-deny profile is active.
|
||||||
packages = with pkgs; [
|
killUnconfinedConfinables = false;
|
||||||
apparmor-utils
|
|
||||||
apparmor-profiles
|
# Packages contributing to AppArmor's include path (abstractions).
|
||||||
];
|
# NOTE: these are FHS-oriented; nixpkgs adds FHS->NixOS aliases so they mostly work,
|
||||||
|
# but treat resulting profiles as complain-only until verified.
|
||||||
|
packages = [ pkgs.apparmor-profiles ];
|
||||||
|
|
||||||
# apparmor policies
|
|
||||||
policies = {
|
policies = {
|
||||||
|
# Global default-deny scaffold. DANGEROUS to enable: `/**` matches every binary and
|
||||||
|
# the empty block allows nothing. Keep disabled until per-app profiles exist.
|
||||||
"default_deny" = {
|
"default_deny" = {
|
||||||
enforce = false;
|
state = "disable";
|
||||||
enable = false;
|
profile = "profile default_deny /** { }";
|
||||||
profile = ''
|
|
||||||
profile default_deny /** { }
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Confine sudo; complain mode so a missing rule logs instead of blocking.
|
||||||
"sudo" = {
|
"sudo" = {
|
||||||
enforce = false;
|
state = "complain";
|
||||||
enable = false;
|
|
||||||
profile = ''
|
profile = ''
|
||||||
${pkgs.sudo}/bin/sudo {
|
abi <abi/4.0>,
|
||||||
|
include <tunables/global>
|
||||||
|
|
||||||
|
profile ${pkgs.sudo}/bin/sudo {
|
||||||
|
include <abstractions/base>
|
||||||
file /** rwlkUx,
|
file /** rwlkUx,
|
||||||
}
|
}
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# nix runs unconfined (no restriction); inert, kept disabled.
|
||||||
"nix" = {
|
"nix" = {
|
||||||
enforce = false;
|
state = "disable";
|
||||||
enable = false;
|
profile = "profile ${config.nix.package}/bin/nix { unconfined, }";
|
||||||
profile = ''
|
|
||||||
${config.nix.package}/bin/nix {
|
|
||||||
unconfined,
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.systemPackages = with pkgs; [
|
|
||||||
apparmor-bin-utils
|
|
||||||
apparmor-profiles
|
|
||||||
apparmor-parser
|
|
||||||
libapparmor
|
|
||||||
apparmor-kernel-patches
|
|
||||||
apparmor-pam
|
|
||||||
apparmor-utils
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
{ mylib, ... }:
|
{ mylib, ... }:
|
||||||
{
|
{
|
||||||
imports = mylib.scanPaths ./.;
|
imports = mylib.scanPaths ./. ++ [ (mylib.relativeToRoot "hardening/apparmor") ];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
lib,
|
lib,
|
||||||
pkgs,
|
pkgs,
|
||||||
|
mylib,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
{
|
{
|
||||||
@@ -15,6 +16,9 @@
|
|||||||
../base/user-group.nix
|
../base/user-group.nix
|
||||||
|
|
||||||
../../base
|
../../base
|
||||||
|
# AppArmor is wired via modules/nixos/base/default.nix for other hosts; this
|
||||||
|
# aarch64 server imports base files individually, so add it explicitly.
|
||||||
|
(mylib.relativeToRoot "hardening/apparmor")
|
||||||
];
|
];
|
||||||
|
|
||||||
# Servers run on the trusted internal LAN (NAT'd; WAN protected at the router).
|
# Servers run on the trusted internal LAN (NAT'd; WAN protected at the router).
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
outputs,
|
||||||
|
}:
|
||||||
|
lib.genAttrs (builtins.attrNames outputs.nixosConfigurations) (_: true)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
outputs,
|
||||||
|
}:
|
||||||
|
lib.genAttrs (builtins.attrNames outputs.nixosConfigurations) (
|
||||||
|
name: outputs.nixosConfigurations.${name}.config.security.apparmor.enable
|
||||||
|
)
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
outputs,
|
||||||
|
}:
|
||||||
|
lib.genAttrs (builtins.attrNames outputs.nixosConfigurations) (_: true)
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
lib,
|
||||||
|
outputs,
|
||||||
|
}:
|
||||||
|
lib.genAttrs (builtins.attrNames outputs.nixosConfigurations) (
|
||||||
|
name: outputs.nixosConfigurations.${name}.config.security.apparmor.enable
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user