Commit Graph

191 Commits

Author SHA1 Message Date
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
Valentin Rothberg 0f12b6fe55 linter: enable nilerr
A number of cases looked suspicious, so I marked them with `FIXME`s to
leave some breadcrumbs.

Signed-off-by: Valentin Rothberg <vrothberg@redhat.com>
2022-03-22 13:04:35 +01: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
OpenShift Merge Robot cbb2b68fc9
Merge pull request #12429 from cdoern/scp
podman image scp never enter podman user NS
2022-01-05 17:50:37 +01:00
cdoern f6d00ea6ef podman image scp never enter podman user NS
Podman image scp should never enter the Podman UserNS unless it needs to. This allows for
a sudo exec.Command to transfer images to and from rootful storage. If this command is run using sudo,
the simple sudo podman save/load does not work, machinectl/su is necessary here.

This modification allows for both rootful and rootless transfers, and an overall change of scp to be
more of a wrapper function for different load and save calls as well as the ssh component

Signed-off-by: cdoern <cdoern@redhat.com>
2021-12-23 10:10:51 -05: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
Marc Nguyen 1d781ccbea
[NO NEW TESTS NEEDED] rootless: declare TEMP_FAILURE_RETRY before usage (Fixes: #12563)
Signed-off-by: Nguyen Marc <nguyen_marc@live.fr>
2021-12-10 14:20:35 +01:00
OpenShift Merge Robot 878d22e831
Merge pull request #12325 from giuseppe/rootless-use-auto-cleanup
rootless: use auto cleanup functions
2021-11-17 20:20:29 +01:00
Giuseppe Scrivano 3073543fd9
rootless: use catatonit to maintain user+mnt namespace
if catatonit is present, use it to keep the rootless user+mnt
namespace alive.

[NO NEW TESTS NEEDED] no new features added.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-17 12:30:33 +01:00
Giuseppe Scrivano cb9de1007c
rootless: drop strerror(errno) calls
*printf functions already support printing the errno string with %m

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-17 10:57:44 +01:00
Giuseppe Scrivano 084e32336a
rootless: reuse existing open_namespace function
there is already a function for opening a namespace path, reuse it.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-17 10:57:44 +01:00
Giuseppe Scrivano 277d526869
rootless: use auto cleanup functions
simplify code using auto cleanup functions

[NO NEW TESTS NEEDED] it is a refactoring of existing code

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-17 10:57:44 +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
Paul Holzinger c668ca8597
podman machine: do not join userns
The go logic already prevents podman from joining the userns for machine
commands but the c shortcut code did not.

[NO TESTS NEEDED]

Fixes #11731

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-09-27 10:18:23 +02: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 724d048234
rootless: avoid zombie process on first launch
avoid a zombie process if on the first launch Podman creates a long
living process, such as "podman system service -t 0".

The `r` variable was overriden thus causing the waitpid to fail and
not clean up the intermediate process.

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

[NO TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-07-29 11:07:17 +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