[pmg-devel] [PATCH pmg-api] ship AppArmor feature file

Stoiko Ivanov s.ivanov at proxmox.com
Thu Aug 1 11:06:50 CEST 2019


With Debian Buster AppArmor is enabled by default. Since we use a different
kernel (from pve) the pinned App Armor Feature ABI [0] shipped by upstream
does lead to problems with certain applications, which have a aa profile (e.g.
unbound)

The postrm and preinst maintainer scripts are taken (with minor modifications
of comments and replacement of the package name and version) from pve-lxc.

The aa-feature file was generated by:
* commenting the feature-file option in /etc/apparmor/parser.conf
* removing the directories in /var/cache/apparmor/*
* rebooting with 5.0.18-1-pve
* copying the .features from /var/cache/apparmor/$hash/

Tested by rebooting with the file and config in place and successfully starting
unbound (with AA-profile present and in enforce mode).

[0] https://gitlab.com/apparmor/apparmor/wikis/AppArmorFeatureABI

Signed-off-by: Stoiko Ivanov <s.ivanov at proxmox.com>
---
Huge Thanks to Fabian Gruenbichler and Wolfgang Bumiller for pointing me in the
right direction! Would be grateful for a review by eyes more experienced with
AA.


 debian/postrm   | 24 +++++++++++++++
 debian/preinst  | 27 +++++++++++++++++
 src/Makefile    |  1 +
 src/aa-features | 78 +++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 130 insertions(+)
 create mode 100644 debian/postrm
 create mode 100644 debian/preinst
 create mode 100644 src/aa-features

diff --git a/debian/postrm b/debian/postrm
new file mode 100644
index 0000000..9443edb
--- /dev/null
+++ b/debian/postrm
@@ -0,0 +1,24 @@
+#! /bin/sh
+
+set -e
+
+# remove diversion of apparmor feature pinning file, see preinst
+aa_feature_remove_diversion() {
+  dpkg-divert --package pmg-api --remove --rename \
+      --divert /usr/share/apparmor-features/features.stock \
+      /usr/share/apparmor-features/features
+}
+
+case "$1" in
+  abort-upgrade)
+    if dpkg --compare-versions "$2" 'lt' '6.0-1+2'; then
+      aa_feature_remove_diversion
+    fi
+    ;;
+  remove|abort-install|disappear)
+    aa_feature_remove_diversion
+    ;;
+esac
+
+exit 0
+
diff --git a/debian/preinst b/debian/preinst
new file mode 100644
index 0000000..f091f9f
--- /dev/null
+++ b/debian/preinst
@@ -0,0 +1,27 @@
+#! /bin/sh
+
+set -e
+
+# divert apparmor feature pinning file
+# Debian 9.4+ pins to apparmor kernel feature sets
+# Debian 10.0+ enables apparmor by default
+# since we use a newer kernel we need to ship its feature set
+aa_feature_add_diversion() {
+  dpkg-divert --package pmg-api --add --rename \
+      --divert /usr/share/apparmor-features/features.stock \
+      /usr/share/apparmor-features/features
+}
+
+case "$1" in
+  upgrade)
+    if dpkg --compare-versions "$2" 'lt' '6.0-1+2'; then
+      aa_feature_add_diversion
+    fi
+    ;;
+  *)
+    aa_feature_add_diversion
+    ;;
+esac
+
+exit 0
+
diff --git a/src/Makefile b/src/Makefile
index c864ae8..c254b5d 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -186,6 +186,7 @@ install: ${SOURCES} $(addsuffix .service-bash-completion, ${SERVICES}) $(addsuff
 	install -d -m 0755 ${DESTDIR}/lib/systemd/system
 	for i in ${TIMER_UNITS}; do install -m 0644 $$i ${DESTDIR}/lib/systemd/system/; done
 	install -D -m 0644 pmg-initramfs.conf ${DESTDIR}/etc/initramfs-tools/conf.d/pmg-initramfs.conf
+	install -D -m 0644 aa-features ${DESTDIR}/usr/share/apparmor-features/features
 
 .PHONY: check
 check:
diff --git a/src/aa-features b/src/aa-features
new file mode 100644
index 0000000..9f272e6
--- /dev/null
+++ b/src/aa-features
@@ -0,0 +1,78 @@
+query {label {multi_transaction {yes
+}
+data {yes
+}
+perms {allow deny audit quiet
+}
+}
+}
+dbus {mask {acquire send receive
+}
+}
+signal {mask {hup int quit ill trap abrt bus fpe kill usr1 segv usr2 pipe alrm term stkflt chld cont stop stp ttin ttou urg xcpu xfsz vtalrm prof winch io pwr sys emt lost
+}
+}
+ptrace {mask {read trace
+}
+}
+caps {mask {chown dac_override dac_read_search fowner fsetid kill setgid setuid setpcap linux_immutable net_bind_service net_broadcast net_admin net_raw ipc_lock ipc_owner sys_module sys_rawio sys_chroot sys_ptrace sys_pacct sys_admin sys_boot sys_nice sys_resource sys_time sys_tty_config mknod lease audit_write audit_control setfcap mac_override mac_admin syslog wake_alarm block_suspend audit_read
+}
+}
+rlimit {mask {cpu fsize data stack core rss nproc nofile memlock as locks sigpending msgqueue nice rtprio rttime
+}
+}
+capability {0xffffff
+}
+namespaces {pivot_root {no
+}
+profile {yes
+}
+}
+mount {mask {mount umount pivot_root
+}
+}
+network {af_unix {yes
+}
+af_mask {unspec unix inet ax25 ipx appletalk netrom bridge atmpvc x25 inet6 rose netbeui security key netlink packet ash econet atmsvc rds sna irda pppox wanpipe llc ib mpls can tipc bluetooth iucv rxrpc isdn phonet ieee802154 caif alg nfc vsock kcm qipcrtr smc xdp
+}
+}
+network_v8 {af_mask {unspec unix inet ax25 ipx appletalk netrom bridge atmpvc x25 inet6 rose netbeui security key netlink packet ash econet atmsvc rds sna irda pppox wanpipe llc ib mpls can tipc bluetooth iucv rxrpc isdn phonet ieee802154 caif alg nfc vsock kcm qipcrtr smc xdp
+}
+}
+file {mask {create read write exec append mmap_exec link lock
+}
+}
+domain {version {1.2
+}
+attach_conditions {xattr {yes
+}
+}
+computed_longest_left {yes
+}
+post_nnp_subset {yes
+}
+fix_binfmt_elf_mmap {yes
+}
+stack {yes
+}
+change_profile {yes
+}
+change_onexec {yes
+}
+change_hatv {yes
+}
+change_hat {yes
+}
+}
+policy {set_load {yes
+}
+versions {v8 {yes
+}
+v7 {yes
+}
+v6 {yes
+}
+v5 {yes
+}
+}
+}
-- 
2.20.1




More information about the pmg-devel mailing list