OpenShift user namespaces give Testcontainers a narrower path through Pipelines
Red Hat’s reference workflow replaces privileged Docker-in-Docker with a rootless Podman sidecar, a dedicated service account and task-scoped user namespaces.
Running integration tests inside a CI task becomes awkward when the tests need to start their own database or message broker. A new Red Hat Developer walkthrough shows a narrower OpenShift path: run Testcontainers against a rootless Podman sidecar inside an OpenShift Pipelines task, while using a user namespace to keep the nested processes mapped away from host identities.
The pattern matters because it does not treat unrestricted Docker-in-Docker as the default answer. Instead, it confines the extra capability to one Tekton task and one service account.
What the pattern changes
The walkthrough builds on user namespaces introduced in OpenShift 4.20 and generally available and enabled by default in OpenShift 4.21. Its example runs a Quarkus Petclinic Maven build whose tests start PostgreSQL through Testcontainers. The supplied run completed five tests without failures.
A custom Maven task places two containers in the TaskRun pod: the build step and a rootless Podman sidecar. Testcontainers reaches Podman through a shared Unix socket identified by DOCKER_HOST. The example uses Red Hat’s UBI OpenJDK 21 and RHEL 9 Podman images rather than introducing a custom CI image.
The sidecar receives /dev/fuse and /dev/net/tun through a CRI-O annotation. Those devices let Podman use fuse-overlayfs and give nested containers private networking. The build step itself does not receive the sidecar’s added SETUID and SETGID capabilities.
The security boundary is explicit
The PipelineRun sets hostUsers: false, which requests a pod-level user namespace. A dedicated pipeline-user-namespace service account is bound to OpenShift’s nested-container Security Context Constraint. Other tasks remain on the default pipeline service account, so the additional permissions do not automatically spread across the whole pipeline.
That is still an administrative decision, not a namespace-only trick. Red Hat notes that creating the RoleBinding requires permission to bind a cluster role; a namespace administrator may need a cluster administrator to do it. The configuration also disables Testcontainers’ Ryuk resource reaper because the nested rootless setup cannot mount the Podman socket into another container.
What teams should check first
The example requires OpenShift 4.21 or later and OpenShift Pipelines. Platform teams should review the dedicated service account, SCC binding and device annotation before adapting the task, rather than copying the manifests into a shared pipeline account.
There is also a version-specific warning: Red Hat says a crun 1.27 regression can leak storage volumes when user namespaces are used on OpenShift 4.22 and OpenShift 5.0 with RHCOS 9.8. The post points operators to Red Hat issue RHEL-238820 and says the problem is fixed in RHCOS 10.
The useful result is not simply that nested containers run. It is that the example makes each exception visible: user namespaces at the pod level, elevated capabilities only on the Podman sidecar, and an SCC binding limited to a dedicated task identity. That gives pipeline owners concrete boundaries to review when adding infrastructure-backed tests to OpenShift CI.
sources
- OpenShift Pipelines and Test Containersdevelopers.redhat.com
comments · 0