Commit Graph

210 Commits

Author SHA1 Message Date
Kir Kolyshkin f589811073 pkg/rootless: fix ST1005 warning for freebsd
> pkg/rootless/rootless_freebsd.go:24:20: ST1005: error strings should not be capitalized (staticcheck)
> 	return false, -1, errors.New("Rootless mode is not supported on FreeBSD - run podman as root")
> 	                  ^

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2025-04-02 13:35:14 -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
Giuseppe Scrivano c06dba4845
rootless: fix hang on s390x
avoid using the glibc fork() function after using directly the clone()
syscall, as it confuses glibc causing the fork() to hang in some
cases.

The issue has been observed only on s390x, and the fix was confirmed
in the issue discussion.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2025-02-06 13:49:53 +01:00
Federico Di Pierro 51fd6e906c fix(pkg/rootless): avoid memleak during init() contructor.
`argv[0]`, ie: the full buffer allocated by `get_cmd_line_args`,
was going to be freed only if `can_use_shortcut()` was called.
Instead, let `init()` always manage `argv0` lifecycle.

Signed-off-by: Federico Di Pierro <nierro92@gmail.com>
2025-01-30 12:11:42 +01:00
Giuseppe Scrivano c81c77109b
vendor: update containers/storage
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-09-24 20:28:30 +02:00
Paul Holzinger 3350cd3eed
pkg/rootless: simplify reexec for container code
The code currently tried to avoid joining the userns from conmon
directly and rather joined to only read the pid file and then send this
back to use so we could join the userns. From the comment this was done
because we could not read the pid file. However this is no longer true
as of commit 49eb5af301 and file is no always owned by the real user.

This means we can just remove this special logic and join the namespace
directly there. A test has been added to check the rejoin logic with a
custom uidmapping.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-07-08 13:28:31 +02:00
Paul Holzinger 7c5c60bc39
pkg/rootless: set _CONTAINERS_USERNS_CONFIGURED correctly
This is a bit weird and I admit I don't understand exactly how the init
value is used but this seems wrong. When podman reexec itself it then
gets the wrong init value and because rootless_uid() will be 0 the
init() function in rootless_linux.go will not set it either because of
that. Thus the first reexec has the wrong env.

Now that I make use of it in c/common[1] this turns out top be a real
issue and is failing all first podman commands. To reproduce make sure
to kill the pause process then just run any podman command with the new
c/common vendor and without this patch.

[1] https://github.com/containers/common/pull/2020

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-06-04 17:58:39 +02:00
Paul Holzinger 2a609b0f74
rootless: fix reexec to use /proc/self/exe
Under some circumstances podman might be executed with a different argv0
than the actual path to the podman binary. This breaks the reexec logic
as it tried to exec argv0 which failed.

This is visible when using podmansh as login shell which get's the
special -podmansh on argv0 to signal the shell it is a login shell.

To fix this we can simply use /proc/self/exe as command path which is
much more robust and the argv array is still passed correctly.

Fixes #22672

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2024-05-14 12:02:19 +02:00
Giuseppe Scrivano aab06ac445
pkg/rootless: use fileutils.(Le|E)xists
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-19 09:52:14 +02:00
Giuseppe Scrivano aee1e1408d
rootless: drop function ReadMappingsProc
use the equivalent GetHostIDMappings from the storage unshare package.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2024-04-10 11:55:35 +02:00
Matt Heon 72f1617fac Bump Go module to v5
Moving from Go module v4 to v5 prepares us for public releases.

Move done using gomove [1] as with the v3 and v4 moves.

[1] https://github.com/KSubedi/gomove

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-02-08 09:35:39 -05:00
Matt Heon 9fb57d346f Cease using deprecated runc userlookup
Instead switch to github.com/moby/sys/user, which we already had
as an indirect dependency.

Signed-off-by: Matt Heon <mheon@redhat.com>
2024-02-02 11:02:43 -05:00
Oleksandr Redko 2a2d0b0e18 chore: delete obsolete // +build lines
Signed-off-by: Oleksandr Redko <Oleksandr_Redko@epam.com>
2024-01-04 11:53:38 +02:00
Giuseppe Scrivano d636ce8d76
rootless: use functionalities from c/storage
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-11-10 22:03:47 +01:00
Paul Holzinger 29273cda10
lint: fix warnings found by perfsprint
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-10-20 16:27:46 +02:00
Valentin Rothberg e596b17fbe add a podman-compose command
**podman compose** is a thin wrapper around an external compose provider
such as docker-compose or podman-compose.  This means that `podman
compose` is executing another tool that implements the compose
functionality but sets up the environment in a way to let the compose
provider communicate transparently with the local Podman socket.  The
specified options as well the command and argument are passed directly
to the compose provider.

The default compose providers are `docker-compose` and `podman-compose`.
If installed, `docker-compose` takes precedence since it is the original
implementation of the Compose specification and is widely used on the
supported platforms (i.e., Linux, Mac OS, Windows).

If you want to change the default behavior or have a custom installation
path for your provider of choice, please change the `compose_provider`
field in `containers.conf(5)`.  You may also set the
`PODMAN_COMPOSE_PROVIDER` environment variable.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-07-24 19:23:04 +02:00
Valentin Rothberg 60a5a59475 make lint: enable mirror
Helpful reports to avoid unnecessary allocations.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2023-06-19 14:11:12 +02:00
Paul Holzinger 6bc52c9c5e
pkg/rootless: correctly handle proxy signals on reexec
There are quite a lot of places in podman were we have some signal
handlers, most notably libpod/shutdown/handler.go.

However when we rexec we do not want any of that and just send all
signals we get down to the child obviously. So before we install our
signal handler we must first reset all others with signal.Reset().

Also while at it fix a problem were the joinUserAndMountNS() code path
would not forward signals at all. This code path is used when you have
running containers but the pause process was killed.

Fixes #16091
Given that signal handlers run in different goroutines parallel it would
explain why it flakes sometimes in CI. However to my understanding this
flake can only happen when the pause process is dead before we run the
podman command. So the question still is what kills the pause process?

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-05-25 16:48:15 +02:00
tomsweeneyredhat c8e423b55e Add file swith for pre-exec
The long term goal was to provide the customer a way to turn on the
preexec_hooks processing of script by having some kind of configuration
that could be read.  I had tried putting it into containers.conf to
start, but that turned out to be unyieldly quickly and time is of
the essence for this fix.  That is mostly due to the fact that this
code is preexecution and in C, the conatiners.conf file is read in
Go much further down the stack.

After first trying this process using an ENVVAR, I have
thought it over and chatted with others and will now look for a
/etc/containers/podman_preexec_hooks.txt file to exist.  If the admin
had put one in there, we will then process the files in the
directories `/usr/libexec/podman/pre-exec-hooks`
and `/etc/containers/pre-exec-hooks`.

Thoughts/suggestions gratefully accepted. This will be a 8.8/9.2 ZeroDay
fix and will need to be backported to the v4.4.1-rhel branch.

Signed-off-by: tomsweeneyredhat <tsweeney@redhat.com>
2023-04-26 10:20:10 -04:00
Paul Holzinger 38c217a0bf
pkg/rootless: use catatonit from /usr/libexec/podman
The path was missing a slash between the libexec path and the binary
name. This was never noticed because the code already falls back to a
builtt-in pause process.

Fixes: 71f96c2e6f ("rootless: define LIBEXECPODMAN")

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2023-04-11 11:00:07 +02:00
Giuseppe Scrivano 266cc78829
rootless: drop preexec hook error message
the exec hooks already print the error message, so there is no need to
print another one.

[NO NEW TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-03-31 09:58:07 +02:00
Giuseppe Scrivano 0498ce3a56
cmd: do not require userns for "version"
Closes: https://github.com/containers/podman/issues/17657

[NO NEW TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-03-03 14:27:54 +01:00
Giuseppe Scrivano a581d2a041
rootless: rename auth-scripts to preexec-hooks
to not give a false sense of security since these are not a security
mechanism but a hook to run arbitrary code before executing a
command.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2023-01-17 10:58:46 +01:00
Giuseppe Scrivano 1bac160960
rootless: always create userns with euid != 0
always create a user namespace when running with euid != 0 since the
user is not owning the current mount namespace.

This issue happened on a Kubernetes cluster, where the pod was running
privileged but the UID was not 0, as it was configured in the image
itself.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-12-20 13:33:23 +01:00
Giuseppe Scrivano 90719d38f7
rootless: inhibit copy mapping for euid != 0
when running with euid != 0, inhibit the copy of the current mappings,
even if the kernel allows that.  This seems to be the expectation when
running in a Kubernetes cluster with a non-root user.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-12-20 13:32:58 +01:00
Daniel J Walsh 41a70adc74
Merge pull request #16859 from dfr/freebsd-rootless
pkg/rootless: Change error text ...
2022-12-15 20:34:14 -05:00
Doug Rabson f0a8c0bd97 pkg/rootless: Change error text ...
... redirect the user to run with superuser privileges instead of
printing 'this function is not supported'.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-12-15 17:40:21 +00:00
Giuseppe Scrivano 290019c486
rootless: add cli validator
whenever the podman process is launched, it runs any file found in
these directories:

- /etc/containers/auth-scripts
- /usr/libexec/podman/auth-scripts

The current podman command line is passed as arguments to the
process.

If any of the processes fail, the error is immediately reported back
from podman that exits with the same error code.

[NO NEW TESTS NEEDED] requires a system-wide configuration.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-12-15 18:31:16 +01:00
Giuseppe Scrivano 71f96c2e6f
rootless: define LIBEXECPODMAN
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-12-15 18:30:21 +01:00
Valentin Rothberg dcbf7b4481 bump golangci-lint to v1.50.1
Also fix a number of duplicate words.  Yet disable the new `dupword`
linter as it displays too many false positives.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-12-15 13:39:56 +01:00
Miloslav Trmač c83efd0f07 Update c/storage after https://github.com/containers/storage/pull/1436
... and update to remove the now-deprecated Locker interface.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2022-12-01 16:05:13 +01:00
Doug Rabson f36b3bc811 pkg/rootless: Implement rootless.IsFdInherited on FreeBSD
This is needed to support --preserve-fds in create and exec.

[NO NEW TESTS NEEDED]

Signed-off-by: Doug Rabson <dfr@rabson.org>
2022-11-15 08:18:41 +00:00
OpenShift Merge Robot f21847917e
Merge pull request #16202 from rhatdan/VENDOR
Update vendor containers/(common,storage, buildah, image)
2022-10-28 14:10:19 -04:00
Giuseppe Scrivano 5dad34212f
rootless: add argument to GetConfiguredMappings
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-10-28 14:26:07 +02:00
Daniel J Walsh 6fe64591d6
Update vendor containers/(common,storage,buildah,image)
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-10-28 06:16:22 -04:00
Erik Sjölund cb2631bf3a rootless: fix return value handling
[NO NEW TESTS NEEDED]

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

Signed-off-by: Erik Sjölund <erik.sjolund@gmail.com>
2022-10-15 10:44:17 +02:00
Chris Evich d968f3fe09
Replace deprecated ioutil
Package `io/ioutil` was deprecated in golang 1.16, preventing podman from
building under Fedora 37.  Fortunately, functionality identical
replacements are provided by the packages `io` and `os`.  Replace all
usage of all `io/ioutil` symbols with appropriate substitutions
according to the golang docs.

Signed-off-by: Chris Evich <cevich@redhat.com>
2022-09-20 15:34:27 -04:00
Daniel J Walsh 3508bd22fe
Add support for podman context as alias to podman system connection
Alias
podman --context -> podman --connection
podman context use -> podman system connection default
podman context rm -> podman system connection rm
podman context create -> podman system connection add
podman context ls ->podman system connection ls
podman context inspect ->podman system connection ls --json (For
specified connections)

Podman context is a hidden command, but can be used for existing scripts
that assume Docker under the covers.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-15 08:17:15 -04:00
Daniel J Walsh 2c63b8439b
Fix stutters
Podman adds an Error: to every error message.  So starting an error
message with "error" ends up being reported to the user as

Error: error ...

This patch removes the stutter.

Also ioutil.ReadFile errors report the Path, so wrapping the err message
with the path causes a stutter.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-09-10 07:52:00 -04:00
Daniel J Walsh ab72a371bb
Don't warn on '/' not being shared while in a container
Fixes: https://github.com/containers/podman/issues/15295

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-08-15 10:28:29 -04:00
Sascha Grunert a46f798831
pkg: switch to golang native error wrapping
We now use the golang error wrapping format specifier `%w` instead of
the deprecated github.com/pkg/errors package.

[NO NEW TESTS NEEDED]

Signed-off-by: Sascha Grunert <sgrunert@redhat.com>
2022-07-08 08:54:47 +02:00
Erik Sjölund aa4279ae15 Fix spelling "setup" -> "set up" and similar
* Replace "setup", "lookup", "cleanup", "backup" with
  "set up", "look up", "clean up", "back up"
  when used as verbs. Replace also variations of those.

* Improve language in a few places.

Signed-off-by: Erik Sjölund <erik.sjolund@gmail.com>
2022-06-22 18:39:21 +02:00
Giuseppe Scrivano ecf225019a
rootless: attempt to join all specified paths
when there are multiple paths specified, attempt to join them all
before returning an error.  Previously we were failing on the first
pid found.

[NO NEW TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-06-21 15:50:52 +02:00
Giuseppe Scrivano 9afd5e31c8
rootless: improve error messages
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-06-21 15:50:52 +02:00
Giuseppe Scrivano 99258703a7
rootless: do not ignore reexec_in_user_namespace_wait errors
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-06-21 15:49:05 +02:00
Paul Holzinger 41528739ce
golangci-lint: enable nolintlint
The nolintlint linter does not deny the use of `//nolint`
Instead it allows us to enforce a common nolint style:
- force that a linter name must be specified
- do not add a space between `//` and `nolint`
- make sure nolint is only used when there is actually a problem

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-06-14 16:29:42 +02:00
Valentin Rothberg c090931da4 remote: do not join user NS
As noticed while debugging #13992, do not join the rootless user NS as a
Linux remote client.

[NO NEW TESTS NEEDED] as existing tests should continue to work.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-04-26 15:05:20 +02:00
Daniel J Walsh 2508913a0f
If newuidmap or newgidmap fail, then check their permissions
Often distributions to not have newuidmap and netgidmap configured
to be setuid. If Podman fails to setup the user namespace, check to
see if these files doe not have the proper protection and tell the user.

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-04-08 10:52:08 -04:00
Daniel J Walsh 7680211ede
Remove error stutter
When podman gets an error it prints out "Error: " before
printing the error string.  If the error message starts with
error, we end up with

Error: error ...

This PR Removes all of these stutters.

logrus.Error() also prints out that this is an error, so no need for the
error stutter.

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2022-03-25 21:47:04 -04:00
Valentin Rothberg 06dd9136a2 fix a number of errcheck issues
Numerous issues remain, especially in tests/e2e.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-22 13:15:28 +01:00