]> glassweightruler.freedombox.rocks Git - waydroid.git/commitdiff
Change apparmor profile at runtime
authorAlessandro Astone <ales.astone@gmail.com>
Mon, 14 Nov 2022 22:10:08 +0000 (23:10 +0100)
committerAlessandro Astone <ales.astone@gmail.com>
Fri, 18 Nov 2022 14:19:17 +0000 (15:19 +0100)
Makefile
tools/helpers/lxc.py

index a3ec1c8d953f851d4b94d1a92b27dd258d4b3e2f..c70814d34f2e6f29bc538192a63b292093ddb5d3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -39,8 +39,6 @@ install_apparmor:
        cp -f data/configs/apparmor_profiles/adbd $(INSTALL_APPARMOR_DIR)/adbd
        cp -f data/configs/apparmor_profiles/android_app $(INSTALL_APPARMOR_DIR)/android_app
        cp -f data/configs/apparmor_profiles/lxc-waydroid $(INSTALL_APPARMOR_DIR)/lxc/lxc-waydroid
-       sed --sandbox -i "/lxc.aa_profile/ s/unconfined/lxc-waydroid/g" $(DESTDIR)$(WAYDROID_DIR)/data/configs/config_1
-       sed --sandbox -i "/lxc.apparmor.profile/ s/unconfined/lxc-waydroid/g" $(DESTDIR)$(WAYDROID_DIR)/data/configs/config_2
        # Load the profiles if not just packaging
        if [ -z $(DESTDIR) ] && { aa-enabled --quiet || systemctl is-active -q apparmor; } 2>/dev/null; then \
                apparmor_parser -r -T -W "$(INSTALL_APPARMOR_DIR)/adbd"; \
index 45d5e5d0947136bf1f2b2baefb0de2a9b2284b53..e1a81e04ddb0396c41c75b002a8e9c5df58940f3 100644 (file)
@@ -127,6 +127,15 @@ def generate_nodes_lxc_config(args):
 
     return nodes
 
+LXC_APPARMOR_PROFILE = "lxc-waydroid"
+def get_apparmor_status(args):
+    enabled = False
+    if shutil.which("aa-status"):
+        enabled = (tools.helpers.run.user(args, ["aa-status", "--quiet"], check=False) == 0)
+    if not enabled and shutil.which("systemctl"):
+        enabled = (tools.helpers.run.user(args, ["systemctl", "is-active", "-q", "apparmor"], check=False) == 0)
+    enabled &= os.path.exists(os.path.join("/etc/apparmor.d/lxc", LXC_APPARMOR_PROFILE))
+    return enabled
 
 def set_lxc_config(args):
     lxc_path = tools.config.defaults["lxc"] + "/waydroid"
@@ -154,6 +163,9 @@ def set_lxc_config(args):
     tools.helpers.run.user(args, command)
     command = ["cp", "-fpr", seccomp_profile, lxc_path + "/waydroid.seccomp"]
     tools.helpers.run.user(args, command)
+    if get_apparmor_status(args):
+        command = ["sed", "-i", "-E", "/lxc.aa_profile|lxc.apparmor.profile/ s/unconfined/{}/g".format(LXC_APPARMOR_PROFILE), lxc_path + "/config"]
+        tools.helpers.run.user(args, command)
 
     nodes = generate_nodes_lxc_config(args)
     config_nodes_tmp_path = args.work + "/config_nodes"