Commit Graph

104 Commits

Author SHA1 Message Date
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
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
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 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
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
Giuseppe Scrivano 5dad34212f
rootless: add argument to GetConfiguredMappings
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-10-28 14:26:07 +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 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
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 ea08765f40 go fmt: use go 1.18 conditional-build syntax
Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-18 09:11:53 +01:00
Giuseppe Scrivano 7046e78040
rootless: report correctly the error
`err` is nil at this point, so errors.Wrapf() would return nil
ignoring the remaining arguments.  This would prevent SetupRootless()
to fail causing podman to run without capabilities but believing so,
and it would end up in a crash when accessing the local store.

Closes: https://github.com/containers/podman/discussions/12923

[NO NEW TESTS NEEDED] it requires running in the environment created
by bazel linux-sandbox.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2022-01-19 21:14:33 +01:00
Valentin Rothberg bd09b7aa79 bump go module to version 4
Automated for .go files via gomove [1]:
`gomove github.com/containers/podman/v3 github.com/containers/podman/v4`

Remaining files via vgrep [2]:
`vgrep github.com/containers/podman/v3`

[1] https://github.com/KSubedi/gomove
[2] https://github.com/vrothberg/vgrep

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2022-01-18 12:47:07 +01:00
Giuseppe Scrivano a837984c46
rootless: include the args in the debug message
include the arguments used to create the user namespace to help
debugging.

[NO NEW TESTS NEEDED] it changes a debug message

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-12-17 14:47:18 +01:00
Giuseppe Scrivano 9877280f5a
rootless: adjust error message
since we now support reading additional IDs with libsubid, clarify
that the /etc/subuid and /etc/subgid files are honored only when
shadow-utils is configured to use them.

[NO TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-10 09:26:22 +01:00
Daniel J Walsh 1c4e6d8624
standardize logrus messages to upper case
Remove ERROR: Error stutter from logrus messages also.

[ NO TESTS NEEDED] This is just code cleanup.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-09-22 15:29:34 -04:00
Valentin Rothberg fe2be7f886 make sure that signal buffers are sufficiently big
Dealing with os.Signal channels seems more like an art than science
since signals may get lost.  os.Notify doesn't block on an unbuffered
channel, so users are expected to know what they're doing or hope for
the best.

In the recent past, I've seen a number of flakes and BZs on non-amd64
architectures where I was under the impression that signals may got
lost, for instance, during stop and exec.

[NO TESTS NEEDED] since this is art.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-08-17 12:10:20 +02:00
Giuseppe Scrivano 67d439197e
rootless: check that / is mounted as shared
if the root mount '/' is not mounted as MS_SHARED, print a
warning, otherwise new mounts that are created in the host won't be
propagated to the rootless mount namespace.

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

[NO TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-07-28 11:04:36 +02:00
Giuseppe Scrivano 493786fbae
podman: ignore ESRCH from kill
Closes: https://github.com/containers/podman/issues/10826

[NO TESTS NEEDED] Fixes a race condition

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-07-01 17:01:54 +02:00
Andrej Shadura 09e640d1b5
rootless: Tell the user what was led to the error, not just what it is
Users coming e.g. from Docker do not always read the manual and
expect podman to not require sudo or uidmap, for them the default
message is not very helpful:

    Error: Cannot connect to the Podman socket, make sure there is a Podman REST API service running.:
    cannot find newuidmap: exec: "newuidmap": executable file not found in $PATH

Adding a bit more context to this would help to nudge them into the
right direction and tell them what to look for in the documentation:

    command required for rootless mode with multiple IDs: exec: "newuidmap": executable file not found in $PATH

Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>

[NO TESTS NEEDED]
2021-04-27 11:20:43 +02:00
Giuseppe Scrivano e4c269e2d0
rootless: attempt to copy current mappings first
when creating a user namespace, attempt to create it first by copying
the current mappings and then fallback to the other methods:

1) use newidmap tools and ...
2) create a user namespace with a single user mapped.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-04-26 08:58:54 +02:00
Giuseppe Scrivano 24f00e4695
rootless: if root is not sub?id raise a debug message
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-04-22 15:32:36 +02:00
Valentin Rothberg 5dded6fae7 bump go module to v3
We missed bumping the go module, so let's do it now :)

* Automated go code with github.com/sirkon/go-imports-rename
* Manually via `vgrep podman/v2` the rest

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-22 09:03:51 +01:00
Josh Soref 4fa1fce930 Spelling
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-12-22 13:34:31 -05:00
Kir Kolyshkin 4878dff3e2 Remove excessive error wrapping
In case os.Open[File], os.Mkdir[All], ioutil.ReadFile and the like
fails, the error message already contains the file name and the
operation that fails, so there is no need to wrap the error with
something like "open %s failed".

While at it

 - replace a few places with os.Open, ioutil.ReadAll with
   ioutil.ReadFile.

 - replace errors.Wrapf with errors.Wrap for cases where there
   are no %-style arguments.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-10-05 15:30:37 -07:00
Giuseppe Scrivano 7147c935aa
rootless: fix hang when newidmap is not installed
when newidmap is not installed the code would hit the
reexec_in_user_namespace_wait code and wait for the child process to
be terminated.  The child process is blocked waiting on the w pipe.

So make sure to unblock the child process first and then clean it up.

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

Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
2020-09-25 18:08:46 +02:00
Jonathan Dieter 0cd2f2d974 Wait for reexec to finish when fileOutput is nil
Currently, we're not cleanup up after ourselves when fileOutput is nil.
This patch fixes that.

Signed-off-by: Jonathan Dieter <jonathan.dieter@spearline.com>
2020-08-15 16:34:58 +01:00
Jonathan Dieter ec231973d8 Fix hang when `path` doesn't exist
I'm not sure if this is an OS-specific issue, but on CentOS 8, if `path`
doesn't exist, this hangs while waiting to read from this socket, even
though the socket is closed by the `reexec_in_user_namespace`.  Switching
to a pipe fixes the problem, and pipes shouldn't be an issue since this is
Linux-specific code.

Signed-off-by: Jonathan Dieter <jonathan.dieter@spearline.com>
2020-08-11 16:42:39 +01:00
Qi Wang 34e82f81bd validate fds --preserve-fds
validate file descriptors passed from podman run and podman exec --preserve-fds.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-08-04 15:09:17 -04:00
Giuseppe Scrivano d188b2fe22
rootless: add a check for the host id included in the range
add a check to verify whether the additional IDs also contain the host
ID.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-30 23:16:50 +02:00
Giuseppe Scrivano d86ef45441
rootless: child exits immediately on userns errors
if the parent process failed to create the user namespace, let the
child exit immediately.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-30 21:46:04 +02:00
Giuseppe Scrivano 8408cfd35c
rootless: do not ignore errors if mappings are specified
when setting up the user namespace do not ignore errors from
newuidmap/newgidmap if there are mappings configured.

The single user mapping is a fallback only when there are not mappings
specified for the user.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-30 21:43:09 +02:00
Daniel J Walsh a5e37ad280
Switch all references to github.com/containers/libpod -> podman
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-28 08:23:45 -04:00
Valentin Rothberg 8489dc4345 move go module to v2
With the advent of Podman 2.0.0 we crossed the magical barrier of go
modules.  While we were able to continue importing all packages inside
of the project, the project could not be vendored anymore from the
outside.

Move the go module to new major version and change all imports to
`github.com/containers/libpod/v2`.  The renaming of the imports
was done via `gomove` [1].

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

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-06 15:50:12 +02:00
Douglas Schilling Landgraf 11e237bc3a rootless_linux: improve error message
Improve the error message for rootless mode.

Git-Url: https://github.com/containers/libpod/issues/6572
Signed-off-by: Douglas Schilling Landgraf <dougsland@redhat.com>
2020-06-21 06:35:25 -04:00
Giuseppe Scrivano 788fdc685b
rootless: move join namespace inside child process
open the namespace file descriptors inside of the child process.

Closes: https://github.com/containers/libpod/issues/5873

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-04-20 17:40:25 +02:00
Giuseppe Scrivano 8360fcf82c
rootless: skip looking up parent user ns
since we join directly the conmon user namespace, there is no need to
look up its parent user namespace, as we can safely assume it is the
init namespace.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-04-20 17:40:24 +02:00
Giuseppe Scrivano 6dbb89e56c
rootless: become root only if the pause file is specified
we need to store the pause process PID file so that it can be re-used
later.

commit e9dc212092 introduced this
regression.

Closes: https://github.com/containers/libpod/issues/5246

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-02-25 18:15:29 +01:00