KubeOS: fix the hostshell cannot obtain the lib

Fix the hostshell cannot obtain the lib

Signed-off-by: liyuanr <liyuanrong1@huawei.com>
This commit is contained in:
liyuanr 2023-08-07 19:17:58 +08:00 committed by Yuhang Wei
parent 803aac8a0d
commit fbb9b2debd
2 changed files with 83 additions and 1 deletions

View File

@ -0,0 +1,75 @@
From 470e190db2de92b65e7fa720864823e7245c51e9 Mon Sep 17 00:00:00 2001
From: liyuanr <liyuanrong1@huawei.com>
Date: Mon, 7 Aug 2023 19:09:18 +0800
Subject: [PATCH] KubeOS: fix the hostshell cannot obtain the lib
Fix the hostshell cannot obtain the lib
Signed-off-by: liyuanr <liyuanrong1@huawei.com>
---
cmd/admin-container/main.go | 40 +++++++++++++++++++++++++------------
1 file changed, 27 insertions(+), 13 deletions(-)
diff --git a/cmd/admin-container/main.go b/cmd/admin-container/main.go
index f6a7293..5fa0838 100644
--- a/cmd/admin-container/main.go
+++ b/cmd/admin-container/main.go
@@ -22,28 +22,42 @@ import (
"github.com/sirupsen/logrus"
)
+const (
+ bashPath = "/usr/bin/bash"
+ usrBin = "/usr/bin"
+ usrSbin = "/usr/sbin"
+ localBin = "/usr/local/bin"
+ localSbin = "/usr/local/sbin"
+ usrLib = "/usr/lib"
+ usrLib64 = "/usr/lib64"
+ lib = "/lib"
+ lib64 = "/lib64"
+ envPathPrefix = "PATH=$PATH:"
+ envLdLibrarPathPrefix = "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:"
+)
+
func main() {
EUID := os.Geteuid()
rootEUID := 0 // 0 indicates that the process has the permission of the root user.
if EUID != rootEUID {
logrus.Error("please use root to run hostshell")
- return
+
}
PPID := os.Getppid()
rootFsPath := "/proc/" + strconv.Itoa(PPID) + "/root"
- bashPath := "/usr/bin/bash"
- usrBin := "/usr/bin"
- usrSbin := "/usr/sbin"
- localBin := "/usr/local/bin"
- localSbin := "/usr/local/sbin"
- paths := []string{usrBin, usrSbin, localBin, localSbin}
- for i, p := range paths {
- paths[i] = rootFsPath + p
- }
- path := "PATH=$PATH:" + strings.Join(paths, ":")
- lib := "LD_LIBRARY_PATH=/lib:/lib64:/usr/lib:/usr/lib64:$LD_LIBRARY_PATH"
+ path := concatenateEnvPath(rootFsPath, envPathPrefix, []string{usrBin, usrSbin, localBin, localSbin})
+ libPath := concatenateEnvPath(rootFsPath, envLdLibrarPathPrefix, []string{usrLib, usrLib64, lib, lib64})
if err := syscall.Exec("/usr/bin/nsenter", []string{"nsenter", "-t", "1", "-a",
- "env", "-i", path, lib, rootFsPath + bashPath}, os.Environ()); err != nil {
+ "env", "-i", path, libPath, rootFsPath + bashPath}, os.Environ()); err != nil {
logrus.Error("nsenter excute error", err)
}
}
+
+func concatenateEnvPath(prefix string, envVarPrefix string, paths []string) string {
+ for i, p := range paths {
+ paths[i] = prefix + p
+ }
+ pathLine := envVarPrefix + strings.Join(paths, ":")
+ pathEnv := os.ExpandEnv(pathLine)
+ return pathEnv
+}
--
2.33.0.windows.2

View File

@ -2,10 +2,11 @@
Name: KubeOS Name: KubeOS
Version: 1.0.4 Version: 1.0.4
Release: 1 Release: 2
Summary: O&M platform used to update the whole OS as an entirety Summary: O&M platform used to update the whole OS as an entirety
License: Mulan PSL v2 License: Mulan PSL v2
Source0: https://gitee.com/openeuler/KubeOS/repository/archive/v%{version}.tar.gz Source0: https://gitee.com/openeuler/KubeOS/repository/archive/v%{version}.tar.gz
Patch1: 0001-KubeOS-fix-the-hostshell-cannot-obtain-the-lib.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRoot: %{_tmppath}/%{name}-%{version}-build
BuildRequires: make BuildRequires: make
@ -82,6 +83,12 @@ install -p -m 0600 ./scripts/admin-container/set-ssh-pub-key.service %{buildroot
rm -rfv %{buildroot} rm -rfv %{buildroot}
%changelog %changelog
* Mon Aug 07 2023 liyuanrong<liyuanrong1@huawei.com> - 1.0.4-2
- Type:requirement
- CVE:NA
- SUG:restart
- DESC:fix the hostshell cannot obtain the lib
* Wed Aug 02 2023 liyuanrong<liyuanrong1@huawei.com> - 1.0.4-1 * Wed Aug 02 2023 liyuanrong<liyuanrong1@huawei.com> - 1.0.4-1
- Type:requirement - Type:requirement
- CVE:NA - CVE:NA