74 Commits

Author SHA1 Message Date
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
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
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
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
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
4fa1fce930 Spelling
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-12-22 13:34:31 -05:00
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
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
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
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
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
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
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
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
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
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
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
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
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
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 e9dc2120925d9bc32b87ed3c4122aa40f7413db5 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
e9dc212092 rootless: check if the conmon process is valid
if the pause process doesn't exist and  we try to join a conmon
namespace, make sure the process still exists.  Otherwise re-create
the user namespace.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-02-17 19:11:41 +01:00
83764b84ec fix lint in pkg/rootless
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-08 15:44:30 +01:00
64f53b4f02 rootless: do not enable lingering mode
do not automatically enable lingering mode.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-17 19:12:10 +02:00
550ff9d49a rootless: drop dependency on docker
use the definition from "golang.org/x/sys/unix".

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-16 22:22:52 +02:00
3fff42e0ab show uid_map in podman info
show uid_map gid_map in podman info

Signed-off-by: Qi Wang <qiwan@redhat.com>
2019-10-09 21:27:18 -04:00
9a61b765d0 rootless: do not close files twice
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-10-09 15:49:12 +02:00
62c0b387f5 Set log-level immediately, before rootless setup
If we don't do this, we print WARN level messages that we should
not be printing by default.

Up one WARN message to ERROR so it still shows up by default.

Fixes: #4115
Fixes: #4012

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-09-26 16:14:57 -04:00
1a24ac7ad6 pkg/util: use rootless function to read additional users
make pkg/rootless.GetConfiguredMappings public so that it can be used
from pkg/util.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-09-03 14:38:08 +02:00
cfe1d27688 rootless: detect user namespace configuration changes
detect if the current user namespace doesn't match the configuration
in the /etc/subuid and /etc/subgid files.

If there is a mismatch, raise a warning and suggest the user to
recreate the user namespace with "system migrate", that also restarts
the containers.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-09-03 13:46:48 +02:00
db826d5d75 golangci-lint round #3
this is the third round of preparing to use the golangci-lint on our
code base.

Signed-off-by: baude <bbaude@redhat.com>
2019-07-21 14:22:39 -05:00
a78c885397 golangci-lint pass number 2
clean up and prepare to migrate to the golangci-linter

Signed-off-by: baude <bbaude@redhat.com>
2019-07-11 09:13:06 -05:00
e053e0e05e first pass of corrections for golangci-lint
Signed-off-by: baude <bbaude@redhat.com>
2019-07-10 15:52:17 -05:00
fec1de6ef4 trivial cleanups from golang
the results of a code cleanup performed by the goland IDE.

Signed-off-by: baude <bbaude@redhat.com>
2019-07-03 15:41:33 -05:00
35ab2184a3 rootless: allow to build without cgo
unfortunately rootless won't work without cgo, as most of the
implementation is in C, but at least allow to build libpod.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-07-02 16:41:02 +02:00
7255468e65 rootless: enable linger if /run/user/UID not exists
at least on Fedora 30 it creates the /run/user/UID directory for the
user logged in via ssh.

This needs to be done very early so that every other check when we
create the default configuration file will point to the correct
location.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-06-27 16:34:35 +02:00
4bfbc355de Build cgo files with -Wall -Werror
To avoid unnecessary warnings and errors in the future I'd like to
propose building all cgo related sources with `-Wall -Werror`. This
commit fixes some warnings which came up in `shm_lock.c`, too.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2019-06-21 10:14:19 +02:00
8d2c7c269d Fix cgo includes for musl
closes #3284

Signed-off-by: Cameron Nemo <cnemo@tutanota.com>
2019-06-08 14:15:03 -07:00
4dca13e704 rootless: skip NS_GET_PARENT on old kernels
on old kernels the ioctl NS_GET_PARENT is not available.

Handle the error code and immediately return the same fd.  It should
be fine now that we use the namespace resolution using the conmon pid,
so the namespace parent resolution is just a safety measure.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-06-06 15:32:45 +02:00
153503e391 rootless: make JoinUserAndMountNS private
as it is used only by the rootless package now.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-05-25 13:48:00 +02:00
30ef6ba125 rootless: enable loginctl linger
otherwise the processes we leave around will be killed once the
session terminates.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-05-25 13:47:58 +02:00
ee11f3bce9 rootless: new function to join existing conmon processes
move the logic for joining existing namespaces down to the rootless
package.  In main_local we still retrieve the list of conmon pid files
and use it from the rootless package.

In addition, create a temporary user namespace for reading these
files, as the unprivileged user might not have enough privileges for
reading the conmon pid file, for example when running with a different
uidmap and root in the container is different than the rootless user.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-05-25 13:47:57 +02:00
6df320c391 rootless: store also the original GID in the host
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-05-23 22:41:48 +02:00
562357ebb2 rootless: join namespace immediately when possible
add a shortcut for joining immediately the namespace so we don't need
to re-exec Podman.

With the pause process simplificaton, we can now attempt to join the
namespaces as soon as Podman starts (and before the Go runtime kicks
in), so that we don't need to re-exec and use just one process.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-05-17 20:48:24 +02:00
791d53a214 rootless: use a pause process
use a pause process to keep the user and mount namespace alive.

The pause process is created immediately on reload, and all successive
Podman processes will refer to it for joining the user&mount
namespace.

This solves all the race conditions we had on joining the correct
namespaces using the conmon processes.

As a fallback if the join fails for any reason (e.g. the pause process
was killed), then we try to join the running containers as we were
doing before.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-05-17 20:48:24 +02:00
814066ee3b rootless: do not block SIGTSTP
we were previously proxying all the signals, but doing that for
SIGTSTP prevented the main process to be stopped by the tty.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-12 18:20:40 +02:00
72382a12a7 rootless: use a single user namespace
simplify the rootless implementation to use a single user namespace
for all the running containers.

This makes the rootless implementation behave more like root Podman,
where each container is created in the host environment.

There are multiple advantages to it: 1) much simpler implementation as
there is only one namespace to join.  2) we can join namespaces owned
by different containers.  3) commands like ps won't be limited to what
container they can access as previously we either had access to the
storage from a new namespace or access to /proc when running from the
host.  4) rootless varlink works.  5) there are only two ways to enter
in a namespace, either by creating a new one if no containers are
running or joining the existing one from any container.

Containers created by older Podman versions must be restarted.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-01 15:32:58 +02:00
ed326206f2 rootless: remove SkipStorageSetup()
in the few places where we care about skipping the storage
initialization, we can simply use the process effective UID, instead
of relying on a global boolean flag.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-04-01 13:24:04 +02:00
ce0ca0d459 rootless: change env prefix
from _LIBPOD to _CONTAINERS.  The same change was done in buildah
unshare.

This is necessary for podman to detect we are running in a rootless
environment and work properly from a "buildah unshare" session.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-28 17:08:20 +01:00
e6a4bac09e rootless: use Geteuid instead of Getuid
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-15 10:39:23 +01:00
6421208e0f Merge pull request #2583 from giuseppe/rootless-fix-pod-rm
rootless: fix stop and rm when the container is running with uid != 0
2019-03-11 10:01:25 -07:00