podman top: join the container userns

When we execute ps(1) in the container and the container uses a userns
with a different id mapping the user id field will be wrong.

To fix this we must join the userns in such case.

Fixes #22293

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2024-06-25 14:41:30 +02:00
parent 5e27243935
commit 65ed96585d
3 changed files with 56 additions and 6 deletions

View File

@@ -119,6 +119,18 @@ var _ = Describe("Podman top", func() {
exec := podmanTest.Podman([]string{"top", session.OutputToString(), "aux"})
exec.WaitWithDefaultTimeout()
Expect(exec).Should(ExitWithError(125, "OCI runtime attempted to invoke a command that was not found"))
session = podmanTest.Podman([]string{"run", "-d", "--uidmap=0:1000:1000", "--user", "9", fedoraMinimal, "sleep", "inf"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())
result = podmanTest.Podman([]string{"top", session.OutputToString(), "-ef", "hn"})
result.WaitWithDefaultTimeout()
Expect(result).Should(ExitCleanly())
output := result.OutputToString()
Expect(output).To(ContainSubstring("sleep inf"))
// check for https://github.com/containers/podman/issues/22293
Expect(output).To(HavePrefix("9 "), "user id of process")
})
It("podman top with comma-separated options", func() {