Skip to content

Commit 24d4bc3

Browse files
committed
Pass supplemental groups when Podman is using crun
This solves the common issue where /dev/vboxusb/* is owned by group "vboxusers", causing volume mounts to fail when running `toolbox enter`. Same is true for any other mapped dirs with supplemental group owners.
1 parent 836c055 commit 24d4bc3

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/cmd/create.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,12 @@ func createContainer(container, image, release, authFile string, showCommandToEn
464464
"--volume", runtimeDirectoryMountArg,
465465
}...)
466466

467+
if runtime, _ := podman.GetRuntimeName(); runtime == "crun" {
468+
createArgs = append(createArgs, []string{
469+
"--group-add", "keep-groups",
470+
}...)
471+
}
472+
467473
createArgs = append(createArgs, avahiSocketMount...)
468474
createArgs = append(createArgs, kcmSocketMount...)
469475
createArgs = append(createArgs, mediaMount...)

src/pkg/podman/podman.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,31 @@ func GetImages(args ...string) ([]Image, error) {
213213
return images, nil
214214
}
215215

216+
// GetRuntimeName returns OCI Runtime of Podman in a string
217+
func GetRuntimeName() (string, error) {
218+
var stdout bytes.Buffer
219+
220+
logLevelString := LogLevel.String()
221+
args := []string{"--log-level", logLevelString, "info", "--format", "json"}
222+
223+
if err := shell.Run("podman", nil, &stdout, nil, args...); err != nil {
224+
return "", err
225+
}
226+
227+
var podmanInfo struct {
228+
Host struct {
229+
OCIRuntime struct {
230+
Name string `json:"name"`
231+
} `json:"ociRuntime"`
232+
} `json:"host"`
233+
}
234+
if err := json.Unmarshal(stdout.Bytes(), &podmanInfo); err != nil {
235+
return "", err
236+
}
237+
238+
return podmanInfo.Host.OCIRuntime.Name, nil
239+
}
240+
216241
// GetVersion returns version of Podman in a string
217242
func GetVersion() (string, error) {
218243
if podmanVersion != "" {

0 commit comments

Comments
 (0)