Skip to content

Commit 7b8fca4

Browse files
committed
fix(vm): run virt-launcher as non-root
Signed-off-by: Isteb4k <[email protected]>
1 parent fc6f5dd commit 7b8fca4

File tree

6 files changed

+108
-248
lines changed

6 files changed

+108
-248
lines changed

images/libvirt/patches/001-disable-ro-and-admin-servers.patch

Lines changed: 0 additions & 220 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
2+
index 9e82132654..fcc7514169 100644
3+
--- a/src/remote/remote_daemon.c
4+
+++ b/src/remote/remote_daemon.c
5+
@@ -628,24 +628,24 @@ static void daemonRunStateInit(void *opaque)
6+
7+
/* Tie the non-privileged daemons to the session/shutdown lifecycle */
8+
if (!virNetDaemonIsPrivileged(dmn)) {
9+
-
10+
- sessionBus = virGDBusGetSessionBus();
11+
- if (sessionBus != NULL)
12+
- g_dbus_connection_add_filter(sessionBus,
13+
- handleSessionMessageFunc, dmn, NULL);
14+
-
15+
- systemBus = virGDBusGetSystemBus();
16+
- if (systemBus != NULL)
17+
- g_dbus_connection_signal_subscribe(systemBus,
18+
- "org.freedesktop.login1",
19+
- "org.freedesktop.login1.Manager",
20+
- "PrepareForShutdown",
21+
- NULL,
22+
- NULL,
23+
- G_DBUS_SIGNAL_FLAGS_NONE,
24+
- handleSystemMessageFunc,
25+
- dmn,
26+
- NULL);
27+
+ if (FALSE) {
28+
+ sessionBus = virGDBusGetSessionBus();
29+
+ if (sessionBus != NULL)
30+
+ g_dbus_connection_add_filter(sessionBus,
31+
+ handleSessionMessageFunc, dmn, NULL);
32+
+ systemBus = virGDBusGetSystemBus();
33+
+ if (systemBus != NULL)
34+
+ g_dbus_connection_signal_subscribe(systemBus,
35+
+ "org.freedesktop.login1",
36+
+ "org.freedesktop.login1.Manager",
37+
+ "PrepareForShutdown",
38+
+ NULL,
39+
+ NULL,
40+
+ G_DBUS_SIGNAL_FLAGS_NONE,
41+
+ handleSystemMessageFunc,
42+
+ dmn,
43+
+ NULL);
44+
+ }
45+
}
46+
47+
/* Only now accept clients from network */

images/libvirt/patches/002-treat-getpeercon-eintval-as-success.patch

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
diff --git a/cmd/virt-launcher-monitor/virt-launcher-monitor.go b/cmd/virt-launcher-monitor/virt-launcher-monitor.go
2+
index f2a0ed86f5..90caff4265 100644
3+
--- a/cmd/virt-launcher-monitor/virt-launcher-monitor.go
4+
+++ b/cmd/virt-launcher-monitor/virt-launcher-monitor.go
5+
@@ -35,8 +35,8 @@ import (
6+
"time"
7+
8+
"github.com/spf13/pflag"
9+
-
10+
"golang.org/x/sys/unix"
11+
+
12+
"kubevirt.io/client-go/log"
13+
14+
"kubevirt.io/kubevirt/pkg/util"
15+
@@ -177,10 +177,13 @@ func RunAndMonitor(containerDiskDir, uid string) (int, error) {
16+
cmd.Stdout = os.Stdout
17+
cmd.Stderr = os.Stderr
18+
19+
+ log.Log.Info("11111")
20+
+
21+
if err := cmd.Start(); err != nil {
22+
- log.Log.Reason(err).Error("failed to run virt-launcher")
23+
+ log.Log.Reason(err).With("cmd", cmd.String()).Error("[AAA] failed to run virt-launcher")
24+
return 1, err
25+
}
26+
+ log.Log.Info("22222")
27+
28+
exitStatus := make(chan int, 10)
29+
sigs := make(chan os.Signal, 10)
30+
diff --git a/pkg/virt-launcher/virtwrap/util/libvirt_helper.go b/pkg/virt-launcher/virtwrap/util/libvirt_helper.go
31+
index 99ce4370f6..72c69f91d1 100644
32+
--- a/pkg/virt-launcher/virtwrap/util/libvirt_helper.go
33+
+++ b/pkg/virt-launcher/virtwrap/util/libvirt_helper.go
34+
@@ -222,7 +222,7 @@ func (l LibvirtWrapper) StartVirtquemud(stopChan chan struct{}) {
35+
cmd := exec.Command("/usr/sbin/virtqemud", args...)
36+
if l.user != 0 {
37+
cmd.SysProcAttr = &syscall.SysProcAttr{
38+
- AmbientCaps: []uintptr{unix.CAP_NET_BIND_SERVICE},
39+
+ AmbientCaps: []uintptr{unix.CAP_NET_BIND_SERVICE, unix.CAP_DAC_OVERRIDE},
40+
}
41+
}
42+

images/virt-launcher/werf.inc.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import:
99
after: install
1010
imageSpec:
1111
config:
12-
user: 0
12+
user: 107
1313

1414
---
1515
{{- define "virt-launcher-dependencies" -}}
@@ -139,6 +139,12 @@ binaries:
139139
- /usr/bin/sh
140140
- /usr/bin/bash
141141
- /usr/bin/uname
142+
- /usr/bin/ls
143+
- /usr/bin/id
144+
- /usr/bin/cat
145+
- /usr/bin/namei
146+
- /usr/bin/whoami
147+
- /usr/bin/strace
142148
- /usr/bin/nohup
143149
- /usr/bin/sleep
144150
- /usr/bin/cp
@@ -408,4 +414,4 @@ shell:
408414
mkdir -p /binaries
409415
echo 'go build -ldflags="-s -w" -o /binaries/node-labeller ./cmd/node-labeller'
410416
go build -ldflags="-s -w" -o /binaries/node-labeller ./cmd/node-labeller
411-
echo "Done"
417+
echo "Done"

0 commit comments

Comments
 (0)