[lxc-devel] [lxd/master] Instance: Fix a class of bugs related to incorrect log path generation when instance is in non-default project
tomponline on Github
lxc-bot at linuxcontainers.org
Tue Oct 20 13:18:44 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 674 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201020/59091e9a/attachment.bin>
-------------- next part --------------
From 0364002a9db6bfa9707710b7b64a5ca0a93514a5 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 20 Oct 2020 13:51:58 +0100
Subject: [PATCH 1/5] lxd/instance: Use project aware inst.LogPath() function
when clearing log dir in instanceCreateInternal
Avoids clearing lxc.conf of a different container and preventing access to it.
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/instance.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxd/instance.go b/lxd/instance.go
index 2d812f6b97..71718a6390 100644
--- a/lxd/instance.go
+++ b/lxd/instance.go
@@ -640,15 +640,15 @@ func instanceCreateInternal(s *state.State, args db.InstanceArgs) (instance.Inst
s.Cluster.DeleteInstance(dbInst.Project, dbInst.Name)
}()
- // Wipe any existing log for this instance name.
- os.RemoveAll(shared.LogPath(args.Name))
-
args = db.InstanceToArgs(&dbInst)
inst, err := instance.Create(s, args)
if err != nil {
return nil, errors.Wrap(err, "Create instance")
}
+ // Wipe any existing log for this instance name.
+ os.RemoveAll(inst.LogPath())
+
revert = false
return inst, nil
}
From c029aab2ca63ea6a83f6f73be8d0e8b7a827a525 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 20 Oct 2020 13:57:21 +0100
Subject: [PATCH 2/5] lxd/instance/drivers/driver/lxc: Project aware rename of
log path in Rename()
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/instance/drivers/driver_lxc.go | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index e4290118f5..e99c01f4df 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -3682,9 +3682,10 @@ func (c *lxc) Rename(newName string) error {
}
// Rename the logging path.
- os.RemoveAll(shared.LogPath(newName))
+ newFullName := project.Instance(c.Project(), c.Name())
+ os.RemoveAll(shared.LogPath(newFullName))
if shared.PathExists(c.LogPath()) {
- err := os.Rename(c.LogPath(), shared.LogPath(newName))
+ err := os.Rename(c.LogPath(), shared.LogPath(newFullName))
if err != nil {
logger.Error("Failed renaming container", ctxMap)
return err
From feb558885cbedfbbf55911a5cba96d0890720b74 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 20 Oct 2020 13:58:18 +0100
Subject: [PATCH 3/5] lxd/instance/drivers/driver/qemu: Project aware rename of
log path in Rename()
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/instance/drivers/driver_qemu.go | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lxd/instance/drivers/driver_qemu.go b/lxd/instance/drivers/driver_qemu.go
index 1abaddbbb2..733a868605 100644
--- a/lxd/instance/drivers/driver_qemu.go
+++ b/lxd/instance/drivers/driver_qemu.go
@@ -2647,9 +2647,10 @@ func (vm *qemu) Rename(newName string) error {
}
// Rename the logging path.
- os.RemoveAll(shared.LogPath(newName))
+ newFullName := project.Instance(vm.Project(), vm.Name())
+ os.RemoveAll(shared.LogPath(newFullName))
if shared.PathExists(vm.LogPath()) {
- err := os.Rename(vm.LogPath(), shared.LogPath(newName))
+ err := os.Rename(vm.LogPath(), shared.LogPath(newFullName))
if err != nil {
logger.Error("Failed renaming instance", ctxMap)
return err
From fa7f5e39b6ad4cd27b6e0dd38a3d79d9c147c293 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 20 Oct 2020 14:00:26 +0100
Subject: [PATCH 4/5] lxd/instance/drivers/driver/lxc: Makes collectCRIULogFile
project log path aware
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/instance/drivers/driver_lxc.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lxd/instance/drivers/driver_lxc.go b/lxd/instance/drivers/driver_lxc.go
index e99c01f4df..81d814e3df 100644
--- a/lxd/instance/drivers/driver_lxc.go
+++ b/lxd/instance/drivers/driver_lxc.go
@@ -4815,7 +4815,7 @@ func (c *lxc) Export(w io.Writer, properties map[string]string) (api.ImageMetada
func collectCRIULogFile(c instance.Instance, imagesDir string, function string, method string) error {
t := time.Now().Format(time.RFC3339)
- newPath := shared.LogPath(c.Name(), fmt.Sprintf("%s_%s_%s.log", function, method, t))
+ newPath := filepath.Join(c.LogPath(), fmt.Sprintf("%s_%s_%s.log", function, method, t))
return shared.FileCopy(filepath.Join(imagesDir, fmt.Sprintf("%s.log", method)), newPath)
}
From 645ce23fa728eb3922df5466361e6ae0b344c5c4 Mon Sep 17 00:00:00 2001
From: Thomas Parrott <thomas.parrott at canonical.com>
Date: Tue, 20 Oct 2020 14:11:17 +0100
Subject: [PATCH 5/5] lxd/instance/logs: Makes containerLogsGet project aware
Signed-off-by: Thomas Parrott <thomas.parrott at canonical.com>
---
lxd/instance_logs.go | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/lxd/instance_logs.go b/lxd/instance_logs.go
index 0f7df6893b..c63fb5afde 100644
--- a/lxd/instance_logs.go
+++ b/lxd/instance_logs.go
@@ -53,11 +53,11 @@ func containerLogsGet(d *Daemon, r *http.Request) response.Response {
return response.SmartError(err)
}
- project := projectParam(r)
+ projectName := projectParam(r)
name := mux.Vars(r)["name"]
// Handle requests targeted to a container on a different node
- resp, err := forwardedResponseIfInstanceIsRemote(d, r, project, name, instanceType)
+ resp, err := forwardedResponseIfInstanceIsRemote(d, r, projectName, name, instanceType)
if err != nil {
return response.SmartError(err)
}
@@ -72,7 +72,8 @@ func containerLogsGet(d *Daemon, r *http.Request) response.Response {
result := []string{}
- dents, err := ioutil.ReadDir(shared.LogPath(name))
+ fullName := project.Instance(projectName, name)
+ dents, err := ioutil.ReadDir(shared.LogPath(fullName))
if err != nil {
return response.SmartError(err)
}
More information about the lxc-devel
mailing list