From 3a9a67499f410bfc7f6af78a783232f7a0045d7e Mon Sep 17 00:00:00 2001 From: Feng Wang Date: Mon, 9 Aug 2021 13:44:33 -0700 Subject: [PATCH] qemu: Add credentials to qemu Cmd add credentials to the command attribute Fixes #2444 Signed-off-by: Feng Wang --- qemu/qemu.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/qemu/qemu.go b/qemu/qemu.go index c4aada81e5..1152ffd72a 100644 --- a/qemu/qemu.go +++ b/qemu/qemu.go @@ -2439,6 +2439,13 @@ type Config struct { // Ctx is the context used when launching qemu. Ctx context.Context + // User ID. + Uid uint32 + // Group ID. + Gid uint32 + // Supplementary group IDs. + Groups []uint32 + // Name is the qemu guest name Name string @@ -2898,8 +2905,15 @@ func LaunchQemu(config Config, logger QMPLog) (string, error) { ctx = context.Background() } + attr := syscall.SysProcAttr{} + attr.Credential = &syscall.Credential{ + Uid: config.Uid, + Gid: config.Gid, + Groups: config.Groups, + } + return LaunchCustomQemu(ctx, config.Path, config.qemuParams, - config.fds, nil, logger) + config.fds, &attr, logger) } // LaunchCustomQemu can be used to launch a new qemu instance.