Commit Graph

4270 Commits

Author SHA1 Message Date
openshift-merge-bot[bot] 70c255955a
Merge pull request #21062 from gavinkflam/base-hosts-file-flag
Add --hosts-file flag; Add nohosts to remote build APIs
2024-11-25 14:40:18 +00:00
ksw2000 e4e7bc41f3 refact: EventerType and improve consistency
1. Completed the EventerType comment.
2. Changed EventerType to be represented as a string.
3. Since EventerType is designed to be entirely lowercase, changed the comparison to use lowercase instead of uppercase.
4. Renamed newEventJournalD to newJournalDEventer.
5. Removed redundant error-checking steps in events_linux.go.

Signed-off-by: ksw2000 <13825170+ksw2000@users.noreply.github.com>
2024-11-25 08:52:53 +00:00
Gavin Lam 4f7395f93a
Add --hosts-file flag to container and pod commands
* Add --hosts-file flag to container create, container run and pod create
* Add HostsFile field to pod inspect and container inspect results
* Test BaseHostsFile config in containers.conf

Signed-off-by: Gavin Lam <gavin.oss@tutamail.com>
2024-11-24 22:00:34 -05:00
openshift-merge-bot[bot] d85ac938e6
Merge pull request #24442 from Honny1/change-healthcheck-config-via-podman-update
Configure HealthCheck with `podman update`
2024-11-22 15:57:30 +00:00
Jan Rodák a1249425bd
Configure HealthCheck with `podman update`
New flags in a `podman update` can change the configuration of HealthCheck when the container is started, without having to restart or recreate the container.

This can help determine why a given container suddenly started failing HealthCheck without interfering with the services it provides. For example, reconfigure HealthCheck to keep logs longer than the usual last X results, store logs to other destinations, etc.

Fixes: https://issues.redhat.com/browse/RHEL-60561

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-11-19 19:44:14 +01:00
openshift-merge-bot[bot] 1712594493
Merge pull request #24592 from giuseppe/honor-pivot-root-build
libpod: pass down NoPivotRoot to Buildah
2024-11-18 15:02:55 +00:00
Giuseppe Scrivano e60e11167e
libpod: pass down NoPivotRoot to Buildah
Closes: https://github.com/containers/podman/issues/24546

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-11-18 12:41:47 +01:00
Paul Holzinger d513973237
libpod: addHosts() prevent nil deref
In theory RootlessNetnsInfo() should never return nil here. However that
was actually only true when the rootless netns was set up before and
wrote the right cache file with the ip addresses.

Given this cache file is a new feature just added in 5.3 if you updated
from 5.2 or earlier the file will not exists thus cause failures for all
following started containers.
The fix for this is to stop all containers and make sure the
rootless-netns was removed so the next start creates it new with the
proper 5.3 cache file. However as there is no way to rely on users doing
that and it is also not requirement so simply handle the nil deref here.

The only way to test this would be to run the old version then the new
version which we cannot really do in CI. We do have upgrade test for
that but they are root only and likely need a lot more work to get them
going rootless but certainly worth to explore to prevent such problems
in the future.

Fixes: a1e6603133 ("libpod: make use of new pasta option from c/common")
Fixes: #24566

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-15 13:39:45 +01:00
openshift-merge-bot[bot] 8f2d5011f2
Merge pull request #24532 from mheon/subpath
Add subpath support to volumes in `--mount` option
2024-11-12 21:46:58 +00:00
Giuseppe Scrivano 0a69aefa41
spec: clamp rlimits in a userns
commit 5ebba75dbd implemented this
behaviour for rootless users, but the same limitation exists for any
user in a user namespace.  Change the check to use the clamp to the
current values anytime podman runs in a user namespace.

Closes: https://github.com/containers/podman/issues/24508

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-11-12 16:44:33 +01:00
Matt Heon 8a192c8403 Add subpath support to volumes in `--mount` option
All the backend work was done a while back for image volumes, so
this is effectively just plumbing the option in for volumes in
the parser logic. We do need to change the return type of the
volume parser as it only worked on spec.Mount before (which does
not have subpath support, so we'd have to pass it as an option
and parse it again) but that is cleaner than the alternative.

Fixes #20661

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-11-12 09:13:16 -05:00
Kashiwa da6404ba16 refactor: simplify LinuxNS type definition and String method
Signed-off-by: Kashiwa <13825170+ksw2000@users.noreply.github.com>
2024-11-12 11:46:47 +00:00
openshift-merge-bot[bot] aac206e9c5
Merge pull request #24412 from Sativarsainath-26/network-events
Fix: To print create and remove network in podman events
2024-11-06 18:33:18 +00:00
Daniel J Walsh 6346a11b09
AdditionalSupport for SubPath volume mounts
Add support for inspecting Mounts which include SubPaths.

Handle SubPaths for kubernetes image volumes.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-11-06 10:10:26 -05:00
Sainath Sativar c23d9c6f23 Log network creation and removal events in Podman
This commit resolves an issue where network creation and removal events were not being logged in `podman events`. A new function has been introduced in the `events` package to ensure consistent logging of network lifecycle events. This update will allow users to track network operations more effectively through the event log, improving visibility and aiding in debugging network-related issues.

Fixes: #24032
Signed-off-by: Sainath Sativar <Sativar.sainath@gmail.com>
2024-11-05 11:58:47 +00:00
Paul Holzinger b237b4dc2a
libpod: journald do not lock thread
This is not needed and was added by during debugging but it turned out
to be something else. We should not lock the thread unless needed
because this just raises question why it is here otherwise.
Also the lock would not do much as we spawn a goroutine below anyway so
it runs on another thread no matter what.

From the review comment by Miloslav but it was merged before I had the
chance to fix it:
https://github.com/containers/podman/pull/24406#discussion_r1828102666

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-05 11:32:51 +01:00
Paul Holzinger 768ad8653a
rework event code to improve API errors
One of the problems with the Events() API was that you had to call it in
a new goroutine. This meant the the error returned by it had to be read
back via a second channel. This cuased other bugs in the past but here
the biggest problem is that basic errors such as invalid since/until
options were not directly returned to the caller.
It meant in the API we were not able to write http code 200 quickly
because we always waited for the first event or error from the
channels. This in turn made some clients not happy as they assume the
server hangs on time out if no such events are generated.

To fix this we resturcture the entire event flow. First we spawn the
goroutine inside the eventer Read() function so not all the callers have
to. Then we can return the basic error quickly without the goroutine.
The caller then checks the error like any normal function and the API
can use this one to decide which status code to return.
Second we now return errors/event in one channel then the callers can
decide to ignore or log them which makes it a bit more clear.

Fixes c46884aa93 ("podman events: check for an error after we finish reading events")
Fixes #23712

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-01 18:54:13 +01:00
Paul Holzinger e3abf5c9e8
events: remove memory eventer
This type is unsused, undocumented and basically broken. If this would
be used anywhere it will just deadlock after writing 100+ events without
reading as the channel will just be full.

It was added in commit 8da5f3f733 but never used there nor is there any
justification why this was added in the commit message or PR comments.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-01 18:53:09 +01:00
Paul Holzinger 6348778348
libpod: log file use Wait() over event API
Using the internal Wait() API over the events API as this is much more
efficient. Reading events will need to read a lot of data otherwise.

For the function here it should work fine and it is even better as it
does not depend on the event logger at all.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-11-01 18:53:08 +01:00
openshift-merge-bot[bot] 496e7ca024
Merge pull request #24381 from t4chib4ne/kube-play-wait-interval
stop podman kube play --wait from using 100% CPU
2024-11-01 12:51:09 +00:00
Maximilian Hueter 314dece926 add default polling interval to Container.Wait
Signed-off-by: Maximilian Hueter <maximilian.hueter@icloud.com>
2024-10-30 20:00:52 +01:00
Paul Holzinger c98538db7d
libpod: use pasta Setup() over Setup2()
Setup2() calls Setup() so they are both the same thing, the idea was to
keep Setup2() around in c/common for a bit to avoid breaking changes
during our regular vendoring. Now just use Setup() so we can get rid of
Setup2() in c/common.

a7415c3eab

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-10-30 13:35:56 +01:00
Giuseppe Scrivano 1f44d0f8b2
libpod: report cgroups deleted during Stat() call
The cgroup.Stat() operation is not atomic, so it's possible that the
cgroup is removed during the Stat() call.  Catch specific errors that
can occur when the cgroup is missing and validate the existence of the
cgroup path.
If the cgroup is not found, return a more specific error indicating
that the container has been removed.

Closes: https://github.com/containers/podman/issues/23789

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-10-29 11:16:57 +01:00
Paul Holzinger c0f4e2ce67
healthcheck: do not leak service on failed stop
We reset the failed unit to not leak it, however we did so before
stopping, this is wrong because when the stop fails we will again have a
failed unit. The correct thing is to reset after the stop because once
it is stopped it cannot create new errors.

I found this using the following reproducer and this is enough to fix
it:
```
while :; do
cid=$(podman run -d --name foo --health-cmd /home/podman/healthcheck \
	--health-startup-cmd /home/podman/healthcheck \
	quay.io/libpod/testimage:20241011 /home/podman/pause)
podman healthcheck run $cid
podman rm -fa
sleep 2
systemctl --user list-units --failed | grep $cid && break
done
```

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-10-25 15:27:05 +02:00
Paul Holzinger 6069cdda00
healthcheck: do not leak statup service
The startup service is special because we have to transition from
startup to the normal unit. And in order to do so we kill ourselves (as
we are run as part of the service). This means we always exited 1 which
causes systemd to keep us failure and not remove the transient unit
unless "reset-failed" is called. As there is no process around to do
that we cannot really do this, thus make us exit(0) which makes more
sense.

Of course we could try to reset-failed the unit later but the code for
that seems more complicated than that.

Add a new test from Ed that ensures we check for all healthcheck units
not just the timer to avoid leaks. I slightly modified it to provide a
better error on leaks.

Fixes: 0bbef4b830 ("libpod: rework shutdown handler flow")
Fixes: #24351

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-10-25 13:47:59 +02:00
Jan Rodák afedb83917
Add Startup HealthCheck configuration to the podman inspect
Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-10-24 13:49:51 +02:00
Matt Heon 23ab7b858a Set quota on volume root directory, not _data
This will appease the higher-level quota logic. Basically, to
find a free quota ID to prevent reuse, we will iterate through
the contents of the directory and check the quota IDs of all
subdirectories, then use the first free ID found that is larger
than the base ID (the one set on the base directory). Problem:
our volumes use a two-tier directory structure, where the volume
has an outer directory (with the name of the actual volume) and
an inner directory (always named _data). We were only setting the
quota on _data, meaning the outer directory did not have an ID,
and the ID-choosing logic thus never detected that any IDs had
been allocated and always chose the same ID.

Setting the ID on the outer directory with PROJINHERIT set makes
the ID allocation logic work properly, and guarantees children
inherit the ID - so _data and all contents of the volume get the
ID as we'd expect.

No tests as we don't have a filesystem in our CI that supports
XFS quotas (setting it on / needs kernel flags added).

Fixes https://issues.redhat.com/browse/RHEL-18038

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-10-22 08:49:56 -04:00
Giuseppe Scrivano 5ebba75dbd
spec: always specify default rlimits
the previous implementation was expecting the rlimits to be set for the
entire process and clamping the values only when running as rootless.

Change the implementation to always specify the expected values in the
OCI spec file and do the clamping only when running as rootless and
using the default values.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-10-11 23:04:27 +02:00
Paul Holzinger b3829a2932
libpod API: make wait endpoint better against rm races
In the common scenario of podman-remote run --rm the API is required to
attach + start + wait to get exit code. This has the problem that the
wait call races against the container removal from the cleanup process
so it may not get the exit code back. However we keep the exit code
around for longer than the container so  we can just look it up in the
endpoint. Of course this only works when we get a full id as param but
podman-remote will do that.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-10-08 18:03:15 +02:00
openshift-merge-bot[bot] d28af234de
Merge pull request #24164 from mheon/host_network_no_expose_in_ports
Exposed ports are only included when not --net=host
2024-10-04 17:03:40 +00:00
openshift-merge-bot[bot] 1f7fe1d1e8
Merge pull request #24167 from giuseppe/improve-check-for-current-user-mapped
libpod: hasCurrentUserMapped checks for gid too
2024-10-04 16:55:13 +00:00
Matt Heon 8061553c0f Exposed ports are only included when not --net=host
Undoing some of my own work here from #24090 now that we have the
ExposedPorts field implemented in inspect. I considered a revert
of that patch, but it's still needed as without it we'd be
including exposed ports when --net=container which is not
correct.

Basically, exposed ports for a container should always go in the
new ExposedPorts field we added. They sometimes go in the Ports
field in NetworkSettings, but only when the container is not
net=host and not net=container. We were always including exposed
ports, which was not correct, but is an easy logical fix.

Also required is a test change to correct the expected behavior
as we were testing for incorrect behavior.

Fixes https://issues.redhat.com/browse/RHEL-60382

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-10-04 11:19:43 -04:00
Giuseppe Scrivano e46ae46f18
libpod: hasCurrentUserMapped checks for gid too
the kernel checks that both the uid and the gid are mapped inside the
user namespace, not only the uid:

/**
 * privileged_wrt_inode_uidgid - Do capabilities in the namespace work over the inode?
 * @ns: The user namespace in question
 * @idmap: idmap of the mount @inode was found from
 * @inode: The inode in question
 *
 * Return true if the inode uid and gid are within the namespace.
 */
bool privileged_wrt_inode_uidgid(struct user_namespace *ns,
				 struct mnt_idmap *idmap,
				 const struct inode *inode)
{
	return vfsuid_has_mapping(ns, i_uid_into_vfsuid(idmap, inode)) &&
	       vfsgid_has_mapping(ns, i_gid_into_vfsgid(idmap, inode));
}

for this reason, improve the check for hasCurrentUserMapped to verify
that the gid is also mapped, and if it is not, use an intermediate
mount for the container rootfs.

Closes: https://github.com/containers/podman/issues/24159

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-10-04 16:17:04 +02:00
openshift-merge-bot[bot] 70f31281d6
Merge pull request #24114 from kolyshkin/sys-cap
vendor: switch to moby/sys/capability
2024-10-02 16:56:54 +00:00
openshift-merge-bot[bot] 75a6a6681d
Merge pull request #24110 from mheon/fix_rhel_60382_round_2
Add ExposedPorts to Inspect's ContainerConfig
2024-10-02 13:41:34 +00:00
openshift-merge-bot[bot] 857a47de9b
Merge pull request #24082 from Luap99/netns-leak
Fix netns leak on container creation and exit code 1 on SIGTERM.
2024-10-01 21:02:05 +00:00
Kir Kolyshkin 28e01cc8cc Switch to moby/sys/capability
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-10-01 12:52:18 -07:00
Kir Kolyshkin 6a91149b53 platformInspectContainerHostConfig: rm dead code
In this code, g.HostSpecific is _always_ false, as it is never set by
generate.New and is thus left at the default value (false).

Remove dead code.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2024-10-01 12:52:18 -07:00
Matt Heon edc3dc5e11 Add ExposedPorts to Inspect's ContainerConfig
A field we missed versus Docker. Matches the format of our
existing Ports list in the NetworkConfig, but only includes
exposed ports (and maps these to struct{}, as they never go to
real ports on the host).

Fixes https://issues.redhat.com/browse/RHEL-60382

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-10-01 07:54:52 -04:00
openshift-merge-bot[bot] 1f5ec677d8
Merge pull request #24091 from Luap99/mount-race
podman mount: ignore ErrLayerUnknown
2024-09-30 18:31:32 +00:00
Matt Heon a619c03eff Include exposed ports in inspect output when net=host
Previously, we didn't bother including exposed ports in the
container config when creating a container with --net=host. Per
Docker this isn't really correct; host-net containers are still
considered to have exposed ports, even though that specific
container can be guaranteed to never use them.

We could just fix this for host container, but we might as well
make it generic. This patch unconditionally adds exposed ports to
the container config - it was previously conditional on a network
namespace being configured. The behavior of `podman inspect` with
exposed ports when using `--net=container:` has also been
corrected. Previously, we used exposed ports from the container
sharing its network namespace, which was not correct. Now, we use
regular port bindings from the namespace container, but exposed
ports from our own container.

Fixes https://issues.redhat.com/browse/RHEL-60382

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-09-27 12:54:24 -04:00
Paul Holzinger 1950555b26
podman mount: some better error wrapping
As shown in #23671 these functions can return the raw error without any
useful context to the user which makes it hard to understand where
things went wrong. Simply add some context to some error paths here.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-09-27 15:15:23 +02:00
Paul Holzinger 5de7b7c3f3
libpod: remove shutdown.Unregister()
It is never used and needed so let's just remove some dead code.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-09-26 16:20:56 +02:00
Paul Holzinger 0bbef4b830
libpod: rework shutdown handler flow
Currently podman run -d can exit 0 if we send SIGTERM during startup
even though the contianer was never started. That just doesn't make any
sense is horribly confusing for a external job manager like systemd.

The original motivation was to exit 0 for the podman.service in commit
ca7376bb11. That does make sense but it should only do so for the
service and only if the server did indeed gracefully shutdown.

So we rework how the exit logic works, do not let the handler perform
the exit. Instead the shutdown package does the exit after all handlers
are run, this solves the issue of ordering. Then we default to exit code
1 like we did before and allow the service exit handler to overwrite the
exit code 0 in case of a graceful shutdown.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-09-26 16:14:30 +02:00
Paul Holzinger 2de82d523b
libpod: ensure we are not killed during netns creation
When we are killed during netns setup it will leak the netns path as it
was not commited in the db. This is rather common if you run systemctl
stop on a podman systemd unit. Of course we cannot protect against
SIGKILL but in systemd case we get SIGTERM and we really should not exit
in a critical section like this.

Fixes #24044

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-09-26 15:39:20 +02:00
openshift-merge-bot[bot] 4e38381d37
Merge pull request #23900 from Honny1/healthcheck-log
HealthCheck log output options
2024-09-26 11:55:55 +00:00
Jan Rodák de856dab99
Add --health-max-log-count, --health-max-log-size, --health-log-destination flags
These flags can affect the output of the HealtCheck log. Currently, when a container is configured with HealthCheck, the output from the HealthCheck command is only logged to the container status file, which is accessible via `podman inspect`.
It is also limited to the last five executions and the first 500 characters per execution.

This makes debugging past problems very difficult, since the only information available about the failure of the HealthCheck command is the generic `healthcheck service failed` record.

- The `--health-log-destination` flag sets the destination of the HealthCheck log.
  - `none`: (default behavior) `HealthCheckResults` are stored in overlay containers. (For example: `$runroot/healthcheck.log`)
  - `directory`: creates a log file named `<container-ID>-healthcheck.log` with JSON `HealthCheckResults` in the specified directory.
  - `events_logger`: The log will be written with logging mechanism set by events_loggeri. It also saves the log to a default directory, for performance on a system with a large number of logs.

- The `--health-max-log-count` flag sets the maximum number of attempts in the HealthCheck log file.
  - A value of `0` indicates an infinite number of attempts in the log file.
  - The default value is `5` attempts in the log file.
- The `--health-max-log-size` flag sets the maximum length of the log stored.
  - A value of `0` indicates an infinite log length.
  - The default value is `500` log characters.

Add --health-max-log-count flag

Signed-off-by: Jan Rodák <hony.com@seznam.cz>

Add --health-max-log-size flag

Signed-off-by: Jan Rodák <hony.com@seznam.cz>

Add --health-log-destination flag

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-09-25 14:01:35 +02:00
Paul Holzinger 792796183f
libpod: setupNetNS() correctly mount netns
The netns dir has a special logic to bind mout itself and make itslef
shared. This code here didn't which lead to catastrophic bug during
netns unmounting as we were unable to unmount the netns as the mount got
duplicated and had the wrong parent mount. This caused us to loop forever
trying to remove the file.

Fixes https://issues.redhat.com/browse/RHEL-59620
Fixes #23685

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-09-20 15:19:22 +02:00
Brad Stilwell 31cdf1197b fix typo in error message
Fixes: containers/podman#24001

Signed-off-by: Brad Stilwell <stilwelb@us.ibm.com>
2024-09-18 13:24:34 -04:00
openshift-merge-bot[bot] f580ae0d19
Merge pull request #23985 from Luap99/wait-hang
wait: fix handling of multiple conditions with exited
2024-09-18 12:26:28 +00:00