Commit graph

44 commits

Author SHA1 Message Date
Giuseppe Scrivano e6a4bac09e
rootless: use Geteuid instead of Getuid
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-15 10:39:23 +01:00
baude c8ca027938 Add gating tasks
to protect against regressions, we need to add a few gating tasks:
 * build with varlink
 * build podman-remote
 * build podman-remote-darwin

we already have a gating task for building without varlink

Signed-off-by: baude <bbaude@redhat.com>
2019-03-13 12:10:35 -05:00
OpenShift Merge Robot 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
Giuseppe Scrivano af3e73426a
rootless: allow single mappings
we were playing safe and not allowed any container to have less than
65536 mappings.  There are a couple of reasons to change it:

- it blocked libpod to work in an environment where
  newuidmap/newgidmap are not available, or not configured.

- not allowed to use different partitions of subuids, where each user
  has less than 65536 ids available.

Hopefully this change in containers/storage:

https://github.com/containers/storage/pull/303

will make error clearers if there are not enough IDs for the image
that is being used.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-11 14:38:42 +01:00
Giuseppe Scrivano f31ba2929b
rootless: support a custom arg to the new process
let the process running as euid != 0 pass down an argument to the
process running in the user namespace.  This will be useful for
commands like rm -a that needs to join different namespaces, so that
we can re-exec separately for each of them.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-11 11:48:25 +01:00
Giuseppe Scrivano cc411dd98f
rootless: propagate errors from info
we use "podman info" to reconfigure the runtime after a reboot, but we
don't propagate the error message back if something goes wrong.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-08 19:42:20 +01:00
OpenShift Merge Robot 7418ff988b
Merge pull request #2543 from giuseppe/fix-rootless-s390x-cris
rootless: fix clone syscall on s390 and cris archs
2019-03-06 05:48:27 -08:00
Giuseppe Scrivano ca5114faf9
rootless: fix clone syscall on s390 and cris archs
from the clone man page:

  On the cris and s390 architectures, the order of the first two
  arguments is reversed:

           long clone(void *child_stack, unsigned long flags,
                      int *ptid, int *ctid,
                      unsigned long newtls);

Closes: https://bugzilla.redhat.com/show_bug.cgi?id=1672714

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-05 17:27:43 +01:00
Giuseppe Scrivano 0b34327ad4
exec: support --preserve-fds
Allow to pass additional FDs to the process being executed.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-03-02 11:45:42 +01:00
Giuseppe Scrivano 23615099e9
rootless, new[ug]idmap: on failure add output
if any of the mapping tools for setting up the user namespace fail,
then include their output in the error message.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-02-28 16:16:48 +01:00
Giuseppe Scrivano 8984ba7461
rootless: force same cwd when re-execing
when joining an existing namespace, we were not maintaining the
current working directory, causing commands like export -o to fail
when they weren't referring to absolute paths.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-02-22 23:55:21 +01:00
Harald Hoyer 3f60dc02e3
Adjust LISTEN_PID for reexec in varlink mode
Because the varlink server honors the socket activation protocol,
LISTEN_PID has to be adjusted with the new PID.

https://varlink.org/FAQ.html#how-does-socket-activation-work
Signed-off-by: Harald Hoyer <harald@redhat.com>
2019-02-21 10:25:57 +01:00
Daniel J Walsh 0abb757425
Cleanup coverity scan issues
If realloc fails, then buffer will be leaked, this change frees up the buffer.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-01-15 17:09:15 -05:00
baude 43c6da22b9 Add darwin support for remote-client
Add the ability to cross-compile podman remote for OSX.

Also, add image exists and tag to remote-client.

Signed-off-by: baude <bbaude@redhat.com>
2019-01-11 11:30:28 -06:00
Giuseppe Scrivano f2e96b0934
rootless: add function to join user and mount namespace
Add the possibility to join directly the user and mount namespace
without looking up the parent of the user namespace.

We need this in order to be able the conmon process, as the mount
namespace is kept alive only there.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-12-21 09:46:05 +01:00
Giuseppe Scrivano 727b6a78ee
rootless: raise error if newuidmap/newgidmap are not installed
it was reported on IRC that Podman on Ubuntu failed as
newuidmap/newgidmap were not installed by default.

Raise an error if we are not allowing single mappings (used only by
the tests suite) and any of the binaries is not present.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-12-03 16:45:44 +01:00
Giuseppe Scrivano 1e3ff69502
rootless: call IsRootless just once
we are calling this function several times, it is worth to store its
result and re-use it.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-11-14 10:13:50 +01:00
Daniel J Walsh 542d8fe95f
Better document rootless containers
Need to return an error pointing user in right direction if rootless podman
fails, because of no /etc/subuid or /etc/subgid files.

Also fix up man pages to better describe rootless podman.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-11-10 04:46:06 -05:00
Giuseppe Scrivano 55c9b03baf
rootless: detect when user namespaces are not enabled
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-10-11 17:49:16 +02:00
Giuseppe Scrivano 2933c3b980
rootless: report more error messages from the startup phase
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-10-11 17:09:19 +02:00
Giuseppe Scrivano 48f6f9254d
rootless: fix an hang on older versions of setresuid/setresgid
the issue is caused by the Go Runtime that messes up with the process
signals, overriding SIGSETXID and SIGCANCEL which are used internally
by glibc.  They are used to inform all the threads to update their
stored uid/gid information.  This causes a hang on the set*id glibc
wrappers since the handler installed by glibc is never invoked.

Since we are running with only one thread, we don't really need to
update other threads or even the current thread as we are not using
getuid/getgid before the execvp.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-10-11 17:09:18 +02:00
Giuseppe Scrivano 4f42fe2e9e rootless: error out if there are not enough UIDs/GIDs available
Most container images assume there are at least 65536 UIDs/GIDs
available.  Raise an error if there are not enough IDs allocated to
the current user.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1520
Approved by: rhatdan
2018-09-21 14:34:58 +00:00
Giuseppe Scrivano 37b2601a81 rootless: skip usage of filepath.Join
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1507
Approved by: rhatdan
2018-09-21 10:13:39 +00:00
Giuseppe Scrivano 6d1eecf7cf create, rootless: join the userns of ns:PATH
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1507
Approved by: rhatdan
2018-09-21 10:13:39 +00:00
Giuseppe Scrivano 807f6f8d8f rootless: check uid with Geteuid() instead of Getuid()
change the tests to use chroot to set a numeric UID/GID.

Go syscall.Credential doesn't change the effective UID/GID of the
process.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1372
Approved by: mheon
2018-09-04 14:36:57 +00:00
Giuseppe Scrivano 86aefb5de2 rootless: unexport GetUserNSForPid
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1371
Approved by: rhatdan
2018-08-29 16:25:20 +00:00
Giuseppe Scrivano 1789242933 rootless: add new function to join existing namespace
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1371
Approved by: rhatdan
2018-08-29 16:25:20 +00:00
Giuseppe Scrivano c5753f57c1 rootless: exec handle processes that create an user namespace
Manage the case where the main process of the container creates and
joins a new user namespace.

In this case we want to join only the first child in the new
hierarchy, which is the user namespace that was used to create the
container.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1331
Approved by: rhatdan
2018-08-26 07:22:42 +00:00
Giuseppe Scrivano 720eb85ba5 rootless: fix exec
We cannot re-exec into a new user namespace to gain privileges and
access an existing as the new namespace is not the owner of the
existing container.

"unshare" is used to join the user namespace of the target container.

The current implementation assumes that the main process of the
container didn't create a new user namespace.

Since in the setup phase we are not running with euid=0, we must skip
the setup for containers/storage.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1331
Approved by: rhatdan
2018-08-26 07:22:42 +00:00
Giuseppe Scrivano 9e06478d83 rootless: fix user lookup if USER= is not set
Lookup the current username by UID if the USER env variable is not
set.

Reported in: https://github.com/projectatomic/libpod/issues/1092

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1217
Approved by: rhatdan
2018-08-08 09:27:27 +00:00
Anders F Björklund 71af51e723 Check for missing arguments in /proc/self/cmdline
Closes: #1206
Approved by: giuseppe
2018-08-03 07:39:25 +00:00
Giuseppe Scrivano 13b1845214 rootless: do not set setgroups to deny when using newuidmap
It is required only when directly configuring the user namespace.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1200
Approved by: rhatdan
2018-08-02 18:49:55 +00:00
Giuseppe Scrivano c7b6403ae5
rootless: do not segfault if the parent already died
Closes: https://github.com/projectatomic/libpod/issues/1189

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-08-02 14:29:50 +02:00
Giuseppe Scrivano 6372c977ea rootless: require subids to be present
Most images won't work without multiple ids/gids.  Error out
immediately if there are no multiple ids available.

The error code when the user is not present in /etc/sub{g,u}id looks
like:

$ bin/podman run --rm -ti alpine echo hello
ERRO[0000] No subuid ranges found for user "gscrivano"

Closes: https://github.com/projectatomic/libpod/issues/1087

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1097
Approved by: rhatdan
2018-07-16 13:40:40 +00:00
Daniel J Walsh 14a6d51a84
Merge pull request #1091 from giuseppe/rootless-unshare-mount-ns
rootless: unshare mount namespace
2018-07-13 14:16:24 -04:00
Giuseppe Scrivano 62e48e5b71
rootless: correctly propagate the exit status from the container
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-07-13 16:41:11 +02:00
Giuseppe Scrivano 6ffcb98a70
rootless: unshare mount namespace
unshare the mount namespace as well when creating an user namespace so
that we are the owner of the mount namespace and we can mount FUSE
file systems on Linux 4.18.  Tested on Fedora Rawhide:

podman --storage-opt overlay.fuse_program=/usr/bin/fuse-overlayfs run alpine echo hello
hello

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-07-13 16:37:37 +02:00
Giuseppe Scrivano 84cfdb2061 rootless: fix when argv[0] is not an absolute path
use execvp instead of exec so that we keep the PATH environment
variable and the lookup for the "podman" executable works.

Closes: https://github.com/projectatomic/libpod/issues/1070

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1072
Approved by: mheon
2018-07-10 16:13:43 +00:00
W. Trevor King 83968de28c rootless: Merge rootless.go back into rootless_linux.go
The files were split apart by b96be3af (changes to allow for darwin
compilation, 2018-06-20, #1015), but the C import and two functions
left in rootless.go are all Linux-specific as well.  This commit moves
all of the pre-b96be3af rootless.go into rootless_linux.go, just
adding the '// +build linux' header (b96be3af also scrambled the + in
that header) and keeping the new GetRootlessUID from a1545fe6
(rootless: add function to retrieve the original UID, 2018-07-05, #1048).

Signed-off-by: W. Trevor King <wking@tremily.us>

Closes: #1034
Approved by: baude
2018-07-06 00:48:39 +00:00
baude cc6f0e85f9 more changes to compile darwin
this should represent the last major changes to get darwin to **compile**.  again,
the purpose here is to get darwin to compile so that we can eventually implement a
ci task that would protect against regressions for darwin compilation.

i have left the manual darwin compilation largely static still and in fact now only
interject (manually) two build tags to assist with the build.  trevor king has great
ideas on how to make this better and i will defer final implementation of those
to him.

Signed-off-by: baude <bbaude@redhat.com>

Closes: #1047
Approved by: rhatdan
2018-07-05 16:05:12 +00:00
Giuseppe Scrivano a1545fe6e4 rootless: add function to retrieve the original UID
After we re-exec in the userNS os.Getuid() returns the new UID (= 0)
which is not what we want to use.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1048
Approved by: mheon
2018-07-05 13:30:15 +00:00
baude b96be3af1b changes to allow for darwin compilation
Signed-off-by: baude <bbaude@redhat.com>

Closes: #1015
Approved by: baude
2018-06-29 20:44:09 +00:00
Giuseppe Scrivano 20862c9746 rootless: do not configure additional groups
Additional groups are not allowed in an userNS.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #936
Approved by: rhatdan
2018-06-27 14:07:17 +00:00
Giuseppe Scrivano 5ff90677c8 rootless: add management for the userNS
When running podman as non root user always create an userNS and let
the OCI runtime use it.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #936
Approved by: rhatdan
2018-06-27 14:07:17 +00:00