Merge pull request #6175 from leseb/do-not-exec-lvm

ceph: do not exec on rootfs just lookup
This commit is contained in:
Sébastien Han authored and GitHub committed 2020-08-27 16:26:02 +02:00
commit 296997e723
2 files changed
+5 -22

No files matched your search

+5 -3
View File
@@ -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
-19
View File
@@ -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)
}