when running with uid 0 (like in nested container), podman run fails
sporadically with:
``
Error: preparing container ... for attach: container uses ID mappings ([]specs
.LinuxIDMapping{specs.LinuxIDMapping{ContainerID:0x3e9, HostID:0x0, 
Size:0x1}}), but doesn't map UID 0
```

Since default user in containers is 0 (run without -u option), there is
no need to repeat that in this case.

Tested-by: John Snow <[email protected]>
Reviewed-by: Pierrick Bouvier <[email protected]>
Link: 
https://lore.kernel.org/qemu-devel/[email protected]
Signed-off-by: Pierrick Bouvier <[email protected]>
---
 tests/docker/docker.py | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/tests/docker/docker.py b/tests/docker/docker.py
index d97dda26967..7c15da59db6 100755
--- a/tests/docker/docker.py
+++ b/tests/docker/docker.py
@@ -334,10 +334,11 @@ def run(self, cmd, keep, quiet, as_user=False):
 
         if as_user:
             uid = os.getuid()
-            cmd = [ "-u", str(uid) ] + cmd
-            # podman requires a bit more fiddling
-            if self._command[0] == "podman":
-                cmd.insert(0, '--userns=keep-id')
+            if uid != 0:
+                cmd = [ "-u", str(uid) ] + cmd
+                # podman requires a bit more fiddling
+                if self._command[0] == "podman":
+                    cmd.insert(0, '--userns=keep-id')
 
         ret = self._do_check(["run", "--rm", "--label",
                              "com.qemu.instance.uuid=" + label] + cmd,
-- 
2.47.3


Reply via email to