Commit graph

2046 commits

Author SHA1 Message Date
Daniel J Walsh 4c4a00f63e
Support default profile for apparmor
Currently you can not apply an ApparmorProfile if you specify
--privileged.  This patch will allow both to be specified
simultaniosly.

By default Apparmor should be disabled if the user
specifies --privileged, but if the user specifies --security apparmor:PROFILE,
with --privileged, we should do both.

Added e2e run_apparmor_test.go

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-22 06:27:20 -04:00
OpenShift Merge Robot 59bad8bf71
Merge pull request #7006 from ashley-cui/umask
Add --umask flag for create, run
2020-07-22 05:40:32 -04:00
Ashley Cui d4d3fbc155 Add --umask flag for create, run
--umask sets the umask inside the container
Defaults to 0022

Co-authored-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Ashley Cui <acui@redhat.com>
2020-07-21 14:22:30 -04:00
Matthew Heon 90e547ec1a Do not print an error message on non-0 exec exit code
This was added with an earlier exec rework, and honestly is very
confusing. Podman is printing an error message, but the error had
nothing to do with Podman; it was the executable we ran inside
the container that errored, and per `podman run` convention we
should set the Podman exit code to the process's exit code and
print no error.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-07-21 13:28:40 -04:00
OpenShift Merge Robot f8e2a3500e
Merge pull request #6902 from vrothberg/events-endpoint
events endpoint: fix panic and race condition
2020-07-21 10:55:40 -04:00
Daniel J Walsh 841eac0af6
Switch references from libpod.conf to containers.conf
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-20 15:09:54 -04:00
Qi Wang 020d81f113 Add support for overlay volume mounts in podman.
Add support -v for overlay volume mounts in podman.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-07-20 09:48:55 -04:00
Valentin Rothberg d856e87f40 events endpoint: fix panic and race condition
Fix a potential panic in the events endpoint when parsing the filters
parameter.  Values of the filters map might be empty, so we need to
account for that instead of uncondtitionally accessing the first item.

Also apply a similar for race conditions as done in commit f4a2d25c0f:

	Fix a race that could cause read errors to be masked.  Masking
	such errors is likely to report red herrings since users don't
	see that reading failed for some reasons but that a given event
	could not be found.

Another race was the handler closing event channel, which could lead to
two kinds of panics: double close, send to close channel.  The backend
takes care of that.  However, make sure that the backend stops working
in case the context has been cancelled.

Fixes: #6899
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-20 11:37:05 +02:00
Giuseppe Scrivano 65d382dc68
abi: set default umask and rlimits
the code got lost in the migration to podman 2.0, reintroduce it.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-17 20:53:38 +02:00
OpenShift Merge Robot d86bae2a01
Merge pull request #6965 from giuseppe/followup-pr6324
allow switching of port-forward approaches in rootless/using slirp4netns
2020-07-17 04:44:49 -04:00
Giuseppe Scrivano 7722b582b4
network, slirp4netns: add option to allow host loopback
Closes: https://github.com/containers/podman/issues/6912

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-16 22:37:27 +02:00
Giuseppe Scrivano 9be7029cdd
libpod: pass down network options
do not pass network specific options through the network namespace.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-16 22:37:27 +02:00
Matthew Heon 1ad7042a34 Preserve passwd on container restart
We added code to create a `/etc/passwd` file that we bind-mount
into the container in some cases (most notably,
`--userns=keep-id` containers). This, unfortunately, was not
persistent, so user-added users would be dropped on container
restart. Changing where we store the file should fix this.

Further, we want to ensure that lookups of users in the container
use the right /etc/passwd if we replaced it. There was already
logic to do this, but it only worked for user-added mounts; it's
easy enough to alter it to use our mounts as well.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-15 10:25:46 -04:00
OpenShift Merge Robot 6224f3f5d5
Merge pull request #6956 from mheon/add_ports_to_pod_inspect
Include infra container information in `pod inspect`
2020-07-15 04:50:40 -04:00
aleks-mariusz 8d12f19371
allow switching of port-forward approaches in rootless/using slirp4netns
As of podman 1.8.0, because of commit da7595a, the default approach of providing
port-forwarding in rootless mode has switched (and been hard-coded) to rootlessport,
for the purpose of providing super performance. The side-effect of this switch is
source within the container to the port-forwarded service always appears to originate
from 127.0.0.1 (see issue #5138).

This commit allows a user to specify if they want to revert to the previous approach
of leveraging slirp4netns add_hostfwd() api which, although not as stellar performance,
restores usefulness of seeing incoming traffic origin IP addresses.

The change should be transparent; when not specified, rootlessport will continue to be
used, however if specifying --net slirp4netns:slirplisten the old approach will be used.

Note: the above may imply the restored port-forwarding via slirp4netns is not as
performant as the new rootlessport approach, however the figures shared in the original
commit that introduced rootlessport are as follows:
slirp4netns: 8.3 Gbps,
RootlessKit: 27.3 Gbps,
which are more than sufficient for many use cases where the origin of traffic is more
important than limits that cannot be reached due to bottlenecks elsewhere.

Signed-off-by: Aleks Mariusz <m.k@alek.cx>
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-15 08:04:35 +02:00
Matthew Heon fbc1167c4d Fix lint
Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-07-14 13:24:12 -04:00
Matthew Heon 05988fc74f Add SystemdMode to inspect for containers
This allows us to determine if the container auto-detected that
systemd was in use, and correctly activated systemd integration.
Use this to wire up some integration tests to verify that systemd
integration is working properly.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-14 13:21:05 -04:00
Matthew Heon 1fdfd52eeb Populate remaining unused fields in pod inspect
We were hard-coding two fields to false, instead of grabbing
their value from the pod config, which means that `pod inspect`
would print the wrong value always.

Fixes #6968

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-07-14 12:03:11 -04:00
Matthew Heon 41457b5a28 Include infra container information in pod inspect
We had a field for this in the inspect data, but it was never
being populated. Because of this, `podman pod inspect` stopped
showing port bindings (and other infra container settings). Add
code to populate the infra container inspect data, and add a test
to ensure we don't regress again.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-07-14 12:03:11 -04:00
Matthew Heon c4627b5846 Fix container and pod create commands for remote create
In `podman inspect` output for containers and pods, we include
the command that was used to create the container. This is also
used by `podman generate systemd --new` to generate unit files.

With remote podman, the generated create commands were incorrect
since we sourced directly from os.Args on the server side, which
was guaranteed to be `podman system service` (or some variant
thereof). The solution is to pass the command along in the
Specgen or PodSpecgen, where we can source it from the client's
os.Args.

This will still be VERY iffy for mixed local/remote use (doing a
`podman --remote run ...` on a remote client then a
`podman generate systemd --new` on the server on the same
container will not work, because the `--remote` flag will slip
in) but at the very least the output of `podman inspect` will be
correct. We can look into properly handling `--remote` (parsing
it out would be a little iffy) in a future PR.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-10 11:22:23 -04:00
Matthew Heon 4b784b377c Remove all instances of named return "err" from Libpod
This was inspired by https://github.com/cri-o/cri-o/pull/3934 and
much of the logic for it is contained there. However, in brief,
a named return called "err" can cause lots of code confusion and
encourages using the wrong err variable in defer statements,
which can make them work incorrectly. Using a separate name which
is not used elsewhere makes it very clear what the defer should
be doing.

As part of this, remove a large number of named returns that were
not used anywhere. Most of them were once needed, but are no
longer necessary after previous refactors (but were accidentally
retained).

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-09 13:54:47 -04:00
OpenShift Merge Robot bc3b3b373f
Merge pull request #6916 from vrothberg/logs-fixes
log API: add context to allow for cancelling
2020-07-09 17:05:47 +02:00
Valentin Rothberg 09dc77aedf log API: add context to allow for cancelling
Add a `context.Context` to the log APIs to allow for cancelling
streaming (e.g., via `podman logs -f`).  This fixes issues for
the remote API where some go routines of the server will continue
writing and produce nothing but heat and waste CPU cycles.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-09 15:13:07 +02:00
Qi Wang a1d6114177 Fix saving in oci format
- fix saving&loading oci format. Close #6544
- support loading using image name without "localhost/" prefix when reading from ociarchive/dir saved from this semantics

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-07-09 08:03:54 -04:00
OpenShift Merge Robot 54d16f3b5f
Merge pull request #6829 from rhatdan/keepid
Add username to /etc/passwd inside of container if --userns keep-id
2020-07-07 19:23:27 +02:00
Valentin Rothberg f4a2d25c0f fix race condition in libpod.GetEvents(...)
Fix a race that could cause read errors to be masked.  Masking such
errors is likely to report red herrings since users don't see that
reading failed for some reasons but that a given event could not be
found.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-07 16:22:22 +02:00
Daniel J Walsh 6c6670f12a
Add username to /etc/passwd inside of container if --userns keep-id
If I enter a continer with --userns keep-id, my UID will be present
inside of the container, but most likely my user will not be defined.

This patch will take information about the user and stick it into the
container.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-07 08:34:31 -04:00
Joseph Gooch 0b1c1ef461 Implement --sdnotify cmdline option to control sd-notify behavior
--sdnotify container|conmon|ignore
With "conmon", we send the MAINPID, and clear the NOTIFY_SOCKET so the OCI
runtime doesn't pass it into the container. We also advertise "ready" when the
OCI runtime finishes to advertise the service as ready.

With "container", we send the MAINPID, and leave the NOTIFY_SOCKET so the OCI
runtime passes it into the container for initialization, and let the container advertise further metadata.
This is the default, which is closest to the behavior podman has done in the past.

The "ignore" option removes NOTIFY_SOCKET from the environment, so neither podman nor
any child processes will talk to systemd.

This removes the need for hardcoded CID and PID files in the command line, and
the PIDFile directive, as the pid is advertised directly through sd-notify.

Signed-off-by: Joseph Gooch <mrwizard@dok.org>
2020-07-06 17:47:18 +00:00
OpenShift Merge Robot 9532509c50
Merge pull request #6836 from ashley-cui/tzlibpod
Add --tz flag to create, run
2020-07-06 13:28:20 -04:00
Valentin Rothberg 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
OpenShift Merge Robot 4351e33947
Merge pull request #6846 from mheon/fix_pod_errors
Print errors from individual containers in pods
2020-07-06 06:26:19 -04:00
Ashley Cui 9a1543caec Add --tz flag to create, run
--tz flag sets timezone inside container
Can be set to IANA timezone as well as `local` to match host machine

Signed-off-by: Ashley Cui <acui@redhat.com>
2020-07-02 13:30:59 -04:00
Matthew Heon e996bb583d Print errors from individual containers in pods
The infra/abi code for pods was written in a flawed way, assuming
that the map[string]error containing individual container errors
was only set when the global error for the pod function was nil;
that is not accurate, and we are actually *guaranteed* to set the
global error when any individual container errors. Thus, we'd
never actually include individual container errors, because the
infra code assumed that err being set meant everything failed and
no container operations were attempted.

We were originally setting the cause of the error to something
nonsensical ("container already exists"), so I made a new error
indicating that some containers in the pod failed. We can then
ignore that error when building the report on the pod operation
and actually return errors from individual containers.

Unfortunately, this exposed another weakness of the infra code,
which was discarding the container IDs. Errors from individual
containers are not guaranteed to identify which container they
came from, hence the use of map[string]error in the Pod API
functions. Rather than restructuring the structs we return from
pkg/infra, I just wrapped the returned errors with a message
including the ID of the container.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-02 12:59:10 -04:00
Matthew Heon 9e4cf6ca51 Fix system service panic from early hangup in events
We weren't actually halting the goroutine that sent events, so it
would continue sending even when the channel closed (the most
notable cause being early hangup - e.g. Control-c on a curl
session). Use a context to cancel the events goroutine and stop
sending events.

Fixes #6805

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-02 09:57:39 -04:00
OpenShift Merge Robot c2a0ccd394
Merge pull request #6747 from giuseppe/fix-user-volumes
container: move volume chown after spec generation
2020-06-30 12:01:40 -04:00
Giuseppe Scrivano b32172e20b
container: move volume chown after spec generation
move the chown for newly created volumes after the spec generation so
the correct UID/GID are known.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-29 17:58:50 +02:00
Giuseppe Scrivano 688cc0aee3
libpod: volume copyup honors namespace mappings
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-29 17:51:55 +02:00
OpenShift Merge Robot 6ac009d530
Merge pull request #6666 from giuseppe/conmon-delegate
podman: add new cgroup mode split
2020-06-29 10:53:41 -04:00
Giuseppe Scrivano 6ee5f740a4
podman: add new cgroup mode split
When running under systemd there is no need to create yet another
cgroup for the container.

With conmon-delegated the current cgroup will be split in two sub
cgroups:

- supervisor
- container

The supervisor cgroup will hold conmon and the podman process, while
the container cgroup is used by the OCI runtime (using the cgroupfs
backend).

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-25 17:16:12 +02:00
Matthew Heon d78e83f47d Add support for dangling filter to volumes
The dangling filter determine whether a volume is dangling - IE,
it has no containers attached using it. Unlike our other filters,
this one is a boolean - must be true or false, not arbitrary
values.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-24 15:12:56 -04:00
OpenShift Merge Robot b61e429f19
Merge pull request #6732 from mheon/fix_stopsignal_set
Set stop signal to 15 when not explicitly set
2020-06-24 13:02:43 -04:00
OpenShift Merge Robot 988fd27541
Merge pull request #6746 from vrothberg/untag
podman untag: error if tag doesn't exist
2020-06-24 12:19:42 -04:00
OpenShift Merge Robot 6bc5dcc282
Merge pull request #6729 from QiWang19/inspect-format
Reformat inspect network settings
2020-06-24 09:35:25 -04:00
Valentin Rothberg 1c6c12581c podman untag: error if tag doesn't exist
Throw an error if a specified tag does not exist.  Also make sure that
the user input is normalized as we already do for `podman tag`.

To prevent regressions, add a set of end-to-end and systemd tests.

Last but not least, update the docs and add bash completions.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-06-24 15:34:46 +02:00
Matthew Heon 7fe4c5204e Set stop signal to 15 when not explicitly set
When going through the output of `podman inspect` to try and
identify another issue, I noticed that Podman 2.0 was setting
StopSignal to 0 on containers by default. After chasing it
through the command line and SpecGen, I determined that we were
actually not setting a default in Libpod, which is strange
because I swear we used to do that. I re-added the disappeared
default and now all is well again.

Also, while I was looking for the bug in SpecGen, I found a bunch
of TODOs that have already been done. Eliminate the comments for
these.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-24 09:27:20 -04:00
Giuseppe Scrivano 370195cf78
libpod: specify mappings to the storage
specify the mappings in the container configuration to the storage
when creating the container so that the correct mappings can be
configured.

Regression introduced with Podman 2.0.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-24 11:26:49 +02:00
Qi Wang f586c006f8 Reformat inspect network settings
Reformat ports of inspect network settings to compatible with docker inspect. Close #5380

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-06-23 16:14:27 -04:00
OpenShift Merge Robot 9e37fd43e4
Merge pull request #6625 from QiWang19/fd
Add --preservefds to podman run
2020-06-23 10:00:21 +02:00
OpenShift Merge Robot 11dd5f51b6
Merge pull request #6702 from jgallucci32/follow-logs-poll
Stop following logs using timers
2020-06-22 18:10:06 +02:00
jgallucci32 8926e1f03b Use POLL_DURATION for timer
Signed-off-by: jgallucci32 <john.gallucci.iv@gmail.com>
2020-06-21 09:31:22 -07:00