fix(containermanager): conditionally use size attribute on podman

This commit is contained in:
balanza authored and Alessio Biancalana committed 2026-06-14 13:04:28 +02:00
1 parent 64f32d53b0
commit 120c614137
2 files changed
+18 -2

No files matched your search

+17 -1
View File
@@ -376,7 +376,11 @@ func (p *Podman) makeCreateCommand(
// Use keep-id only if going rootless.
if !p.root {
options = append(options, "--userns", "keep-id:size=65536")
if p.supportsKeepIDSize(ctx, containerImage) {
options = append(options, "--userns", "keep-id:size=65536")
} else {
options = append(options, "--userns", "keep-id")
}
}
// Now execute the entrypoint, refer to `distrobox-init -h` for instructions
@@ -627,6 +631,18 @@ func commandExists(cmd string) bool {
return err == nil
}
// supportsKeepIDSize tests whether podman supports the keep-id:size= userns option
// by attempting a quick container run. Older podman versions do not support the size suboption.
func (p *Podman) supportsKeepIDSize(ctx context.Context, image string) bool {
_, err := p.run(ctx, []string{"run", "--rm", "--userns=keep-id:size=65536", image, "/bin/true"}, runOptions{})
if err == nil {
return true
}
// If the error mentions "size" as unknown option, the feature is not supported.
// Other errors (e.g., /bin/true not found exit 127) mean the option itself was accepted.
return !strings.Contains(err.Error(), "unknown option specified: \"size\"")
}
// usesRunc detects whether podman is configured to use runc as the OCI runtime.
// Equivalent to shell: podman info 2>/dev/null | grep -q runc.
func (p *Podman) usesRunc(ctx context.Context) bool {
@@ -57,7 +57,7 @@ func TestPodman_makeCreateCommand(t *testing.T) {
"--annotation run.oci.keep_original_groups=1",
"--ulimit host",
"--systemd=always",
"--userns keep-id:size=65536",
"--userns keep-id",
}
for _, flag := range requiredFlags {