Skip to contentSkip to conversation

tests/docker: Specify --userns keep-id for Podman

PATCH In review Akihiko Odaki 2 participants 2 messages Jun 26, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tests/docker: Specify --userns keep-id for Podman

Previously we are always specifying -u $(UID) to match the UID in the container with one outside. This causes a problem with rootless Podman.

Rootless Podman remaps user IDs in the container to ones controllable for the current user outside. The -u option instructs Podman to use a specified UID in the container but does not affect the UID remapping. Therefore, the UID in the container can be remapped to some other UID outside the container. This can make the access to bind-mounted volumes fail because the remapped UID mismatches with the owner of the directories.

Replace -u $(UID) with --userns keep-id, which fixes the UID remapping. This change is limited to Podman because Docker does not support --userns keep-id.

---
 tests/docker/Makefile.include | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
tests/docker/Makefile.include +6 -1
index 8df50a0ca06f..708e3a72fb8a 100644
@@ -207,7 +207,12 @@ docker-run: docker-qemu-src
 	$(call quiet-command,						\
 		$(RUNC) run 						\
 			--rm						\
-			$(if $(NOUSER),,-u $(UID)) 			\
+			$(if $(NOUSER),,				\
+				$(if $(filter docker,$(RUNC)),		\
+					-u $(UID),			\
+					--userns keep-id		\
+				)					\
+			) 						\
 			--security-opt seccomp=unconfined		\
 			$(if $(DEBUG),-ti,)				\
 			$(if $(NETWORK),$(if $(subst $(NETWORK),,1),--net=$(NETWORK)),--net=none) \

---
base-commit: 74abb45dac6979e7ff76172b7f0a24e869405184
change-id: 20240620-podman-99d55d3a610b

Best regards,

Signature · 1 line
Akihiko Odaki <[email protected]>
#1 lore raw
Quoted 11 lines · Akihiko Odaki

Previously we are always specifying -u $(UID) to match the UID in the container with one outside. This causes a problem with rootless Podman.

Rootless Podman remaps user IDs in the container to ones controllable for the current user outside. The -u option instructs Podman to use a specified UID in the container but does not affect the UID remapping. Therefore, the UID in the container can be remapped to some other UID outside the container. This can make the access to bind-mounted volumes fail because the remapped UID mismatches with the owner of the directories.

Quoted 3 lines

Replace -u $(UID) with --userns keep-id, which fixes the UID remapping. This change is limited to Podman because Docker does not support --userns keep-id.

Queued to testing/next, thanks.

Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro