From f2313d6db0d9decac91a7ff79032f8e2a5e75884 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Han?= Date: Thu, 27 Aug 2020 15:12:00 +0200 Subject: [PATCH] ceph: do not exec on rootfs just lookup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Trying to execute a binary from the host within the container can result in mismatched libraries. The host version is compiled with paths of libraries on the host where the libs inside the container can differ. Because the path is known and we only need to make sure whether the bin exists or not then simply doing a lookup when we fallback on /rootfs is sufficient. Closes: https://github.com/rook/rook/issues/6078 Signed-off-by: Sébastien Han --- pkg/daemon/ceph/osd/nsenter.go | 8 +++++--- pkg/daemon/ceph/osd/nsenter_test.go | 19 ------------------- 2 files changed, 5 insertions(+), 22 deletions(-) diff --git a/pkg/daemon/ceph/osd/nsenter.go b/pkg/daemon/ceph/osd/nsenter.go index 7d10e51e0..e44eb867f 100644 --- a/pkg/daemon/ceph/osd/nsenter.go +++ b/pkg/daemon/ceph/osd/nsenter.go @@ -18,6 +18,7 @@ package osd import ( "fmt" + "os" "path/filepath" "github.com/pkg/errors" @@ -77,11 +78,12 @@ func (ne *NSEnter) checkIfBinaryExistsOnHost() error { err := ne.callNsEnter(binPath) if err != nil { logger.Debugf("failed to call nsenter. %v", err) - // If nsenter failed, let's try with the rootfs directly + // If nsenter failed, let's try with the rootfs directly but only lookup the binary and do not execute it + // This avoids mismatch libraries between the container and the host while executing rootFSBinPath := filepath.Join(rootFSPath, binPath) - output, err := ne.context.Executor.ExecuteCommandWithCombinedOutput(rootFSBinPath, ne.binaryArgs...) + _, err := os.Stat(rootFSBinPath) if err != nil { - logger.Debugf("failed to execute command on the host rootfs. %s. %v", output, err) + logger.Debugf("failed to lookup binary path %q on the host rootfs. %v", rootFSBinPath, err) continue } binPath = rootFSBinPath diff --git a/pkg/daemon/ceph/osd/nsenter_test.go b/pkg/daemon/ceph/osd/nsenter_test.go index 6bffaea8e..f6c70cf55 100644 --- a/pkg/daemon/ceph/osd/nsenter_test.go +++ b/pkg/daemon/ceph/osd/nsenter_test.go @@ -51,23 +51,4 @@ func TestCheckIfBinaryExistsOnHost(t *testing.T) { ne := NewNsenter(context, lvmCommandToCheck, []string{"help"}) err := ne.checkIfBinaryExistsOnHost() assert.NoError(t, err) - - executor.MockExecuteCommandWithCombinedOutput = func(command string, args ...string) (string, error) { - logger.Infof("%s %v", command, args) - switch command { - - case "/rootfs/usr/sbin/lvm": - return "success", nil - - case "/rootfs/sbin/lvm": - return "success", nil - - } - return "", errors.Errorf("unknown command %s %s", command, args) - } - - context = &clusterd.Context{Executor: executor} - ne = NewNsenter(context, lvmCommandToCheck, []string{"help"}) - err = ne.checkIfBinaryExistsOnHost() - assert.NoError(t, err) }