[lxc-devel] [lxd/master] lxd/apparmor/forkproxy: Socket path fixes

stgraber on Github lxc-bot at linuxcontainers.org
Tue Oct 6 19:29:23 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 533 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201006/8685fbaf/attachment.bin>
-------------- next part --------------
From f69844954acb125f4adeb3cfc04fc03f8696eede Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 6 Oct 2020 15:27:57 -0400
Subject: [PATCH] lxd/apparmor/forkproxy: Socket path fixes
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This handles two issues:
 - Symlinks that need to be dereferenced.
 - Ubuntu Core systems where the initial path should be used rather than
   the HostPath.

Closes #5009

Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 lxd/apparmor/instance_forkproxy.go | 31 ++++++++++++++++++++++++++++--
 1 file changed, 29 insertions(+), 2 deletions(-)

diff --git a/lxd/apparmor/instance_forkproxy.go b/lxd/apparmor/instance_forkproxy.go
index 05fe662460..7b320f0056 100644
--- a/lxd/apparmor/instance_forkproxy.go
+++ b/lxd/apparmor/instance_forkproxy.go
@@ -99,7 +99,13 @@ func forkproxyProfile(state *state.State, inst instance, dev device) (string, er
 	fields := strings.SplitN(dev.Config()["listen"], ":", 2)
 	if fields[0] == "unix" && !strings.HasPrefix(fields[1], "@") {
 		if dev.Config()["bind"] == "host" || dev.Config()["bind"] == "" {
-			sockets = append(sockets, shared.HostPath(fields[1]))
+			hostPath := shared.HostPath(fields[1])
+			sockets = append(sockets, hostPath)
+
+			if hostPath != fields[1] {
+				// AppArmor can get confused on Ubuntu Core so allow both paths.
+				sockets = append(sockets, fields[1])
+			}
 		} else {
 			sockets = append(sockets, fields[1])
 		}
@@ -110,8 +116,29 @@ func forkproxyProfile(state *state.State, inst instance, dev device) (string, er
 		if dev.Config()["bind"] == "host" || dev.Config()["bind"] == "" {
 			sockets = append(sockets, fields[1])
 		} else {
-			sockets = append(sockets, shared.HostPath(fields[1]))
+			hostPath := shared.HostPath(fields[1])
+			sockets = append(sockets, hostPath)
+
+			if hostPath != fields[1] {
+				// AppArmor can get confused on Ubuntu Core so allow both paths.
+				sockets = append(sockets, fields[1])
+			}
+		}
+	}
+
+	// AppArmor requires deref of all paths.
+	for k := range sockets {
+		// Skip non-existing because of the additional entry for the host side.
+		if !shared.PathExists(sockets[k]) {
+			continue
 		}
+
+		v, err := filepath.EvalSymlinks(sockets[k])
+		if err != nil {
+			return "", err
+		}
+
+		sockets[k] = v
 	}
 
 	// Render the profile.


More information about the lxc-devel mailing list