The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/7991

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
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 <stgra...@ubuntu.com>
From f69844954acb125f4adeb3cfc04fc03f8696eede Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@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 <stgra...@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.
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to