Commit Graph

87 Commits

Author SHA1 Message Date
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
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 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
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
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
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
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
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
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
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 11badab046
rootless: fix fast join userns path
commit ab88632835 changed the path for
the pause.pid file but didn't update the same path in the C code.
This prevented Podman to take the fast path when the userns is already
created and to join it without re-execing itself.

Fix the path in the C code as well so we can join the rootless
user+mount namespace without having to re-exec Podman.

[NO TESTS NEEDED]

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-06-09 15:30:41 +02:00
flouthoc 2addc0f90d rootless: fix SIGSEGV ,make LISTEN_FDNAMES optional [Closes #10435].
[NO TESTS NEEDED]

Signed-off-by: flouthoc <flouthoc.git@gmail.com>
2021-05-29 15:16:26 +05:30
pendulm 11917a1a6b Move socket activation check into init() and set global condition.
So rootless setup could use this condition in parent and child, child
podman should adjust LISTEN_PID to its self PID.

Add system test for systemd socket activation

Signed-off-by: pendulm <lonependulm@gmail.com>
2021-04-05 17:43:11 +08:00
Giuseppe Scrivano 2446bdc7bb
rootless: use is_fd_inherited
since we already have an exported function that does the check,
refactor the code to use it instead of duplicating the logic.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-03-29 11:44:43 +02:00
Jonas Schievink 43a581904f Log working dir when chdir fails
Signed-off-by: Jonas Schievink <jonasschievink@gmail.com>
2021-02-19 17:04:38 +01:00
Jakub Guzik e1ad50654c leak fix in rootless_linux.c fcn can_use_shortcut
Signed-off-by: Jakub Guzik <jakubmguzik@gmail.com>
2021-02-19 11:20:35 +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 8df7ab24b0
rootless: system service joins immediately the namespaces
when there is a pause process running, let the "system service" podman
instance join immediately the existing namespaces.

Closes: https://github.com/containers/podman/issues/7180
Closes: https://github.com/containers/podman/issues/6660

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-08-03 22:08:17 +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
Daniel J Walsh 6979d140f1
Add podman image mount
There are many use cases where you want to just mount an image
without creating a container on it. For example you might want
to just examine the content in an image after you pull it for
security analysys.  Or you might want to just use the executables
on the image without running it in a container.

The image is mounted readonly since we do not want people changing
images.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-28 10:27:44 -04:00
Daniel J Walsh 8f7ed50cb2
Cleanup handling of podman mount/unmount
We should default to the user name unmount rather then the internal
name of umount.

Also User namespace was not being handled correctly. We want to inform
the user that if they do a mount when in rootless mode that they have
to be first in the podman unshare state.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-27 16:53:02 -04:00
Giuseppe Scrivano 89d4940a37
rootless: move ns open before fork
commit 788fdc685b introduced a race
where the target process dies before the child process opens the
namespace files.  Move the open before the fork so if it fails the
parent process can attempt to join a different container instead of
failing.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-04-29 11:44:24 +02: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 c33371fadb
rootless: use snprintf
use directly snprintf instead of strlen+strcpy.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-04-13 13:35:38 +02:00
Giuseppe Scrivano 1091440e5d
rootless: fix usage with hidepid=1
when /proc is mounted with hidepid=1 a process doesn't see processes
from the outer user namespace.  This causes an issue reading the
cmdline from the parent process.

To address it, always read the command line from /proc/self instead of
using /proc/PARENT_PID.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-19 11:18:23 +01:00
Giuseppe Scrivano d400f0b5b2
rootless: fix segfault when open fd >= FD_SETSIZE
if there are more than FD_SETSIZE open fds passed down to the Podman
process, the initialization code could crash as it attempts to store
them into a fd_set.  Use an array of fd_set structs, each of them
holding only FD_SETSIZE file descriptors.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-02-25 17:52:06 +01:00
Giuseppe Scrivano 1d9537e242 rootless: enable shortcut only for podman
disable joining automatically the user namespace if the process is not
podman.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-01-29 16:16:36 -06:00
Giuseppe Scrivano ab7744d3c1
rootless: set C variables also on shortcut
make sure the rootless env variables are set also when we are joining
directly the user+mount namespace without creating a new process.

It is required by pkg/unshare in containers/common.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-01-20 16:42:45 +01:00
Giuseppe Scrivano a94e625868
rootless: add fallback for renameat2 at runtime
the renameat2 syscall might be defined in the C library but lacking
support in the kernel.

In such case, let it fallback to open(O_CREAT)+rename as it does on
systems lacking the definition for renameat2.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-12-04 10:30:40 +01:00
Giuseppe Scrivano 0a8dcd7112
rootless: provide workaround for missing renameat2
on RHEL 7.7 renameat2 is not implemented for s390x, provide a
workaround.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-11-06 15:27:46 +01:00
Giuseppe Scrivano a114e9059a
rootless: use SYS_renameat2 instead of __NR_renameat2
use the correct definition for the syscall number.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-11-06 13:41:15 +01:00
OpenShift Merge Robot 146719718e
Merge pull request #3782 from eriksjolund/fix_realloc_in_rootless_linux.c
Fix incorrect use of realloc()
2019-08-11 19:44:58 +02:00
Erik Sjölund 39ce3626e0
Adjust read count so that a newline can be added afterwards
Signed-off-by: Erik Sjölund <erik.sjolund@gmail.com>
2019-08-11 16:44:26 +02:00
Erik Sjölund 4d3cf9b576
Fix incorrect use of realloc()
Signed-off-by: Erik Sjölund <erik.sjolund@gmail.com>
2019-08-11 15:58:20 +02:00
Daniel J Walsh 44126969f1
Fix a couple of errors descovered by coverity
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-08-09 15:33:16 -04:00
Giuseppe Scrivano 4b176d4f45
rootless: do not join namespace if it has already euid == 0
do not attempt to join the rootless namespace if it is running already
with euid == 0.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-07-01 21:58:33 +02:00
Danila Kiver 7ea7754e4a Exclude SIGTERM from blocked signals for pause process.
Currently pause process blocks all signals which may cause its
termination, including SIGTERM. This behavior hangs init(1) during
system shutdown, until pause process gets SIGKILLed after some grace
period. To avoid this hanging, SIGTERM is excluded from list of blocked
signals.

Fixes #3440

Signed-off-by: Danila Kiver <danila.kiver@mail.ru>
2019-06-28 00:18:13 +03:00
OpenShift Merge Robot f446ccf0b0
Merge pull request #3379 from openSUSE/rootless-fix
Fix format specifiers in rootless_linux.c
2019-06-21 00:18:24 -07:00
OpenShift Merge Robot f65ddc0991
Merge pull request #3380 from openSUSE/asprintf-fix
Handle possible asprintf failure in rootless_linux.c
2019-06-20 12:30:27 -07:00