Commit graph

2065 commits

Author SHA1 Message Date
Paul Holzinger 2c79f9929d fix podman logs --tail when log is bigger than pagesize
Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-08-06 20:56:30 +02:00
Paul Holzinger 97b2b07953 Improve error message when creating a pod/ctr with the same name
Check if there is an pod or container an return
the appropriate error message instead of blindly
return 'container exists' with `podman create` and
'pod exists' with `podman pod create`.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-08-04 11:39:27 +02:00
OpenShift Merge Robot 96ece0ca56
Merge pull request #7188 from zhangguanzhang/network-404
API returns 500 in case network is not found instead of 404
2020-08-03 09:13:40 -04:00
Sascha Grunert fef3e2da6a
Remove some unnecessary []byte to string conversions
Some calls to `Sprintf("%s")` can be avoided by using direct string
type assertions.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-08-03 09:13:04 +02:00
zhangguanzhang 45b100d21c API returns 500 in case network is not found instead of 404
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
2020-08-02 22:21:28 +08:00
Matthew Heon e3ced7217f Ensure libpod/define does not include libpod/image
The define package under Libpod is intended to be an extremely
minimal package, including constants and very little else.
However, as a result of some legacy code, it was dragging in all
of libpod/image (and, less significantly, the util package).
Fortunately, this was just to ensure that error constants were
not duplicating, and there's nothing preventing us from
importing in the other direction and keeping libpod/define free
of dependencies.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-31 17:17:56 -04:00
OpenShift Merge Robot 7a15be546a
Merge pull request #7168 from QiWang19/exec-fds
Fix close fds of exec --preserve-fds
2020-07-31 11:34:23 -04:00
Qi Wang 3fccb699e4 Fix close fds of exec --preserve-fds
Fix the closing of fds from --preserve-fds to avoid the operation on unrelated fds.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-07-31 08:27:12 -04:00
OpenShift Merge Robot 3cf8237bc0
Merge pull request #7120 from QiWang19/preserve-fd
Fix close fds of run --preserve-fds
2020-07-31 08:25:05 -04:00
Giuseppe Scrivano 10627228be
volumes: do not recurse when chowning
keep the file ownership when chowning and honor the user namespace
mappings.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-31 10:57:03 +02:00
Qi Wang 57967414ae fix close fds of run --preserve-fds
Test flakes mentioned in #6987 might be caused by uncorrect closing of file descriptor.
Fix the code to close file descriptors for podman run since it may close those used by other processes.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-07-30 15:32:39 -04:00
Matthew Heon 9f5a11cacc Ensure that 'rmi --force' evicts Podman containers
The logic for `podman rmi --force` includes a bit of code that
will remove Libpod containers using Libpod's container removal
logic - this ensures that they're cleanly and completely removed.
For other containers (Buildah, CRI-O, etc) we fall back to
manually removing the containers using the image from c/storage.

Unfortunately, our logic for invoking the Podman removal function
had an error, and it did not properly handle cases where we were
force-removing an image with >1 name. Force-removing such images
by ID guarantees their removal, not just an untag of a single
name; our code for identifying whether to remove containers did
not proper detect this case, so we fell through and deleted the
Podman containers as storage containers, leaving traces of them
in the Libpod DB.

Fixes #7153

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-30 12:01:05 -04:00
OpenShift Merge Robot 044a7cb100
Merge pull request #6991 from mheon/change_passwd_ondisk
Make changes to /etc/passwd on disk for non-read only
2020-07-29 14:27:50 -04: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 a5e37ad280
Switch all references to github.com/containers/libpod -> podman
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-28 08:23:45 -04:00
OpenShift Merge Robot 2b7bc9b101
Merge pull request #7094 from rhatdan/volume
When chowning we should not follow symbolic link
2020-07-27 21:42:38 +02:00
Daniel J Walsh e1ab449e21
When chowning we should not follow symbolic link
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-27 13:33:31 -04:00
Matthew Heon bae6853906 Make changes to /etc/passwd on disk for non-read only
Bind-mounting /etc/passwd into the container is problematic
becuase of how system utilities like `useradd` work. They want
to make a copy and then rename to try to prevent breakage; this
is, unfortunately, impossible when the file they want to rename
is a bind mount. The current behavior is fine for read-only
containers, though, because we expect useradd to fail in those
cases.

Instead of bind-mounting, we can edit /etc/passwd in the
container's rootfs. This is kind of gross, because the change
will show up in `podman diff` and similar tools, and will be
included in images made by `podman commit`. However, it's a lot
better than breaking important system tools.

Fixes #6953

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-23 14:27:19 -04:00
louis 10c4ab1149 Refactor container config
This commit handle the TODO task of breaking the Container
config into smaller sub-configs

Signed-off-by: ldelossa <ldelossa@redhat.com>
2020-07-23 10:18:14 -04:00
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