summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoé Lopez <noelopez@free.fr>2025-12-08 16:39:11 +0100
committerRutherther <rutherther@ditigal.xyz>2025-12-22 22:48:57 +0100
commit587fd2dad49d8af3f31d06e29ff43c986d6f35c4 (patch)
tree83caa58ed08acc6dae900f219d4c7bcfb5927cc7
parent9a78e760762c1d93369e765bdce12388e1662ec6 (diff)
etc: Add AppArmor profile for the daemon.
* .gitignore: Add etc/apparmor.d/tunables/guix. * Makefile.am (nodist_apparmor_profile_DATA) (nodist_apparmor_profile_tunables_DATA): Define it. * configure.ac: Generate etc/apparmor.d/tunables/guix. Add --with-apparmor-profile-dir option. * etc/apparmor.d/guix-daemon: New file. * etc/apparmor.d/tunables/guix.in: New file. * doc/guix.texi: Document AppArmor profiles. * gnu/packages/package-management.scm (guix): Add future changes commented. Change-Id: Iac7df9d642383cc46a2d450c3badef31199ab041 Signed-off-by: Rutherther <rutherther@ditigal.xyz>
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am7
-rw-r--r--configure.ac10
-rw-r--r--doc/guix.texi41
-rw-r--r--etc/apparmor.d/guix-daemon88
-rw-r--r--etc/apparmor.d/tunables/guix.in5
-rw-r--r--gnu/packages/package-management.scm4
7 files changed, 156 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index 4f7308b295c..8779222df0c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,6 +68,7 @@
68/doc/stamp-vti 68/doc/stamp-vti
69/doc/version.texi 69/doc/version.texi
70/doc/version-*.texi 70/doc/version-*.texi
71/etc/apparmor.d/tunables/guix
71/etc/committer.scm 72/etc/committer.scm
72/etc/gnu-store.mount 73/etc/gnu-store.mount
73/etc/guix-daemon.cil 74/etc/guix-daemon.cil
diff --git a/Makefile.am b/Makefile.am
index 106849e89f0..bf7d1556f0e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -746,6 +746,13 @@ dist_fishcompletion_DATA = etc/completion/fish/guix.fish
746# SELinux policy 746# SELinux policy
747nodist_selinux_policy_DATA = etc/guix-daemon.cil 747nodist_selinux_policy_DATA = etc/guix-daemon.cil
748 748
749# AppArmor profiles.
750nodist_apparmor_profile_DATA = \
751 etc/apparmor.d/guix-daemon
752
753nodist_apparmor_profile_tunables_DATA = \
754 etc/apparmor.d/tunables/guix
755
749EXTRA_DIST += \ 756EXTRA_DIST += \
750 .dir-locals.el \ 757 .dir-locals.el \
751 .guix-authorizations \ 758 .guix-authorizations \
diff --git a/configure.ac b/configure.ac
index 82f12507745..6ad8e427736 100644
--- a/configure.ac
+++ b/configure.ac
@@ -81,6 +81,15 @@ AC_ARG_WITH([selinux-policy-dir],
81 [selinux_policydir='${datadir}/selinux/']) 81 [selinux_policydir='${datadir}/selinux/'])
82AC_SUBST([selinux_policydir]) 82AC_SUBST([selinux_policydir])
83 83
84AC_ARG_WITH([apparmor-profile-dir],
85 AS_HELP_STRING([--with-apparmor-profile-dir=DIR],
86 [name of the AppArmor profile directory]),
87 [apparmor_profiledir="$withval"],
88 [apparmor_profiledir='${sysconfdir}/apparmor.d'])
89AC_SUBST([apparmor_profiledir])
90apparmor_profile_tunablesdir='${apparmor_profiledir}/tunables'
91AC_SUBST([apparmor_profile_tunablesdir])
92
84dnl Better be verbose. 93dnl Better be verbose.
85AC_MSG_CHECKING([for the store directory]) 94AC_MSG_CHECKING([for the store directory])
86AC_MSG_RESULT([$storedir]) 95AC_MSG_RESULT([$storedir])
@@ -308,6 +317,7 @@ AC_CONFIG_FILES([Makefile
308 po/guix/Makefile.in 317 po/guix/Makefile.in
309 po/packages/Makefile.in 318 po/packages/Makefile.in
310 etc/guix-daemon.cil 319 etc/guix-daemon.cil
320 etc/apparmor.d/tunables/guix
311 guix/config.scm]) 321 guix/config.scm])
312 322
313AC_CONFIG_FILES([etc/committer.scm], [chmod +x etc/committer.scm]) 323AC_CONFIG_FILES([etc/committer.scm], [chmod +x etc/committer.scm])
diff --git a/doc/guix.texi b/doc/guix.texi
index d7d40ceb223..fc25b653f32 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -146,6 +146,7 @@ Copyright @copyright{} 2025 Artur Wroblewski@*
146Copyright @copyright{} 2025 Edouard Klein@* 146Copyright @copyright{} 2025 Edouard Klein@*
147Copyright @copyright{} 2025 Rodion Goritskov@* 147Copyright @copyright{} 2025 Rodion Goritskov@*
148Copyright @copyright{} 2025 dan@* 148Copyright @copyright{} 2025 dan@*
149Copyright @copyright{} 2025 Noé Lopez@*
149 150
150Permission is granted to copy, distribute and/or modify this document 151Permission is granted to copy, distribute and/or modify this document
151under the terms of the GNU Free Documentation License, Version 1.3 or 152under the terms of the GNU Free Documentation License, Version 1.3 or
@@ -919,6 +920,7 @@ pre-built binaries.
919* Build Environment Setup:: Preparing the isolated build environment. 920* Build Environment Setup:: Preparing the isolated build environment.
920* Daemon Offload Setup:: Offloading builds to remote machines. 921* Daemon Offload Setup:: Offloading builds to remote machines.
921* SELinux Support:: Using an SELinux policy for the daemon. 922* SELinux Support:: Using an SELinux policy for the daemon.
923* AppArmor Support:: Using an AppArmor profile for the daemon.
922@end menu 924@end menu
923 925
924@node Build Environment Setup 926@node Build Environment Setup
@@ -1097,6 +1099,8 @@ systemctl daemon-reload
1097systemctl start guix-daemon 1099systemctl start guix-daemon
1098@end example 1100@end example
1099 1101
1102If your system has AppArmor enabled, @pxref{AppArmor Support}.
1103
1100@quotation Warning 1104@quotation Warning
1101The commands above assume that @command{guix pull} was run for the root 1105The commands above assume that @command{guix pull} was run for the root
1102user. You can check whether this is the case by running this command: 1106user. You can check whether this is the case by running this command:
@@ -1526,6 +1530,43 @@ installation time whenever the Guix package that provides the
1526effectively running @code{guix-daemon} executable is upgraded. 1530effectively running @code{guix-daemon} executable is upgraded.
1527@end enumerate 1531@end enumerate
1528 1532
1533@node AppArmor Support
1534@subsection AppArmor Support
1535
1536@cindex AppArmor
1537
1538Guix includes an AppArmor profile for the build daemon in
1539@file{etc/apparmor.d/guix-daemon} that can be installed on systems with
1540strict AppArmor policies to allow it to run unprivileged
1541(@pxref{Build Environment Setup}). Indeed, the unprivileged daemon makes
1542use of Linux user namespaces but these are disallowed
1543without an AppArmor policy on some systems like Ubuntu.
1544
1545To know if this applies to you, check if the
1546@code{kernel.apparmor_restrict_unprivileged_userns} kernel parameter is
1547enabled.
1548
1549@subsubsection Installing the AppArmor profile
1550@cindex AppArmor, profile installation
1551
1552@quotation Note
1553The @code{guix-install.sh} binary installation script offers to perform
1554the steps below for you (@pxref{Binary Installation}).
1555@end quotation
1556
1557Run these commands as root to install the profile:
1558
1559@example
1560export apparmor_sources=/var/guix/profiles/per-user/root/current-guix/etc/apparmor.d
1561cp -f -t /etc/apparmor.d/tunables "$apparmor_sources/tunables/guix"
1562cp -f -t /etc/apparmor.d "$apparmor_sources/guix-daemon"
1563cp -f -t /etc/apparmor.d "$apparmor_sources/guix"
1564apparmor_parser -r /etc/apparmor.d/guix-daemon
1565apparmor_parser -r /etc/apparmor.d/guix
1566@end example
1567
1568After this, the build daemon will be able to function correctly.
1569
1529@node Invoking guix-daemon 1570@node Invoking guix-daemon
1530@section Invoking @command{guix-daemon} 1571@section Invoking @command{guix-daemon}
1531@cindex @command{guix-daemon} 1572@cindex @command{guix-daemon}
diff --git a/etc/apparmor.d/guix-daemon b/etc/apparmor.d/guix-daemon
new file mode 100644
index 00000000000..cb1ee92685c
--- /dev/null
+++ b/etc/apparmor.d/guix-daemon
@@ -0,0 +1,88 @@
1abi <abi/4.0>,
2
3include <tunables/global>
4include <tunables/guix>
5
6profile guix-daemon @{guix_storedir}/*-{guix-daemon,guix}-*/bin/guix-daemon flags=(enforce,attach_disconnected.path=/disconnected) {
7 include <abstractions/base>
8
9 userns,
10 signal,
11 capability sys_admin,
12 capability net_admin,
13 capability sys_chroot,
14 capability setgid,
15 capability chown,
16 network dgram,
17 umount,
18 mount,
19 pivot_root,
20 # Paths inside build chroot
21 /real-root/ w,
22 / w,
23
24 @{guix_localstatedir}/guix/** rwk,
25 /var/log/guix/** w,
26 owner @{PROC}/@{pid}/{fd/,environ} r,
27 owner @{PROC}/@{pid}/oom_score_adj w,
28 owner @{PROC}/@{pid}/uid_map rw,
29 owner @{PROC}/@{pid}/gid_map rw,
30 owner @{PROC}/@{pid}/setgroups w,
31 @{guix_storedir}/ r,
32 @{guix_storedir}/** rwlmk,
33 @{guix_storedir}/*/bin/guile cx -> guix-builder,
34 @{guix_storedir}/*-guix-command cx -> guix-helper,
35 @{guix_storedir}/*-guix-*/bin/guix cx -> guix-helper,
36 @{etc_rw}/nsswitch.conf r,
37 @{etc_rw}/passwd r,
38 @{etc_rw}/group r,
39 owner /tmp/** rwl,
40 owner /var/tmp/** rwl,
41
42 /usr/bin/newgidmap Ux,
43
44 # Site-specific additions and overrides. See local/README for details.
45 include if exists <local/guix-daemon>
46
47 profile guix-builder flags=(enforce,attach_disconnected.path=/disconnected) {
48 include <abstractions/base>
49
50 signal (receive),
51
52 @{guix_storedir}/** rwlmkux,
53
54 owner /tmp/** rw,
55
56 @{PROC}/@{pid}/fd/ r,
57
58 /disconnected/** rw,
59 }
60
61 # This is for any time guix is called by the daemon as a helper:
62 # - guix download
63 # - guix discover
64 # - guix gc --list-busy
65 # - probably more?
66 profile guix-helper flags=(enforce,attach_disconnected.path=/disconnected) {
67 include <abstractions/base>
68 include <abstractions/nameservice>
69
70 signal (receive),
71 ptrace (read) peer=guix-daemon,
72
73 /disconnected/run/dbus/system_bus_socket rw,
74 dbus (send, receive),
75 @{guix_localstatedir}/guix/discover/ rw,
76 @{guix_localstatedir}/guix/discover/* rw,
77
78 @{guix_localstatedir}/guix/substitute/ rw,
79 @{guix_localstatedir}/guix/substitute/** rwk,
80
81 @{guix_sysconfdir}/guix/** r,
82
83 @{guix_storedir}/** rwlmix,
84
85 @{PROC}/ r,
86 owner @{PROC}/@{pid}/{fd/,environ} r,
87 }
88}
diff --git a/etc/apparmor.d/tunables/guix.in b/etc/apparmor.d/tunables/guix.in
new file mode 100644
index 00000000000..e93f7caeb7d
--- /dev/null
+++ b/etc/apparmor.d/tunables/guix.in
@@ -0,0 +1,5 @@
1@{guix_storedir} = @storedir@
2@{guix_sysconfdir} = @guix_sysconfdir@
3@{guix_localstatedir} = @guix_localstatedir@
4
5include if exists <tunables/guix.d> \ No newline at end of file
diff --git a/gnu/packages/package-management.scm b/gnu/packages/package-management.scm
index f04bd5efd9f..eadaea4967d 100644
--- a/gnu/packages/package-management.scm
+++ b/gnu/packages/package-management.scm
@@ -234,6 +234,10 @@
234 (string-append "--with-bash-completion-dir=" 234 (string-append "--with-bash-completion-dir="
235 (assoc-ref %outputs "out") 235 (assoc-ref %outputs "out")
236 "/etc/bash_completion.d") 236 "/etc/bash_completion.d")
237 ;; TODO: Uncomment after guix is updated.
238 ;; (string-append "--with-apparmor-profile-dir="
239 ;; (assoc-ref %outputs "out")
240 ;; "/etc/apparmor.d")
237 241
238 ;; Set 'DOT_USER_PROGRAM' to the empty string so 242 ;; Set 'DOT_USER_PROGRAM' to the empty string so
239 ;; we don't keep a reference to Graphviz, whose 243 ;; we don't keep a reference to Graphviz, whose