302 Commits

Author SHA1 Message Date
f04465bfe6 fix host.containers.internal entry for macvlan networks
For ip/macvlan networks we cannot use the gateway as address for this
hostname. In this case the gateway is normally not on the host so we
just try to use a local ip instead.

[NO NEW TESTS NEEDED] We cannot run macvlan networks in CI.

Fixes #11351

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2022-01-11 16:10:01 +01:00
e8c06fac97 Allow users to add host user accounts to /etc/passwd
Some containers require certain user account(s) to exist within the
container when they are run. This option will allow callers to add a
bunch of passwd entries from the host to the container even if the
entries are not in the local /etc/passwd file on the host.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-12-23 07:51:27 -05:00
f3d485d4d7 Enable checkpoint/restore for /dev/shm
When Podman is running a container in private IPC mode (default), it
creates a bind mount for /dev/shm that is then attached to a tmpfs
folder on the host file system. However, checkpointing a container has
the side-effect of stopping that container and unmount the tmpfs used
for /dev/shm. As a result, after checkpoint all files stored in the
container's /dev/shm would be lost and the container might fail to
restore from checkpoint.

To address this problem, this patch creates a tar file with the
content of /dev/shm that is included in the container checkpoint and
used to restore the container.

Signed-off-by: Radostin Stoyanov <rstoyanov@fedoraproject.org>
2021-12-23 05:47:25 +00:00
af1dbbfb75 Always run passwd management code when DB value is nil
This ensures that existing containers will still manage
`/etc/passwd` by default, as they have been doing until now. New
containers that explicitly set `false` will still have passwd
management disabled, but otherwise the code will run.

[NO NEW TESTS NEEDED] This will only be caught on upgrade and I
don't really know how to write update tests - and Ed is on PTO.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2021-12-22 11:39:52 -05:00
2aea0a5e9b Merge pull request #12375 from rhatdan/hosts
Use hosts public ip address in rootless containers
2021-12-22 16:40:10 +01:00
3280204f72 Merge pull request #12668 from vrothberg/fix-12667
support hosts without /etc/hosts
2021-12-22 12:13:57 +01:00
04dbbd96b6 support hosts without /etc/hosts
Fixes: #12667
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-12-22 10:15:24 +01:00
20ce6e5c60 Podman run --passwd
added support for a new flag --passwd which, when false prohibits podman from creating entries in
/etc/passwd and /etc/groups allowing users to modify those files in the container entrypoint

resolves #11805

Signed-off-by: cdoern <cdoern@redhat.com>
2021-12-21 17:19:41 -05:00
64ce6949f2 Use hosts public ip address in rootless containers
Add first non localhost ipv4 of all host interfaces as destination
for host.contaners.internal for rootless containers.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-12-21 08:50:40 -05:00
bc3389e212 Add more checkpoint/restore information to 'inspect'
This adds the following information to the output of 'podman inspect':

 * CheckpointedAt - time the container was checkpointed
   Only set if the container has been checkpointed

 * RestoredAt - time the container was restored
   Only set if the container has been restored

 * CheckpointLog - path to the checkpoint log file (CRIU's dump.log)
   Only set if the log file exists (--keep)

 * RestoreLog - path to the restore log file (CRIU's restore.log)
   Only set if the log file exists (--keep)

 * CheckpointPath - path to the actual (CRIU) checkpoint files
   Only set if the checkpoint files exists (--keep)

 * Restored - set to true if the container has been restored
   Only set if the container has been restored

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-12-17 10:02:35 +00:00
5490be67b3 network db rewrite: migrate existing settings
The new network db structure stores everything in the networks bucket.
Previously some network settings were not written the the network bucket
and only stored in the container config.
Instead of the old format which used the container ID as value in the
networks buckets we now use the PerNetworkoptions struct there.

To migrate existing users we use the state.GetNetworks() function. If it
fails to read the new format it will automatically migrate the old
config format to the new one. This is allows a flawless migration path.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-12-14 15:23:20 +01:00
23ce826a84 Merge pull request #12498 from rhatdan/cgroups
Update vendor or containers/common moving pkg/cgroups there
2021-12-07 12:49:57 +00:00
2130d18539 Update vendor or containers/common moving pkg/cgroups there
[NO NEW TESTS NEEDED] This is just moving pkg/cgroups out so
existing tests should be fine.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-12-07 06:17:11 -05:00
7d0fd175f1 volume: apply exact permission of target directory without adding extra 0111
While trying to match permissions of target directory podman adds
extra `0111` which should not be needed if target path does not have
execute permission.

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-12-07 15:42:12 +05:30
e648122b29 libpod: improve heuristic to detect cgroup
improve the heuristic to detect the scope that was created for the container.
This is necessary with systemd running as PID 1, since it moves itself
to a different sub-cgroup, thus stats would not account for other
processes in the same container.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2021-11-24 14:50:12 +01:00
97c6403a1b rename libpod nettypes fields
Some field names are confusing. Change them so that they make more sense
to the reader.
Since these fields are only in the main branch we can safely rename them
without worrying about backwards compatibility.
Note we have to change the field names in netavark too.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-11-16 19:19:04 +01:00
f031bd23c6 Merge pull request #12100 from rhatdan/env
Add option --unsetenv to remove default environment variables
2021-11-16 16:27:34 +01:00
be681ab518 Merge pull request #12294 from flouthoc/secret-mount-target
secret: honor custom `target=` for secrets with `type=mount` for ctr.
2021-11-16 01:45:27 +01:00
44d1618dd7 Add --unsetenv & --unsetenv-all to remove def environment variables
Podman adds a few environment variables by default, and
currently there is no way to get rid of them from your container.
This option will allow  you to specify which defaults you don't
want.

--unsetenv-all will remove all default environment variables.

Default environment variables can come from podman builtin,
containers.conf or from the container image.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-11-15 15:10:12 -05:00
014cc4b9d9 secret: honor custom target for secrets with run
Honor custom `target` if specified while running or creating containers
with secret `type=mount`.

Example:
`podman run -it --secret token,type=mount,target=TOKEN ubi8/ubi:latest
bash`

Signed-off-by: Aditya Rajan <arajan@redhat.com>
2021-11-15 23:19:27 +05:30
80e56fa12b Added optional container restore statistics
This adds the parameter '--print-stats' to 'podman container restore'.
With '--print-stats' Podman will measure how long Podman itself, the OCI
runtime and CRIU requires to restore a checkpoint and print out these
information. CRIU already creates process restore statistics which are
just read in addition to the added measurements. In contrast to just
printing out the ID of the restored container, Podman will now print
out JSON:

 # podman container restore --latest --print-stats
 {
     "podman_restore_duration": 305871,
     "container_statistics": [
         {
             "Id": "47b02e1d474b5d5fe917825e91ac653efa757c91e5a81a368d771a78f6b5ed20",
             "runtime_restore_duration": 140614,
             "criu_statistics": {
                 "forking_time": 5,
                 "restore_time": 67672,
                 "pages_restored": 14
             }
         }
     ]
 }

The output contains 'podman_restore_duration' which contains the
number of microseconds Podman required to restore the checkpoint. The
output also includes 'runtime_restore_duration' which is the time
the runtime needed to restore that specific container. Each container
also includes 'criu_statistics' which displays the timing information
collected by CRIU.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-11-15 11:50:25 +00:00
6202e8102b Added optional container checkpointing statistics
This adds the parameter '--print-stats' to 'podman container checkpoint'.
With '--print-stats' Podman will measure how long Podman itself, the OCI
runtime and CRIU requires to create a checkpoint and print out these
information. CRIU already creates checkpointing statistics which are
just read in addition to the added measurements. In contrast to just
printing out the ID of the checkpointed container, Podman will now print
out JSON:

 # podman container checkpoint --latest --print-stats
 {
     "podman_checkpoint_duration": 360749,
     "container_statistics": [
         {
             "Id": "25244244bf2efbef30fb6857ddea8cb2e5489f07eb6659e20dda117f0c466808",
             "runtime_checkpoint_duration": 177222,
             "criu_statistics": {
                 "freezing_time": 100657,
                 "frozen_time": 60700,
                 "memdump_time": 8162,
                 "memwrite_time": 4224,
                 "pages_scanned": 20561,
                 "pages_written": 2129
             }
         }
     ]
 }

The output contains 'podman_checkpoint_duration' which contains the
number of microseconds Podman required to create the checkpoint. The
output also includes 'runtime_checkpoint_duration' which is the time
the runtime needed to checkpoint that specific container. Each container
also includes 'criu_statistics' which displays the timing information
collected by CRIU.

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-11-15 11:50:24 +00:00
216e2cb366 Fix rootless networking with userns and ports
A rootless container created with a custom userns and forwarded ports
did not work. I refactored the network setup to make the setup logic
more clear.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-11-09 15:58:57 +01:00
6b8fc3bd1d Add 'stats-dump' file to exported checkpoint
There was the question about how long it takes to create a checkpoint.
CRIU already provides some statistics about how long it takes to create
a checkpoint and similar.

With this change the file 'stats-dump' is included in the checkpoint
archive and the tool checkpointctl can be used to display these
statistics:

./checkpointctl show -t /tmp/cp.tar --print-stats

Displaying container checkpoint data from /tmp/dump.tar

[...]
CRIU dump statistics
+---------------+-------------+--------------+---------------+---------------+---------------+
| FREEZING TIME | FROZEN TIME | MEMDUMP TIME | MEMWRITE TIME | PAGES SCANNED | PAGES WRITTEN |
+---------------+-------------+--------------+---------------+---------------+---------------+
| 105405 us     | 1376964 us  | 504399 us    | 446571 us     |        492153 |         88689 |
+---------------+-------------+--------------+---------------+---------------+---------------+

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-11-05 16:15:00 +00:00
dcbf5cae12 Set Checkpointed state to false after restore
A restored container still had the state set to 'Checkpointed: true'
which seems wrong if it running again.

[NO NEW TESTS NEEDED]

Signed-off-by: Adrian Reber <areber@redhat.com>
2021-10-27 13:40:54 +00:00
a42c131c80 Update vendor github.com/opencontainers/runtime-tools
This will change mount of /dev within container to noexec, making
containers slightly more secure.

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-10-25 16:50:45 -04:00
207abc4a9a We should only be relabeling when on first run
On the second runs, the labels should be the same so no
need to relabel.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-10-15 14:27:14 -04:00
f9ff0525c5 Don't include ctr.log if not using file logging
Checkpoint is blowing up when you use --log-driver=none

[NO NEW TESTS NEEDED] No way currently to test checkpoint restore.

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

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-10-14 14:12:15 -04:00
8600bce53a codespell code
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-10-12 16:44:25 -04:00
05614ee139 always add short container id as net alias
This matches what docker does. Also make sure the net aliases are also
shown when the container is stopped.

docker-compose uses this special alias entry to check if it is already
correctly connected to the network. [1]
Because we do not support static ips on network connect at the moment
calling disconnect && connect will loose the static ip.

Fixes #11748

[1] 0bea52b18d/compose/service.py (L663-L667)

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2021-09-28 13:40:22 +02:00
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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