Skip to content

Commit d34ccf6

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

File tree

8 files changed

+108
-253
lines changed

8 files changed

+108
-253
lines changed

images/libvirt/install-libvirt.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ usage() {
1818
cat <<EOF
1919
Usage: $0 [OPTIONS]
2020
Options:
21-
21+
2222
Set the source base directory: -s, --src-base PATH (example: /mysourcedir)
2323
Set the build base directory: -b, --build-dir FOLDER (example: mybuildfolder)
2424
Set the destination base directory: -d, --dest-base PATH (example: /mydestdir)
@@ -103,9 +103,9 @@ fi
103103
lib_version=$(convert_version $VERSION_NUM)
104104

105105
# List of files and destinations of libvirt
106-
# Commented lines - binary for additional features.
106+
# Commented lines - binary for additional features.
107107
#
108-
# The specific format of the list, 'SOURCE_FILE to DESTINATION',
108+
# The specific format of the list, 'SOURCE_FILE to DESTINATION',
109109
# is due to the output of the installation scripts. To make it easier to add them to this list.
110110

111111
FILE_LIST=$(cat <<EOF
@@ -568,6 +568,11 @@ copy_file() {
568568
fi
569569
cp -p "$SOURCE_PATH" "$DEST_BASE$dest_dir"
570570
echo "Copied $SOURCE_PATH to $DEST_BASE$dest_dir"
571+
572+
if [[ "$SOURCE_PATH" == *virtqemud ]]; then
573+
setcap cap_net_bind_service=eip "$DEST_BASE$dest_dir/virtqemud"
574+
echo "SETCAP $SOURCE_PATH to $DEST_BASE$dest_dir"
575+
fi
571576
}
572577

573578
main() {
@@ -589,4 +594,4 @@ main() {
589594
done <<< "$FILE_LIST"
590595
}
591596

592-
main
597+
main

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: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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)

images/virt-artifact/werf.inc.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ shell:
9696

9797
- echo ============== Build virt-launcher-monitor ============
9898
# virt-launcher-monitor is wrapped in the final image. Add suffix here to prevent image size increasing as effect of file renaming.
99-
- go build -ldflags="-s -w" -o /kubevirt-binaries/virt-launcher-monitor ./cmd/virt-launcher-monitor/
99+
- CGO_ENABLED=0 go build -ldflags="-s -w" -o /kubevirt-binaries/virt-launcher-monitor ./cmd/virt-launcher-monitor/
100+
- setcap cap_net_bind_service=eip /kubevirt-binaries/virt-launcher-monitor
100101

101102
- echo ============== Build virt-tail ========================
102103
- go build -ldflags="-s -w" -o /kubevirt-binaries/virt-tail ./cmd/virt-tail/

0 commit comments

Comments
 (0)