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:
parent
803aac8a0d
commit
fbb9b2debd
75
0001-KubeOS-fix-the-hostshell-cannot-obtain-the-lib.patch
Normal file
75
0001-KubeOS-fix-the-hostshell-cannot-obtain-the-lib.patch
Normal 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
|
||||
|
||||
@ -2,10 +2,11 @@
|
||||
|
||||
Name: KubeOS
|
||||
Version: 1.0.4
|
||||
Release: 1
|
||||
Release: 2
|
||||
Summary: O&M platform used to update the whole OS as an entirety
|
||||
License: Mulan PSL v2
|
||||
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
|
||||
BuildRequires: make
|
||||
@ -82,6 +83,12 @@ install -p -m 0600 ./scripts/admin-container/set-ssh-pub-key.service %{buildroot
|
||||
rm -rfv %{buildroot}
|
||||
|
||||
%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
|
||||
- Type:requirement
|
||||
- CVE:NA
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user