4320 Commits

Author SHA1 Message Date
eed5f9ee4a libpod: race in WaitForConditionWithInterval()
There are multiple concurrent goroutinces which produce result and they
race agains each other, while producing different results.

This commit addresses at least a part of the problem - producing
different results for competing "sources".

Fixes: #25479

Signed-off-by: Yuri Timenkov <yuri@timenkov.pro>
2025-03-06 12:40:43 +00:00
d0efd0e278 libpod: race in WaitForExit() with autoremove
When waiting for container to be not-running, sometimes wait retuns code
-1 with an empty error instead of actual exit code.

It turned out that syncContainer returns ErrCtrRemoved for a removed
container instead of ErrNoSuchCtr, while data can still be pulled from
the database.

This fixes the issue by taking into account both codes.

Fixes: #25479

Signed-off-by: Yuri Timenkov <yuri@timenkov.pro>
2025-03-06 12:37:47 +00:00
47a743bba2 report healthcheck start errors
When starting a container consider healthcheck errors fatal. That way
user know when systemd-run failed to setup the timer to run the
healthcheck and we don't get into a state where the container is running
but not the healthcheck.

This also fixes the broken error reporting from the systemd-run exec, if
the binary could not be run the output was just empty leaving the users
with no idea what failed.

Fixes #25034

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-04 16:48:50 +01:00
511d912685 Add stopped status for HealthCheck
If the container is stopped and the ongoing HealthCheck has no chance to complete the check is evaluated as stopped.

Fixes: https://issues.redhat.com/browse/RUN-2520
Fixes: https://github.com/containers/podman/issues/25276

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2025-03-03 17:09:30 +01:00
efe8e165d8 Merge pull request #25417 from mheon/fix_25368
Fix volume quota assignment
2025-03-01 15:11:06 +00:00
20523152f8 Add "create" and "remove" events for secrets.
This commit adds the "secret" Event type and emits
"create" and "remove" events for this Event type
when Secret is created or removed.

This can be used for example by podman interfaces to
view and manage secrets.

Fixes: #24030

Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
2025-02-28 16:58:06 +01:00
f71067d710 Create quota before _data dir for volumes
This resolves an ordering issue that prevented quotas from being
applied. XFS quotas are applied recursively, but only for
subdirectories created after the quota is applied; if we create
`_data` before the quota, and then use `_data` for all data in
the volume, the quota will never be used by the volume.

Also, add a test that volume quotas are working as designed using
an XFS formatted loop device in the system tests. This should
prevent any further regressions on basic quota functionality,
such as quotas being shared between volumes.

Fixes #25368

Signed-off-by: Matt Heon <mheon@redhat.com>
2025-02-28 09:52:55 -05:00
4695564730 oci: report empty exec path as ENOENT
unify the error codes returned by runc and crun.

Fix the tests to work with both runtimes, as well as the
https://github.com/containers/crun/pull/1672 changes in progress for
crun.

Follow-up for https://github.com/containers/podman/pull/25340

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2025-02-18 22:01:08 +01:00
e88ccec7ed Merge pull request #25311 from mheon/fix_25289
Add SyncMap package and use it for graph stop/remove
2025-02-18 13:22:42 +00:00
c65bb903b6 test: adapt tests new crun error messages
Needed-by: https://github.com/containers/crun/pull/1672

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2025-02-17 20:47:43 +01:00
0f443f22ca Add syncmap package and use it for graph stop/remove
This greatly simplifies the locking around these two functions,
and things end up looking a lot more elegant. This should prevent
the race flakes we were seeing before.

Fixes #25289

Signed-off-by: Matt Heon <mheon@redhat.com>
2025-02-17 14:32:34 -05:00
24e2e9c69b Merge pull request #25003 from Honny1/no-db-healtcheck-exec
Run HealthCheck without saving the `ExecSession` to the database
2025-02-13 10:14:28 +00:00
62cde17193 Merge pull request #25297 from mheon/fix_25291
Remove persist directory when cleaning up Conmon files
2025-02-11 21:09:46 +00:00
ce8813dc8d Remove persist directory when cleaning up Conmon files
This seems to have been added as part of the cleanup of our
handling of OOM files, but code was never added to remove it, so
we leaked a single directory with an exit file and OOM file per
container run. Apparently have been doing this for a while - I'd
guess since March of '23 - so I'm surprised more people didn't
notice.

Fixes #25291

Signed-off-by: Matt Heon <mheon@redhat.com>
2025-02-11 14:51:34 -05:00
4a0b230610 Merge pull request #24775 from mheon/fix_24738
In SQLite state, use defaults for empty-string checks
2025-02-11 15:43:09 +00:00
ad9839ac55 Run HealthCheck without creating and removing the ExecSession in the database
Fixes: https://issues.redhat.com/browse/RHEL-69970

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2025-02-11 13:59:00 +01:00
e943a2b064 Merge pull request #25275 from dfr/freebsd-hascapresource
libpod: make hasCapSysResource platform-specific
2025-02-10 19:01:07 +00:00
cb53abca28 In SQLite state, use defaults for empty-string checks
As part of our database init, we perform a check of the current
values for a few fields (graph driver, graph root, static dir,
and a few more) to validate that Libpod is being started with a
sane & sensible config, and the user's containers can actually be
expected to work. Basically, we take the current runtime config
and compare against values cached in the database from the first
time Podman was run.

We've had some issues with this logic before this year around
symlink resolution, but this is a new edge case. Somehow, the
database is being loaded with the empty string for some fields
(at least graph driver) which is causing comparisons to fail
because we will never compare against "" for those fields - we
insert the default value instead, assuming we have one.

Having a value of "" in the database largely invalidates the
check so arguably we could just drop it, but what BoltDB did -
and what SQLite does after this patch - is to use the default
value for comparison instead of "". This should still catch some
edge cases, and shouldn't be too harmful.

What this does not do is identify or solve the reason that we are
seeing the empty string in the database at all. From my read on
the logic, it must mean that the graph driver is explicitly set
to "" in the c/storage config at the time Podman is first run and
I'm not precisely sure how that happens.

Fixes #24738

Signed-off-by: Matt Heon <mheon@redhat.com>
2025-02-10 12:42:11 -05:00
a475083bff Merge pull request #25169 from mheon/graph_stop
Add graph-based pod stop
2025-02-10 17:00:19 +00:00
ab0410948a libpod: make hasCapSysResource platform-specific
I'm not sure if there is an equivalent to CAP_SYS_RESOURCE on FreeBSD
but for now, I have added a no-op stub which returns false.

Signed-off-by: Doug Rabson <dfr@rabson.org>
2025-02-10 14:52:10 +00:00
46d874aa52 Refactor graph traversal & use for pod stop
First, refactor our existing graph traversal code to improve code
sharing. There still isn't much sharing between inward traversal
(stop, remove) and outward traversal (start) but stop and remove
are sharing most of their code, which seems a positive.

Second, add a new graph-traversal function to stop containers.
We already had start and remove; stop uses the newly-refactored
inward-traversal code which it shares with removal.

Third, rework the shared stop/removal inward-traversal code to
add locking. This allows parallel execution of stop and removal,
which should improve the performance of `podman pod rm` and
retain the performance of `podman pod stop` at about what it is
right now.

Fourth and finally, use the new graph-based stop when possible
to solve unordered stop problems with pods - specifically, the
infra container stopping before application containers, leaving
those containers without a working network.

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

Signed-off-by: Matt Heon <mheon@redhat.com>
2025-02-06 18:28:12 -05:00
39becc2f05 Merge pull request #24781 from ashley-cui/builtfor
Add BuildOrigin field to podman info
2025-02-04 20:13:27 +00:00
06fa617f61 Lock pod while starting and stopping containers
The intention behind this is to stop races between
`pod stop|start` and `container stop|start` being run at the same
time. This could result in containers with no working network
(they join the still-running infra container's netns, which is
then torn down as the infra container is stopped, leaving the
container in an otherwise unused, nonfunctional, orphan netns.

Locking the pod (if present) in the public container start and
stop APIs should be sufficient to stop this.

Signed-off-by: Matt Heon <mheon@redhat.com>
2025-02-03 11:19:20 -05:00
f0ef791808 podman exec: correctly support detaching
podman exec support detaching early via the detach key sequence. In that
case the podman process should exit successfully but the container exec
process keeps running.

Now I wrote automated test for both podman run and exec detach but this
uncovered several larger issues:
 - detach sequence parsing is broken[1]
 - podman-remote exec detach is broken[2]
 - detach in general seems to be buggy/racy, seeing lot of flakes that
   fail to restore the terminal and get an EIO instead, i.e.
   "Unable to restore terminal: input/output error"

Thus I cannot add tests for now but this commit should at least fix the
obvoius case as reported by the user so I like to get this in regardless
and I will work through the other issues once I have more time.

Fixes #24895

[1] https://github.com/containers/common/pull/2302
[2] https://github.com/containers/podman/issues/25089

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-01-31 13:29:04 +01:00
3eb0e1e8ac libpod: remove unused ExecStartAndAttach()
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-01-31 13:28:01 +01:00
d3706bcad1 Add BuildOrigin field to podman info
BuildOrigin is a field that can be set at build time by packagers. This helps us trace how and where the binary was built and installed from, allowing us to see if the issue is due to a specfic installation or a general podman bug. This field shows up in podman version and in podman info when populated. Note that podman info has a new field, Client, that only appears when running podman info using the remote client.

Automatically set the BuildOrigin field when building the macOS pkginstaller to pkginstaller.

Usage: make podman-remote BUILD_ORIGIN="mypackaging"

Signed-off-by: Ashley Cui <acui@redhat.com>
2025-01-30 14:48:30 -05:00
511c8b249d Remove timer for HealthCheck when container is paused.
If is unpaused then new timer for  HealthCheck is created.

Fixes: https://issues.redhat.com/browse/RUN-2468

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2025-01-29 13:34:26 +01:00
81eb84fdaa Clean up after unexpectedly terminated build
The `podman system prune` command is able to remove build containers that were created during the build, but were not removed because the build terminated unexpectedly.

By default, build containers are not removed to prevent interference with builds in progress. Use the **--build** flag when running the command to remove build containers as well.

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

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2025-01-27 14:21:27 +01:00
cfeefb3219 Remove JSON tag from UseImageHosts in ContainerConfig
This did not have a JSON tag prior to being added by #25008. By
adding one we risk a breaking change in the DB (particularly
given the change in case - useImageHosts vs UseImageHosts) which
we should try to avoid.

Remove the tag given this.

Signed-off-by: Matt Heon <mheon@redhat.com>
2025-01-20 13:43:51 -05:00
805e78c2aa Set network ID if available during container inspect
Fixes #24910

Signed-off-by: Florian Apolloner <florian@apolloner.eu>
2025-01-20 15:55:26 +01:00
d4fce5178f Merge pull request #24974 from rhatdan/quadlet
Switch all calls of assert.Nil to assert.NoError
2025-01-20 14:34:13 +00:00
3fb37c588d Switch all calls of assert.Nil to assert.NoError
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2025-01-15 07:08:27 -05:00
6565bde6e8 Add --no-hostname option
Fixes: https://github.com/containers/podman/issues/25002

Also add the ability to inspect containers for
UseImageHosts and UseImageHostname.

Finally fixed some bugs in handling of --no-hosts for Pods,
which I descovered.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2025-01-15 06:51:32 -05:00
0798f54e94 Merge pull request #24655 from mheon/fix_volume_perms_cp
Mount volumes before copying into a container
2025-01-08 14:51:46 +00:00
e9fb805522 update golangci/golangci-lint to v1.63.4
Fix new issues found by usetesting, mainly we should use t.TempDir() in
test which makes the code better as this will be removed on test end
automatically so no need for defer or any error checking.
Also fix issues reported by exptostd, these mainly show where we can
switch the imports to the std maps/slices packages instead of the
golang.org/x/exp/... packages.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-01-07 15:48:53 +01:00
b4ef95590b Merge pull request #24868 from rhatdan/kube
Kube volumes can not contain _
2025-01-07 01:23:05 +00:00
6fa234a5de Pass container hostname to netavark
Passing the hostname allows netavark to include it in DHCP lease
requests which, in an environment where DDNS is used, can cause
DNS entries to be created automatically.

* The current Hostname() function in container.go was updated to
check the new `container_name_as_hostname` option in the
CONTAINERS table of containers.conf.  If set and no hostname
was configured for the container, it causes the hostname to be
set to a version of the container's name with the characters not
valid for a hostname removed.  If not set (the default), the original
behavior of setting the hostname to the short container ID is
preserved.

* Because the Hostname() function can return the host's hostname
if the container isn't running in a private UTS namespace, and we'd
NEVER want to send _that_ in a DHCP request for a container, a new
function NetworkHostname() was added which functions like Hostname()
except that it will return an empty string instead of the host's
hostname if the container is not running in a private UTS namespace.

* networking_common.getNetworkOptions() now uses NetworkHostname()
to set the ContainerHostname member of the NetworkOptions structure.
That member was added to the structure in a corresponding commit in
common/libnetwork/types/network.go.

* Added test to containers_conf_test.go

Signed-off-by: George Joseph <g.devel@wxy78.net>
2025-01-06 07:09:12 -07:00
7ba410aa76 Merge pull request #24760 from Honny1/fix-major-minor-nums
Fix device limitations in `podman-remote update` on remote systems
2024-12-18 14:15:11 +00:00
ecd882f9f7 Kube volumes can not container _
Need to substiture all _ to - for k8s support.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-12-18 09:07:57 -05:00
8b23e6d408 When generating host volumes for k8s, force to lowercase
Fixes: https://github.com/containers/podman/issues/16542

Kubernetes only allows lower case persistent volume names.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2024-12-16 11:22:22 -05:00
2f31a61cce Fix device limitations in podman-remote update on remote systems
Fixes: https://issues.redhat.com/browse/RUN-2381

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-12-09 17:35:56 +01:00
8f1266c717 Fix overwriting of LinuxResources structure in the database
with defaults values when changes configuration with podman update.

The new LinuxResource structure does not represent the current unchanged configuration, which was not affected by the change.

Fixes: https://issues.redhat.com/browse/RUN-2375

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2024-12-04 13:16:32 +01:00
45ac4e2383 Merge pull request #24731 from l0rd/additionalimagestores
Fix additional image stores in podman info
2024-12-03 14:15:08 +00:00
0d3a653c30 Fix podman info with multiple imagestores
The command `podman info` returned only one imagestore in
`store.graphOptions.<driver>.imagestore` even if multiple
image stores were configured.

This change replaces the field `<driver>.imagestore` with
the field `<driver>.additionalImageStores`, that instead
of a string is an array of strings and that includes all
the configured additional image stores.

Fix https://github.com/containers/storage/issues/2094

Signed-off-by: Mario Loriedo <mario.loriedo@gmail.com>
2024-12-02 15:37:16 +00:00
49b52227b4 refact: use uptime.minutes instead of uptime.seconds
Signed-off-by: ksw2000 <13825170+ksw2000@users.noreply.github.com>
2024-12-02 07:35:52 +00:00
3d720ce16b Merge pull request #24702 from mi4r/dev/mi4r/importBuilderNullDerefFix
api: Error checking before NULL dereference
2024-11-28 12:36:53 +00:00
1fa27ffb62 api: Error checking before NULL dereference
Move error checking of possible null returned value before
its dereference in importBuilder.Format

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Signed-off-by: Tigran Sogomonian <tsogomonian@astralinux.ru>
2024-11-28 14:01:45 +03:00
4b38294e92 spec: clamp rlimits without CAP_SYS_RESOURCE
commit 5ebba75dbd4462da47283b3f018804b7361d52bf implemented this
behaviour for rootless users and later commit
0a69aefa41d55d2aa30333d6a4ce76b178d1ed5b changed it when in a user
namespace, but the same limitation exists for root without
CAP_SYS_RESOURCE.  Change the check to use the clamp to the current
values if running without CAP_SYS_RESOURCE.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-11-27 21:35:00 +01:00
e66b788a51 Mount volumes before copying into a container
This solves several problems with copying into volumes on a
container that is not running.

The first, and most obvious, is that we were previously entirely
unable to copy into a volume that required mounting - like
image volumes, volume plugins, and volumes that specified mount
options.

The second is that this fixed several permissions and content
issues with a fresh volume and a container that has not been run
before. A copy-up will not have occurred, so permissions on the
volume root will not have been set and content will not have been
copied into the volume.

If the container is running, this is very low cost - we maintain
a mount counter for named volumes, so it's just an increment in
the DB if the volume actually needs mounting, and a no-op if it
doesn't.

Unfortunately, we also have to fix permissions, and that is
rather more complicated. This involves an ugly set of manual
edits to the volume state to ensure that the permissions fixes
actually worked, as the code was never meant to be used in this
way. It's really ugly, but necessary to reach full Docker
compatibility.

Fixes #24405

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2024-11-27 08:09:50 -05:00
44b0c24ca5 Revert "libpod: remove shutdown.Unregister()"
This reverts commit 5de7b7c3f379987faa9cb06a58be8914f2d56cbe.

We now require the Unregister shutdown handler function for
handling unmounting named volumes after `podman cp` into a
stopped container.

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-11-27 08:09:50 -05:00