Commit Graph

4374 Commits

Author SHA1 Message Date
Lewis Roy 6e7de438cc
bug: Correct Docker compat REST API image delete endpoint
The Docker `-XDELETE image/$name?force=true` endpoint only removes
containers using an image if they are in a non running state.

In Podman, when forcefully removing images we also forcefully delete
containers using the image including running containers.

This patch changes the Docker image force delete compat API to act like the
Docker API while maintaining commands like `podman rmi -f $imagename`

It also corrects the API return code returned when an image is requested
to be deleted with running containers using it.

Fixes: https://github.com/containers/podman/issues/25871

Signed-off-by: Lewis Roy <lewis@redhat.com>
2025-04-27 20:51:11 +10:00
openshift-merge-bot[bot] 5c5ecdea88
Merge pull request #24150 from dfr/freebsd-system-reset
libpod: fix a confusing error message from 'podman system reset' on F…
2025-04-25 15:34:00 +00:00
Jan Kaluza 224e791161 Replace podman pause image with rootfs.
This commit removes the code to build a local pause
image from the Containerfile. It is replaced with
code to find the catatonit binary and include it in
the Rootfs.

This removes the need to build a local pause container
image.

The same logic is also applied to createServiceContainer
which is originally also based on the pause image.

Fixes: #23292

Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
2025-04-17 08:36:27 +02:00
Jan Kaluza d9914ff27d Fix the fd leaking to aardvark-dns.
The openDirectory function is missing the unix.O_CLOEXEC flag.
As a result, this file descriptor can leak into the aardvark-dns
process which can then block the umount of rootfs - in this case,
the umount fails with "Device or Resource busy" error message.

This commits adds the unix.O_CLOEXEC to unix.Open call, resulting
in this fd to be closed on aardvark-dns exec.

Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
2025-04-15 13:24:03 +02:00
Paul Holzinger d3e2ca57e4
libpod: stats catch ErrStatCgroup
Stat() actually ignored ENOENT errors so there is no point in matching
them, instead of Stat() does not find a valid cgroup file it returns
ErrStatCgroup so match that instead.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-04-11 17:19:38 +02:00
timesince 7cbad232fe chore: make function comment match function name
Signed-off-by: timesince <seekseat@icloud.com>
2025-04-09 19:51:21 +08:00
openshift-merge-bot[bot] 62fe2e0f28
Merge pull request #25815 from giuseppe/fix-hostuser
libpod: --user works with  --hostuser entries
2025-04-08 13:42:24 +00:00
openshift-merge-bot[bot] 20e1b9db3a
Merge pull request #24791 from arsenalzp/issue_24664
Allow filtering containers by command
2025-04-08 12:55:09 +00:00
Giuseppe Scrivano 85024a9ba7
libpod: --user works with --hostuser entries
create the /etc/passwd and /etc/group files before any user/group
lookup so that the entries added dynamically are found by --user.

As a side effect, do not automatically create the group with same
value as the uid when not specified, since it is expected to run with
gid=0.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2025-04-07 18:11:06 +02:00
Paul Holzinger f87ab2b7a6
fix network DB desync after failed connect/disconnect
Networks are stored in two ways in the DB, first a static network list
which holds all the network with its option for the container. Second,
the network status which hold the actual network result from netavark
but only when the container is running.

If the container is running they must be in sync and podman inspect has
checks to ensure that as well it errors out of there is a desync between
the two.

As the adding to the db and doing actual networking configuration are
diffeent parts it possible that one worked while the other failed which
triggers the desync. To avoid this make the network connect/disconnect
code more robust against partial failures. When the network calls fail
we update the db again to remove/add the network back.

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

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-04-04 14:42:20 +02:00
openshift-merge-bot[bot] 76eea47fb3
Merge pull request #25743 from kolyshkin/freebsd-golangci-lint
Add freebsd golangci lint run; fix remaining freebsd warnings
2025-04-03 18:30:54 +00:00
Jan Kaluza 9277643ead Set the IDMappings also when RootfsOverlay is used.
This is related to #23292 and is needed to replace
pause image container with pause container based
on the rootfs.

Without this change, the GIDs and UIDs are not mapped
in the rootfs container which use overlay if --userns=auto
is used. This leads to an error mounting /dev/pts with gid=5,
becuase GID 5 simply does not exist in the pause container
using rootfs.

All the tests pass with this change, but I have to admit
I did not find out why the original code has been introduced.

Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
2025-04-03 11:55:45 +02:00
Kir Kolyshkin 7882de95ff libpod: fix whitespace linter issue on freebsd
> libpod/networking_freebsd.go:228:1: unnecessary trailing newline (whitespace)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-02 13:35:14 -07:00
Kir Kolyshkin 421ee18e18 libpod: add a nolint:wastedassign annotation
TODO: figure this out :)

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-02 13:35:14 -07:00
Kir Kolyshkin 8c0c1c8906 libpod: fix wastedassign warning on freebsd
This one:

> libpod/container_internal_freebsd.go:255:2: assigned to foundUTS, but reassigned without using the value (wastedassign)
> 	foundUTS := false
> 	^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-02 13:35:14 -07:00
Kir Kolyshkin 30fd68cb23 libpod: rm some unused freebsd code
This fixes a bunch of "unused" linter warnings on freebsd.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-02 13:35:14 -07:00
Kir Kolyshkin 8754687b55 libpod: move linux-specific code to _linux.go
This fixes a few "unused" linter warnings on freebsd.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-02 13:35:14 -07:00
Kir Kolyshkin c1c963affe libpod: fix unconvert linter warning
When linting for freebsd, Stat_t Bsize is always uint64, thus the
following warning:

> libpod/info.go:234:21: unnecessary conversion (unconvert)
> 	allocated := uint64(grStats.Bsize) * grStats.Blocks
> 	                   ^

Use an intermediate variable to save on linter annotations.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-02 13:35:14 -07:00
Kir Kolyshkin 0eea1cb297 libpod: don't capitalize error string
This fixes the following warning:

> libpod/networking_freebsd.go:148:19: ST1005: error strings should not be capitalized (staticcheck)
> 		return "", nil, fmt.Errorf("Failed to create vnet jail %s for container %s: %w", netns, ctr.ID(), err)
> 		                ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-02 13:35:14 -07:00
Kir Kolyshkin 66c7efdb6b libpod: use context.TODO to fix SA1012 on freebsd
This one:

> libpod/container_internal_freebsd.go:393:37: SA1012: do not pass a nil Context, even if a function permits it; pass context.TODO if you are unsure about which Context to use (staticcheck)
> 		inspectData, err := image.Inspect(nil, nil)
> 		                                  ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-02 13:35:14 -07:00
Kir Kolyshkin 4165877c58 libpod: gix a govet warning on freebsd
> libpod/networking_freebsd.go:160:4: printf: github.com/sirupsen/logrus.Errorf does not support error-wrapping directive %w (govet)
> 			logrus.Errorf("failed to destroy vnet jail %s: %w", netns, err)
> 			^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-02 13:35:14 -07:00
Kir Kolyshkin 851bd141af Fix errcheck warnings on freebsd
These two:

> libpod/container_internal_freebsd.go:183:33: Error return value of `c.runtime.state.UpdateContainer` is not checked (errcheck)
> 	c.runtime.state.UpdateContainer(nsCtr)
> 	                               ^
> pkg/specgen/generate/config_freebsd.go:51:12: Error return value is not checked (errcheck)
> 		addDevice(g, resolvedDevicePath)
> 		         ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-02 13:35:14 -07:00
openshift-merge-bot[bot] 4b2472595c
Merge pull request #25753 from flouthoc/vendor-common
vendor: bump c/common to `9b0d134f392`
2025-04-01 19:09:00 +00:00
flouthoc 74356e1b5a
config: use ErrInvalidName
SA1019: types.RegexError is deprecated: use [ErrInvalidName] instead.

Making linter happy.

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2025-04-01 10:14:51 -07:00
Kir Kolyshkin 7c175064da libpod: rm nolint annotation
It does not make sense because MemInfo.MemTotal is always int64 so the
conversion is always needed.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-31 12:27:55 -07:00
Kir Kolyshkin 6b1033eaa0 libpod/events: refactor to eliminate unused code
Shuffle the code around to eliminate "unused" warnings when linting
with various GOOS and build tags.

The only change in functionality should be that now NewEventer
returns ErrNoJournaldLogging (rather than "unknown event logger type")
on freebsd when journald is requested.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-31 12:27:55 -07:00
Kir Kolyshkin 0f975f8526 ci: rm allow-unused from nolintlint settings
This was added by commit 84e42877a ("make lint: re-enable revive"),
making nolintlint became almost useless.

Remove the ungodly amount of unused nolint annotations.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-31 12:27:55 -07:00
Kir Kolyshkin f4f2580b0d ci: remove stylecheck linter
It is to be merged into staticcheck linter in golangci-lint v2.0.0.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-31 12:27:55 -07:00
Kir Kolyshkin 5aa035c69c libpod: fix a few minor staticcheck warnings
These:

> libpod/container_copy_common.go:34:16: QF1011: could omit type bool from declaration; it will be inferred from the right-hand side (staticcheck)
> 		locked       bool = true
> 		             ^
> libpod/container_internal_common.go:793:3: QF1006: could lift into loop condition (staticcheck)
> 		if maxSymLinks > 40 {
> 		^
> libpod/oci_conmon_linux.go:170:2: QF1007: could merge conditional assignment into variable declaration (staticcheck)
> 	mustCreateCgroup := true
> 	^

Should not result in any change of logic.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-31 12:27:55 -07:00
Kir Kolyshkin 0105131b5c Fix QF1003: could use tagged switch" staticcheck warning
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-31 12:27:55 -07:00
Kir Kolyshkin 0dddc5e3c0 Apply De Morgan's law
This fixes a bunch of "QF1001: could apply De Morgan's law" warnings
from staticcheck linter.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-03-31 12:27:55 -07:00
Micah Chambers (eos) dce36131ae Add cdi-spec-dir option to top level options.
This commit adds new --cdi-spec-dir global option. This
option is used to add additional CDI spec paths.

Signed-off-by: Micah Chambers (eos) <mchambers@anduril.com>
Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
2025-03-28 11:24:57 +01:00
openshift-merge-bot[bot] cb2466004f
Merge pull request #25645 from jankaluza/24418
Add support for --pids-limit in podman kube play.
2025-03-26 16:15:45 +00:00
Jan Kaluza f15b0887c7 Add support for pids-limit annotation for podman kube play.
This commit adds new annotation called:

io.podman.annotations.pids-limit/$ctrname

This annotation is used to define the PIDsLimit for
a particular pod. It is also automatically defined
when newly added --pids-limit option is used.

Fixes: #24418

Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
2025-03-26 10:06:56 +01:00
Victor Toso 321634d599 Add volume SubPath in generate kube
Trying to generate a Pod yaml file when we are using --mount with
SubPath does not generate a VolumeMount with SubPath. This patch fixes
that.

Note that kube play does support SubPath since 95cc7e052, see:
    https://github.com/containers/podman/pull/16803

Signed-off-by: Victor Toso <victortoso@redhat.com>
2025-03-25 11:59:21 +01:00
Paul Holzinger 999a11c8b1
replace deprecated selinux/label calls
These functions were removed in github.com/opencontainers/selinux
v1.12.0.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-24 17:44:43 +01:00
openshift-merge-bot[bot] b2285f6d46
Merge pull request #25626 from jankaluza/24875
Add --env and --unsetenv to podman update.
2025-03-21 13:52:17 +00:00
Jan Kaluza 701aade262 Add --env and --unsetenv to podman update.
The --env is used to add new environment variable to container or
override the existing one. The --unsetenv is used to remove
the environment variable.

It is done by sharing "env" and "unsetenv" flags between both
"update" and "create" commands and later handling these flags
in the "update" command handler.

The list of environment variables to add/remove is stored
in newly added variables in the ContainerUpdateOptions.

The Container.Update API call is refactored to take
the ContainerUpdateOptions as an input to limit the number of its
arguments.

The Env and UnsetEnv lists are later handled using the envLib
package and the Container is updated.

The remote API is also extended to handle Env and EnvUnset.

Fixes: #24875

Signed-off-by: Jan Kaluza <jkaluza@redhat.com>
2025-03-21 13:15:44 +01:00
Giuseppe Scrivano 88b62d2c27
vendor: update c/common
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2025-03-20 13:37:19 +01:00
openshift-merge-bot[bot] 5c9fd29808
Merge pull request #25617 from giuseppe/use-securejoin-openinroot
container: replace code with securejoin.OpenInRoot()
2025-03-19 13:37:37 +00:00
Giuseppe Scrivano 51ca839c14
libpod: fix handling of additional gids in exec
change the behavior to match what Docker does.

Docker always adds the specified additional gids, no matter the user
specified to exec.

Instead the additional gids read from the /etc/group file are added
only when there is not an explicit group specified in the exec
userspec.

➜ docker run -d --name container-with-groups --group-add mail --group-add news --group-add cron --group-add ftp --rm alpine top
c4190928097f64cabb83af7cac6ec10041a9e74de359433dfd3e5b9d8a7dce1a
➜ docker exec container-with-groups id -G
0 1 2 3 4 6 10 11 12 13 16 20 21 26 27
➜ docker exec --user root container-with-groups id -G
0 1 2 3 4 6 10 11 12 13 16 20 21 26 27
➜ docker exec --user nobody container-with-groups id -G
65534 12 13 16 21
➜ docker exec --user nobody:nobody container-with-groups id -G
65534 12 13 16 21
➜ docker exec --user root:root container-with-groups id -G
0 12 13 16 21
➜ docker exec --user root:root container-with-groups id -G
0 12 13 16 21

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2025-03-19 12:56:27 +01:00
Giuseppe Scrivano c0627de21d
container: replace code with securejoin.OpenInRoot()
when the code was first added, there was no securejoin.OpenInRoot().
Since there is a function already provided by a dependency and already
used in libpod, replace the custom code with securejoin.OpenInRoot().

The new version does not report a symlink that points outside the
root, but it is still resolved relative to the specified mountpoint,
since that is the openat2 semantic.  It does not affect the security
of the function.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2025-03-19 09:32:47 +01:00
Matt Heon 687fe08f42 Fix a potential deadlock during `podman cp`
Have one function without a `defer lock.unlock()` as one of the
commands in it calls a function that also takes the same lock,
so the unlock has to happen prior to function completion.
Unfortunately, this is prone to errors, like the one here: I
missed a case, and we could return without unlocking, causing a
deadlock later in the cleanup code as we tried to take the same
lock again.

Refactor the command to use `defer unlock()` to simplify and
avoid any further errors of this type.

Introduced by e66b788a51 - this
should be included in any backports of that commit.

Fixes #25585

Signed-off-by: Matt Heon <mheon@redhat.com>
2025-03-14 10:37:59 -04:00
openshift-merge-bot[bot] d1d8f3334f
Merge pull request #25520 from Honny1/fix-hc-inf-log
Fix HealthCheck log destination, count, and size defaults
2025-03-13 18:59:34 +00:00
openshift-merge-bot[bot] 79e05ca199
Merge pull request #25575 from giuseppe/test-not-safe-for-parallel
libpod: improve createRootlessContainer
2025-03-13 17:35:40 +00:00
Giuseppe Scrivano a2953dad10
libpod: improve createRootlessContainer
do not run the expensive pmount.GetMounts() function if it is not
needed.

As a follow-up for commit c9c44d400c, do
not restore the propagation flag for the parent mount to shared unless
it was changed to slave first.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2025-03-13 16:55:11 +01:00
Paul Holzinger a1008a1294
libpod: add missing return in WaitForConditionWithInterval()
AS pointed out by Valentin on #25491, it is not an actual bug but this
is makes it more clear how it works and should not confuse readers why
this case has no return.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-13 14:10:33 +01:00
Jan Rodák fff42ac232
Fix HealthCheck log destination, count, and size defaults
GoLang sets unset values to the default value of the type. This means that the destination of the log is an empty string and the count and size are set to 0. However, this means that size and count are unbounded, and this is not the default behavior.

Fixes: https://github.com/containers/podman/issues/25473
Fixes: https://issues.redhat.com/browse/RHEL-83262

Signed-off-by: Jan Rodák <hony.com@seznam.cz>
2025-03-12 21:27:00 +01:00
Paul Holzinger 9e94dc53b2
add new artifact mount type
Add a new option to allow for mounting artifacts in the container, the
syntax is added to the existing --mount option:
type=artifact,src=$artifactName,dest=/path[,digest=x][,title=x]

This works very similar to image mounts. The name is passed down into
the container config and then on each start we lookup the artifact and
the figure out which blobs to mount. There is no protaction against a
user removing the artifact while still being used in a container. When
the container is running the bind mounted files will stay there (as the
kernel keeps the mounts active even if the bind source was deleted).
On the next start it will fail to start as if it does not find the
artifact. The good thing is that this technically allows someone to
update the artifact with the new file by creating a new artifact with
the same name.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-12 19:42:14 +01:00
Paul Holzinger b232ea3d18
create artifact store in the libpod runtime
Instead of duplicating the NewArtifactStore() call in many places and
having to make sure we always pass the same path to it define it as
function on the runtime. This allows any caller with access to the
libpod runtime to create the store easily.

This is suing a sync.OnceValues() function so the store is initialized
only once and only when actually needed.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-12 19:42:13 +01:00