Commit graph

271 commits

Author SHA1 Message Date
Aditya Rajan ae5de8b390 volume: Add support for overlay on named volumes
Following PR allows containers to create and mount overlays on top of
named volumes instead of mounting actual volumes via already documented `:O`.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-09-21 13:06:23 +05:30
Paul Holzinger cf28dab9f1
podman machine: use gvproxy for host.containers.internal
Let the gvproxy dns server handle the host.containers.internal entry.
Support for this is already added to gvproxy. [1]

To make sure the container uses the dns response from gvproxy we should
not add host.containers.internal to /etc/hosts in this case.

[NO TESTS NEEDED] podman machine has no tests :/

Fixes #11642

[1] 1108ea4516

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-09-20 11:31:26 +02:00
Paul Holzinger f1ee234252
Only add 127.0.0.1 entry to /etc/hosts with --net=none
The check for net=none was wrong. It just assumed when we do not create
the netns but have one set that we use the none mode. This however also
applies to a container which joins the pod netns.
To correctly check for the none mode use `config.NetMode.IsNone()`.

Fixes #11596

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-09-16 18:19:15 +02:00
Paul Holzinger 85e8fbf7f3
Wire network interface into libpod
Make use of the new network interface in libpod.

This commit contains several breaking changes:
- podman network create only outputs the new network name and not file
  path.
- podman network ls shows the network driver instead of the cni version
  and plugins.
- podman network inspect outputs the new network struct and not the cni
  conflist.
- The bindings and libpod api endpoints have been changed to use the new
  network structure.

The container network status is stored in a new field in the state. The
status should be received with the new `c.getNetworkStatus`. This will
migrate the old status to the new format. Therefore old containers should
contine to work correctly in all cases even when network connect/
disconnect is used.

New features:
- podman network reload keeps the ip and mac for more than one network.
- podman container restore keeps the ip and mac for more than one
  network.
- The network create compat endpoint can now use more than one ipam
  config.

The man pages and the swagger doc are updated to reflect the latest
changes.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-09-15 20:00:20 +02:00
OpenShift Merge Robot c0cde37829
Merge pull request #11567 from giuseppe/cgroups-split-with-pods
libpod: honor --cgroups=split also with pods
2021-09-15 10:46:33 -04:00
Giuseppe Scrivano b1768d3b08
test: enable --cgroup-parent test
and fix it for running with runc.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-14 13:59:09 +02:00
Giuseppe Scrivano 44abc17977
libpod: honor --cgroups=split also with pods
Honor --cgroups=split also when the container is running in a pod.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-09-14 12:35:22 +02:00
Matthew Heon bfcd83ecd6 Add Checkpointed bool to Inspect
When inspecting a container, we now report whether the container
was stopped by a `podman checkpoint` operation via a new bool in
the State portion of inspected, `Checkpointed`.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2021-09-07 14:16:01 -04:00
Parham Alvani ce5baa125b feat: add localhost into hosts if the networking mode is not host
Signed-off-by: Parham Alvani <1995parham@tuta.io>
2021-09-04 18:24:41 +04:30
Valentin Rothberg 10144b707e pass LISTEN_* environment into container
Make sure that Podman passes the LISTEN_* environment into containers.
Similar to runc, LISTEN_PID is set to 1.

Also remove conditionally passing the LISTEN_FDS as extra files.
The condition was wrong (inverted) and introduced to fix #3572 which
related to running under varlink which has been dropped entirely
with Podman 3.0.  Note that the NOTIFY_SOCKET and LISTEN_* variables
are cleared when running `system service`.

Fixes: #10443
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-08-31 17:23:05 +02:00
flouthoc ec1f350ee5 container: resolve workdir after all the mounts happen.
There are use-cases where users would want to use overlay-mounts as
workdir. For such cases workdir should be resolved after all the mounts
are completed during the container init process.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-08-30 19:49:26 +05:30
Daniel J Walsh c22f3e8b4e Implement SD-NOTIFY proxy in conmon
This leverages conmon's ability to proxy the SD-NOTIFY socket.
This prevents locking caused by OCI runtime blocking, waiting for
SD-NOTIFY messages, and instead passes the messages directly up
to the host.

NOTE: Also re-enable the auto-update tests which has been disabled due
to flakiness.  With this change, Podman properly integrates into
systemd.

Fixes: #7316
Signed-off-by: Joseph Gooch <mrwizard@dok.org>
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-08-20 11:12:05 +02:00
Daniel J Walsh 404488a087
Run codespell to fix spelling
[NO TESTS NEEDED] Just fixing spelling.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-08-11 16:41:45 -04:00
Daniel J Walsh 221b1add74 Add support for pod inside of user namespace.
Add the --userns flag to podman pod create and keep
track of the userns setting that pod was created with
so that all containers created within the pod will inherit
that userns setting.

Specifically we need to be able to launch a pod with
--userns=keep-id

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Urvashi Mohnani <umohnani@redhat.com>
2021-08-09 15:17:22 -04:00
Matthew Heon cfcd1e1863 Do not add an entry to /etc/hosts with --net=host
To match Docker's behavior, in the `--net=host` case, we need to
use the host's `/etc/hosts` file, unmodified (without adding an
entry for the container). We will still respect hosts from
`--add-host` but will not make any automatic changes.

Fortuntely, this is strictly a matter of removal and refactoring
as we already base our `/etc/hosts` on the host's version - just
need to remove the code that added entries when net=host was set.

Fixes #10319

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2021-08-04 09:54:23 -04:00
Adrian Reber eb94467780
Support checkpoint/restore with pods
This adds support to checkpoint containers out of pods and restore
container into pods.

It is only possible to restore a container into a pod if it has been
checkpointed out of pod. It is also not possible to restore a non pod
container into a pod.

The main reason this does not work is the PID namespace. If a non pod
container is being restored in a pod with a shared PID namespace, at
least one process in the restored container uses PID 1 which is already
in use by the infrastructure container. If someone tries to restore
container from a pod with a shared PID namespace without a shared PID
namespace it will also fail because the resulting PID namespace will not
have a PID 1.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-07-27 16:10:44 +02:00
Adrian Reber 92dce3e2fe
Prepare CRIU version check to work with multiple versions
The upcoming commit to support checkpointing out of Pods requires CRIU
3.16. This changes the CRIU version check to support checking for
different versions.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-07-27 16:10:44 +02:00
Matej Vasek 6cac65c841 fix: uid/gid for volume mounted to existing dir
If mounting to existing directory the uid/gid should be preserved.
Primary uid/gid of container shouldn't be used.

Signed-off-by: Matej Vasek <mvasek@redhat.com>
2021-07-12 14:56:55 +02:00
Paul Holzinger 8f6a0243f4
podman diff accept two images or containers
First, make podman diff accept optionally a second argument. This allows
the user to specify a second image/container to compare the first with.
If it is not set the parent layer will be used as before.

Second, podman container diff should only use containers and podman
image diff should only use images. Previously, podman container diff
would use the image when both an image and container with this name
exists.

To make this work two new parameters have been added to the api. If they
are not used the previous behaviour is used. The same applies to the
bindings.

Fixes #10649

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-07-02 17:11:56 +02:00
Max Goltzsche 0fb165ed08
Fix systemd-resolved detection.
Previously podman failed when run in an environment where 127.0.0.53 is
the only nameserver but systemd-resolved is not used directly.
In practice this happened when podman was run within an alpine container
that used the host's network and the host was running systemd-resolved.

This fix makes podman ignore a file not found error when reading /run/systemd/resolve/resolv.conf.

Closes #10733

[NO TESTS NEEDED]

Signed-off-by: Max Goltzsche <max.goltzsche@gmail.com>
2021-06-20 17:17:00 +02:00
OpenShift Merge Robot 85bf412bb5
Merge pull request #10684 from Luap99/slirp-hosts
add correct slirp ip to /etc/hosts
2021-06-16 10:10:17 -04:00
Paul Holzinger 9c81b8cf72 add correct slirp ip to /etc/hosts
The container name should have the slirp interface ip set in /etc/hosts
and not the gateway ip. Commit c8dfcce6db introduced this regression.

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1972073

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-06-15 13:41:14 +02:00
Daniel J Walsh 81eb71fe36
Fix permissions on initially created named volumes
Permission of volume should match the directory it is being mounted on.

Fixes: https://github.com/containers/podman/issues/10188

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-06-14 11:56:48 -04:00
Adrian Reber 240bbc3bfa
Fix pre-checkpointing
Unfortunately --pre-checkpointing never worked as intended and recent
changes to runc have shown that it is broken.

To create a pre-checkpoint CRIU expects the paths between the
pre-checkpoints to be a relative path. If having a previous checkpoint
it needs the be referenced like this: --prev-images-dir ../parent

Unfortunately Podman was giving runc (and CRIU) an absolute path.

Unfortunately, again, until March 2021 CRIU silently ignored if
the path was not relative and switch back to normal checkpointing.

This has been now fixed in CRIU and runc and running pre-checkpoint
with the latest runc fails, because runc already sees that the path is
absolute and returns an error.

This commit fixes this by giving runc a relative path.

This commit also fixes a second pre-checkpointing error which was just
recently introduced.

So summarizing: pre-checkpointing never worked correctly because CRIU
ignored wrong parameters and recent changes broke it even more.

Now both errors should be fixed.

[NO TESTS NEEDED]

Signed-off-by: Adrian Reber <areber@redhat.com>
Signed-off-by: Adrian Reber <adrian@lisas.de>
2021-06-10 15:29:24 +02:00
Paul Holzinger 18fa124dfc Improve systemd-resolved detection
When 127.0.0.53 is the only nameserver in /etc/resolv.conf assume
systemd-resolved is used. This is better because /etc/resolv.conf does
not have to be symlinked to /run/systemd/resolve/stub-resolv.conf in
order to use systemd-resolved.

[NO TESTS NEEDED]

Fixes: #10570

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-06-08 18:14:00 +02:00
Adrian Reber 8aa5340ade
Add parameter to specify checkpoint archive compression
The checkpoint archive compression was hardcoded to `archive.Gzip`.

There have been requests to make the used compression algorithm
selectable. There was especially the request to not compress the
checkpoint archive to be able to create faster checkpoints when not
compressing it.

This also changes the default from `gzip` to `zstd`. This change should
not break anything as the restore code path automatically handles
whatever compression the user provides during restore.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-06-07 08:07:15 +02:00
Paul Holzinger df2e7e00fc add ipv6 nameservers only when the container has ipv6 enabled
The containers /etc/resolv.conf allways preserved the ipv6 nameserves
from the host even when the container did not supported ipv6. Check
if the cni result contains an ipv6 address or slirp4netns has ipv6
support enabled and only add the ipv6 nameservers when this is the case.

The test needs to have an ipv6 nameserver in the hosts /etc/hosts but we
should never mess with this file on the host. Therefore the test is
skipped when no ipv6 is detected.

Fixes #10158

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-06-03 10:19:36 +02:00
OpenShift Merge Robot a7fa0da4a5
Merge pull request #10334 from mheon/add_relabel_vol_plugin
Ensure that :Z/:z/:U can be used with named volumes
2021-05-17 16:28:21 -04:00
OpenShift Merge Robot 9a9118b831
Merge pull request #10366 from ashley-cui/secretoptions
Support uid,gid,mode options for secrets
2021-05-17 16:24:20 -04:00
Ashley Cui cf30f160ad Support uid,gid,mode options for secrets
Support UID, GID, Mode options for mount type secrets. Also, change
default secret permissions to 444 so all users can read secret.

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-05-17 14:35:55 -04:00
Baron Lenardson c8dfcce6db Add host.containers.internal entry into container's etc/hosts
This change adds the entry `host.containers.internal` to the `/etc/hosts`
file within a new containers filesystem. The ip address is determined by
the containers networking configuration and points to the gateway address
for the containers networking namespace.

Closes #5651

Signed-off-by: Baron Lenardson <lenardson.baron@gmail.com>
2021-05-17 08:21:22 -05:00
Matthew Heon 6efca0bbac Ensure that :Z/:z/:U can be used with named volumes
Docker allows relabeling of any volume passed in via -v, even
including named volumes. This normally isn't an issue at all,
given named volumes get the right label for container access
automatically, but this becomes an issue when volume plugins are
involved - these aren't managed by Podman, and may well be
unaware of SELinux labelling. We could automatically relabel
these volumes on creation, but I'm still reluctant to do that
(feels like it could break things). Instead, let's allow :z and
:Z to be used with named volumes, so users can explicitly request
relabel of a volume plugin-backed volume.

We also get :U at the same time. I don't see any real need for it
but it also doesn't seem to hurt, so I didn't bother disabling
it.

Fixes #10273

Signed-off-by: Matthew Heon <mheon@redhat.com>
2021-05-17 09:10:59 -04:00
OpenShift Merge Robot 141ba94f97
Merge pull request #10221 from ashley-cui/envsec
Add support for environment variable secrets
2021-05-07 05:34:26 -04:00
Daniel J Walsh f528511bf6
Revert Patch to relabel if selinux not enabled
Revert : https://github.com/containers/podman/pull/9895

Turns out that if Docker is in --selinux-enabeled, it still relabels if
the user tells the system to, even if running a --privileged container
or if the selinux separation is disabled --security-opt label=disable.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-05-06 18:00:16 -04:00
Ashley Cui 2634cb234f Add support for environment variable secrets
Env var secrets are env vars that are set inside the container but not
commited to and image. Also support reading from env var when creating a
secret.

Signed-off-by: Ashley Cui <acui@redhat.com>
2021-05-06 14:00:57 -04:00
Giuseppe Scrivano 27ac750c7d
cgroup: fix rootless --cgroup-parent with pods
extend to pods the existing check whether the cgroup is usable when
running as rootless with cgroupfs.

commit 17ce567c68 introduced the
regression.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-05-06 08:33:28 +02:00
Valentin Rothberg 0f7d54b026 migrate Podman to containers/common/libimage
Migrate the Podman code base over to `common/libimage` which replaces
`libpod/image` and a lot of glue code entirely.

Note that I tried to leave bread crumbs for changed tests.

Miscellaneous changes:

 * Some errors yield different messages which required to alter some
   tests.

 * I fixed some pre-existing issues in the code.  Others were marked as
   `//TODO`s to prevent the PR from exploding.

 * The `NamesHistory` of an image is returned as is from the storage.
   Previously, we did some filtering which I think is undesirable.
   Instead we should return the data as stored in the storage.

 * Touched handlers use the ABI interfaces where possible.

 * Local image resolution: previously Podman would match "foo" on
   "myfoo".  This behaviour has been changed and Podman will now
   only match on repository boundaries such that "foo" would match
   "my/foo" but not "myfoo".  I consider the old behaviour to be a
   bug, at the very least an exotic corner case.

 * Futhermore, "foo:none" does *not* resolve to a local image "foo"
   without tag anymore.  It's a hill I am (almost) willing to die on.

 * `image prune` prints the IDs of pruned images.  Previously, in some
   cases, the names were printed instead.  The API clearly states ID,
   so we should stick to it.

 * Compat endpoint image removal with _force_ deletes the entire not
   only the specified tag.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-05-05 11:30:12 +02:00
Giuseppe Scrivano 17ce567c68
cgroup: always honor --cgroup-parent with cgroupfs
if --cgroup-parent is specified, always honor it without doing any
detection whether cgroups are supported or not.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-05-03 12:36:03 +02:00
Sebastian Jug db7cff8c86
Add support for CDI device configuration
- Persist CDIDevices in container config
- Add e2e test
- Log HasDevice error and add additional condition for safety

Signed-off-by: Sebastian Jug <seb@stianj.ug>
2021-04-20 09:18:52 -04:00
Giuseppe Scrivano 2fad29ccb2
cgroup: do not set cgroup parent when rootless and cgroupfs
do not set the cgroup parent when running as rootless with cgroupfs,
even if cgroup v2 is used.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-04-12 16:55:55 +02:00
Daniel J Walsh 6831c72f6a
Don't relabel volumes if running in a privileged container
Docker does not relabel this content, and openstack is running
containers in this manner.  There is a penalty for doing this
on each container, that is not worth taking on a disable SELinux
container.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-04-05 13:07:36 -04:00
Paul Holzinger 54b588c07d rootless cni without infra container
Instead of creating an extra container create a network and mount
namespace inside the podman user namespace. This ns is used to
for rootless cni operations.
This helps to align the rootless and rootful network code path.
If we run as rootless we just have to set up a extra net ns and
initialize slirp4netns in it. The ocicni lib will be called in
that net ns.

This design allows allows easier maintenance, no extra container
with pause processes, support for rootless cni with --uidmap
and possibly more.

The biggest problem is backwards compatibility. I don't think
live migration can be possible. If the user reboots or restart
all cni containers everything should work as expected again.
The user is left with the rootless-cni-infa container and image
but this can safely be removed.

To make the existing cni configs work we need execute the cni plugins
in a extra mount namespace. This ensures that we can safely mount over
/run and /var which have to be writeable for the cni plugins without
removing access to these files by the main podman process. One caveat
is that we need to keep the netns files at `XDG_RUNTIME_DIR/netns`
accessible.

`XDG_RUNTIME_DIR/rootless-cni/{run,var}` will be mounted to `/{run,var}`.
To ensure that we keep the netns directory we bind mount this relative
to the new root location, e.g. XDG_RUNTIME_DIR/rootless-cni/run/user/1000/netns
before we mount the run directory. The run directory is mounted recursive,
this makes the netns directory at the same path accessible as before.

This also allows iptables-legacy to work because /run/xtables.lock is
now writeable.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-04-01 17:27:03 +02:00
なつき a2e834d0d9 [NO TESTS NEEDED] Fix for kernel without CONFIG_USER_NS
Signed-off-by: Natsuki <i@ntk.me>
2021-03-26 21:03:24 -07:00
TomSweeneyRedHat 5b2e71dc5b Validate passed in timezone from tz option
Erik Sjolund reported an issue where a badly formated file
could be passed into the `--tz` option and then the date in the container
would be badly messed up:

```
erik@laptop:~$ echo Hello > file.txt
erik@laptop:~$ podman run --tz=../../../home/erik/file.txt --rm -ti
docker.io/library/alpine cat /etc/localtime
Hello
erik@laptop:~$ podman --version
podman version 3.0.0-rc1
erik@laptop:~$
```
This fix checks to make sure the TZ passed in is a valid
value and then proceeds with the rest of the processing.

This was first reported as a potential security issue, but it
was thought not to be.   However, I thought closing the hole
sooner rather than later would be good.

Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>
2021-03-21 17:25:35 -04:00
Valentin Rothberg d0d084dd8c turn hidden --trace into a NOP
The --trace has helped in early stages analyze Podman code.  However,
it's contributing to dependency and binary bloat.  The standard go
tooling can also help in profiling, so let's turn `--trace` into a NOP.

[NO TESTS NEEDED]

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-03-08 09:22:42 +01:00
Adrian Reber 91b2f07d5b
Use functions and defines from checkpointctl
No functional changes.

[NO TESTS NEEDED] - only moving code around

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-03-02 17:00:06 +00:00
Adrian Reber bf92e21113
Move checkpoint/restore code to pkg/checkpoint/crutils
To be able to reuse common checkpoint/restore functions this commit
moves code to pkg/checkpoint/crutils.

This commit has not functional changes. It only moves code around.

[NO TESTS NEEDED] - only moving code around

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-03-02 17:00:06 +00:00
Paul Holzinger 90050671b7 Add dns search domains from cni response to resolv.conf
This fixes slow local host name lookups.
see containers/dnsname#57

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-02-24 10:41:56 +01:00
Eduardo Vega 874f2327e6 Add U volume flag to chown source volumes
Signed-off-by: Eduardo Vega <edvegavalerio@gmail.com>
2021-02-22 22:55:19 -06: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