spiegel_podman/pkg
Paul Holzinger 597ebeb60f
top: do not depend on ps(1) in container
This ended up more complicated then expected. Lets start first with the
problem to show why I am doing this:

Currently we simply execute ps(1) in the container. This has some
drawbacks. First, obviously you need to have ps(1) in the container
image. That is no always the case especially in small images. Second,
even if you do it will often be only busybox's ps which supports far
less options.

Now we also have psgo which is used by default but that only supports a
small subset of ps(1) options. Implementing all options there is way to
much work.

Docker on the other hand executes ps(1) directly on the host and tries
to filter pids with `-q` an option which is not supported by busybox's
ps and conflicts with other ps(1) arguments. That means they fall back
to full ps(1) on the host and then filter based on the pid in the
output. This is kinda ugly and fails short because users can modify the
ps output and it may not even include the pid in the output which causes
an error.

So every solution has a different drawback, but what if we can combine
them somehow?! This commit tries exactly that.

We use ps(1) from the host and execute that in the container's pid
namespace.
There are some security concerns that must be addressed:
- mount the executable paths for ps and podman itself readonly to
  prevent the container from overwriting it via /proc/self/exe.
- set NO_NEW_PRIVS, SET_DUMPABLE and PDEATHSIG
- close all non std fds to prevent leaking files in that the caller had
  open
- unset all environment variables to not leak any into the contianer

Technically this could be a breaking change if somebody does not
have ps on the host and only in the container but I find that very
unlikely, we still have the exec in container fallback.

Because this can be insecure when the contianer has CAP_SYS_PTRACE we
still only use the podman exec version in that case.

This updates the docs accordingly, note that podman pod top never falls
back to executing ps in the container as this makes no sense with
multiple containers so I fixed the docs there as well.

Fixes #19001
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=2215572

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-07-10 13:32:55 +02:00
..
annotations Remove ReservedAnnotations from kube generate specification 2023-01-18 08:46:24 -05:00
api top: do not depend on ps(1) in container 2023-07-10 13:32:55 +02:00
auth fix(deps): update module github.com/docker/docker to v24 2023-05-22 15:32:12 +02:00
autoupdate auto update: fix usage of --authfile 2023-07-05 08:30:39 +02:00
bindings top: do not depend on ps(1) in container 2023-07-10 13:32:55 +02:00
channel bump golangci-lint to v1.50.1 2022-12-15 13:39:56 +01:00
checkpoint criu: return error when checking for min version 2023-06-12 15:29:21 +02:00
copy pkg: switch to golang native error wrapping 2022-07-08 08:54:47 +02:00
criu criu: return error when checking for min version 2023-06-12 15:29:21 +02:00
ctime Replace deprecated ioutil 2022-09-20 15:34:27 -04:00
domain auto update: fix usage of --authfile 2023-07-05 08:30:39 +02:00
env vendor: bump containers/(storage, common, buildah, image) 2023-04-10 17:30:14 +05:30
errorhandling Fix typos 2023-02-11 18:23:24 +01:00
inspect pkg/inspect: remove unused ImageResult type 2022-05-24 16:07:39 +02:00
k8s.io *: migrate image registry to registry.k8s.io 2023-04-11 10:30:43 -04:00
lookup source code comments and docs: fix typos, language, Markdown layout 2023-05-22 07:52:16 +02:00
machine Use bytes size consistently instead of human size 2023-07-06 14:51:06 +02:00
namespaces source code comments and docs: fix typos, language, Markdown layout 2023-05-22 07:52:16 +02:00
parallel Fix stutters 2022-09-10 07:52:00 -04:00
ps Add {{.Restarts}} to podman ps 2023-05-02 10:30:07 -04:00
rctl pkg/rctl: Remove unused cgo dependency 2022-10-31 15:13:48 +00:00
rootless make lint: enable mirror 2023-06-19 14:11:12 +02:00
seccomp pkg: switch to golang native error wrapping 2022-07-08 08:54:47 +02:00
selinux Fix SELinux functions names to not be repetitive 2020-04-23 15:57:34 -04:00
signal Run codespell on code 2022-11-04 10:57:41 -04:00
specgen pkg/specgen: properly identify image OS on FreeBSD 2023-07-04 13:53:42 +01:00
specgenutil Fix readonly=false failure 2023-06-27 16:57:21 -04:00
systemd Kube quadlets can support autoupdate as well as containers 2023-06-27 11:20:14 -04:00
terminal podman ssh work, using new c/common interface 2022-08-09 14:00:58 -04:00
timetype bump golangci-lint to v1.49.0 2022-10-17 09:19:41 +02:00
trust chore: replace github.com/ghodss/yaml with sigs.k8s.io/yaml 2023-04-06 21:11:17 +08:00
util Use /proc/self/gid_map as intended, not uid_map 2023-06-30 12:57:55 +02:00