Commit graph

2008 commits

Author SHA1 Message Date
OpenShift Merge Robot 416fd4846f
Merge pull request #5712 from rhatdan/path
Pass path environment down to the OCI runtime
2020-04-03 19:42:15 +02:00
OpenShift Merge Robot 2d9b9e81a3
Merge pull request #5676 from kolyshkin/volume-flags-alt
Fix/improve pkg/storage.InitFSMounts
2020-04-03 18:34:01 +02:00
Adrian Reber 001fe983df
checkpoint: handle XDG_RUNTIME_DIR
For (almost) all commands which podman passes on to a OCI runtime
XDG_RUNTIME_DIR is set to the same value. This does not happen for the
checkpoint command.

Using crun to checkpoint a container without this change will lead to
crun using XDG_RUNTIME_DIR of the currently logged in user and so it
will not find the container Podman wants to checkpoint.

This bascially just copies a few lines from on of the other commands to
handle 'checkpoint' as all the other commands.

Thanks to Giuseppe for helping me with this.

For 'restore' it is not needed as restore goes through conmon and for
calling conmon Podman already configures XDG_RUNTIME_DIR correctly.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-04-03 18:00:57 +02:00
Adrian Reber 7660330ae2
checkpoint: change runtime checkpoint support test
Podman was checking if the runtime support checkpointing by running
'runtime checkpoint -h'. That works for runc.

crun, however, does not use '-h, --help' for help output but, '-?,
--help'.

This commit switches both checkpoint support detection from
 'runtime checkpoint -h'
to
 'runtime checkpoint --help'.

Podman can now correctly detect if 'crun' also support checkpointing.

Signed-off-by: Adrian Reber <areber@redhat.com>
2020-04-03 18:00:57 +02:00
Daniel J Walsh 84aa81fabe
Pass path environment down to the OCI runtime
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-04-03 11:45:55 -04:00
Alban Bedel 77d19f847a If possible use the pod name when creating a network
When creating a network we pass down a name which end up in the
K8S_POD_NAME argument to cni plugins. Currently this name is always
filled with the container name, so for pods it is the name of the
infra container, not really what one would expect.

This mess up with the dnsname plugin as it doesn't receive the pod
name in K8S_POD_NAME. To fix this pass the pod name when the container
is part of a pod, otherwise use the container name like before.

Signed-off-by: Alban Bedel <albeu@free.fr>
---
v2: Only call GetPod() when a pod id is set
2020-04-03 02:47:30 +02:00
Kir Kolyshkin e0614367ca pkg/spec.InitFSMounts: optimize
Instead of getting mount options from /proc/self/mountinfo, which is
very costly to read/parse (and can even be unreliable), let's use
statfs(2) to figure out the flags we need.

[v2: move getting default options to pkg/util, make it linux-specific]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-04-02 07:52:34 -07:00
Giuseppe Scrivano 41fc891173
attach: skip shutdown on errors
skip doing a socket shutdown on an error, since we are not sure the
socket was already closed and we end up using the wrong fd.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-04-02 09:15:57 +02:00
Giuseppe Scrivano 4c02aa46c2
attach: fix hang if control path is deleted
if the control path file is deleted, libpod hangs waiting for a reader
to open it.  Attempt to open it as non blocking until it returns an
error different than EINTR or EAGAIN.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-04-02 09:15:56 +02:00
Brent Baude 8500ce6b9a podmanv2 load
enable podman load for v2

add reexec into main

add systemd build flag to v2 makefile

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-04-01 14:10:57 -05:00
Brent Baude 7def91910c podmanv2 pod ps
add the ability to list pods in podmanv2

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-03-31 19:32:37 -05:00
Sagi Shnaidman f7241b24e6 Revert "Default CPUShares in Inspect are 1024"
cpu-share is 0 in docker inspect, see
https://github.com/moby/moby/issues/35452

This reverts commit eb229d526c.

Signed-off-by: Sagi Shnaidman <sshnaidm@redhat.com>
2020-03-30 21:38:19 +03:00
OpenShift Merge Robot cc22b94a7a
Merge pull request #5602 from rhatdan/vendor
Update vendor of boltdb and containers/image
2020-03-30 15:54:36 +02:00
Daniel J Walsh 366001fb5f
Update vendor of boltdb and containers/image
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-29 06:16:27 -04:00
Valentin Rothberg 9812804f75 podmanv2: implement pod top
Implement `podman pod top` for podmanV2.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-03-28 17:32:22 +01:00
Daniel J Walsh 4352d58549
Add support for containers.conf
vendor in c/common config pkg for containers.conf

Signed-off-by: Qi Wang qiwan@redhat.com
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-27 14:36:03 -04:00
Brent Baude e56d529561 podmanv2 pod create using podspecgen
using the factory approach similar to container, we now create pods based on a pod spec generator.  wired up the podmanv2 pod create command, podcreatewithspec binding, simple binding test, and apiv2 endpoint.

also included some code refactoring as it introduced as easy circular import.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-03-27 09:04:10 -05:00
Valentin Rothberg 2c4ac55c81 use pause:3.2 image for infra containers
The `pause:3.1` has wrong configs for non-amd64 images as they all claim
to be for amd64.  The issue has now been fixed in the latest
`pause:3.2`.

[1] https://github.com/kubernetes/kubernetes/issues/87325

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-03-27 10:32:04 +01:00
Brent Baude 2fa78938a9 podmanv2 container inspect
add ability to inspect a container

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-03-26 15:54:26 -05:00
OpenShift Merge Robot 913426c70c
Merge pull request #5573 from mheon/add_basic_exec_endpoints
Implement APIv2 Exec Create and Inspect Endpoints
2020-03-26 20:10:08 +01:00
Matthew Heon e42cbdd1b2 Add bindings for Container Exec Create + Inspect
Also adds some basic tests for these two. More tests are needed
but will have to wait for state to be finished.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-03-26 13:33:33 -04:00
Giuseppe Scrivano f8ccd76858
slirp: enable seccomp filter
add a check for --enable-seccomp support in slirp4netns.  If it is
supported, always enable it.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-26 16:45:33 +01:00
Matthew Heon 1313f8a450 Ensure that exec sends resize events
We previously tried to send resize events only after the exec
session successfully started, which makes sense (we might drop an
event or two that came in before the exec session started
otherwise). However, the start function blocks, so waiting
actually means we send no resize events at all, which is
obviously worse than losing a few.. Sending resizes before attach
starts seems to work fine in my testing, so let's do that until we
get bug reports that it doesn't work.

Fixes #5584

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-03-25 15:33:52 -04:00
Brent Baude ae614920bf podmanv2 volumes
add volume commands: create, inspect, ls, prune, and rm

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-03-24 16:03:49 -05:00
Matthew Heon 0c40b62c77 Implement APIv2 Exec Create and Inspect Endpoints
Start and Resize require further implementation work.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-03-23 16:20:42 -04:00
OpenShift Merge Robot e34ec617a3
Merge pull request #5434 from mheon/force_delete_cni_netreg
Attempt manual removal of CNI IP allocations on refresh
2020-03-23 12:04:38 +01:00
Miloslav Trmač 8153ea358a Make libpod/lock/shm completely Linux-only
If the tests are not Linux-only, (go test ./...) still tries
to build and test the package.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-03-21 00:21:59 +01:00
Miloslav Trmač c6277e7433 Add a stub for libpod.Container.Top
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-03-21 00:21:59 +01:00
Miloslav Trmač 054addf7ac Fix the libpod.LabelVolumePath stub
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-03-21 00:21:59 +01:00
Matthew Heon b6954758bb Attempt manual removal of CNI IP allocations on refresh
We previously attempted to work within CNI to do this, without
success. So let's do it manually, instead. We know where the
files should live, so we can remove them ourselves instead. This
solves issues around sudden reboots where containers do not have
time to fully tear themselves down, and leave IP address
allocations which, for various reasons, are not stored in tmpfs
and persist through reboot.

Fixes #5433

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-03-19 17:20:31 -04:00
OpenShift Merge Robot aa6c8c2e55
Merge pull request #5088 from mheon/begin_exec_rework
Begin exec rework
2020-03-19 22:09:40 +01:00
OpenShift Merge Robot 1be6178915
Merge pull request #5445 from sujil02/podFilter-new
Filter pods through pod list api
2020-03-19 15:50:50 +01:00
OpenShift Merge Robot 45e7cbfef6
Merge pull request #5480 from vrothberg/auto-updates
auto update containers in systemd units
2020-03-18 18:27:33 +01:00
Matthew Heon e89c6382ae Add inspect for exec sessions
This produces detailed information about the configuration of an
exec session in a format suitable for the new HTTP API.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-03-18 11:02:14 -04:00
Matthew Heon 118e78c5d6 Add structure for new exec session tracking to DB
As part of the rework of exec sessions, we need to address them
independently of containers. In the new API, we need to be able
to fetch them by their ID, regardless of what container they are
associated with. Unfortunately, our existing exec sessions are
tied to individual containers; there's no way to tell what
container a session belongs to and retrieve it without getting
every exec session for every container.

This adds a pointer to the container an exec session is
associated with to the database. The sessions themselves are
still stored in the container.

Exec-related APIs have been restructured to work with the new
database representation. The originally monolithic API has been
split into a number of smaller calls to allow more fine-grained
control of lifecycle. Support for legacy exec sessions has been
retained, but in a deprecated fashion; we should remove this in
a few releases.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-03-18 11:02:14 -04:00
Matthew Heon f138405b46 Populate ExecSession with all required fields
As part of the rework of exec sessions, we want to split Create
and Start - and, as a result, we need to keep everything needed
to start exec sessions in the struct, not just the bare minimum
for tracking running ones.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-03-18 11:02:14 -04:00
OpenShift Merge Robot f08b992f3b
Merge pull request #5536 from giuseppe/avoid-conmon-zombie
podman: avoid conmon zombie on exec
2020-03-18 15:10:41 +01:00
Giuseppe Scrivano a6f5b6a485
podman: avoid conmon zombie on exec
conmon forks itself, so make sure we reap the first process and not
leave a zombie process.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-18 12:58:14 +01:00
Sujil02 15326f051d Filter pods through pod list api
Refactored current filter pods flow through the shared pod functions
so filter pod functionalities can be shared between api and cmd.

Signed-off-by: Sujil02 <sushah@redhat.com>
2020-03-17 17:46:20 -04:00
Valentin Rothberg f4e873c4e1 auto updates
Add support to auto-update containers running in systemd units as
generated with `podman generate systemd --new`.

`podman auto-update` looks up containers with a specified
"io.containers.autoupdate" label (i.e., the auto-update policy).

If the label is present and set to "image", Podman reaches out to the
corresponding registry to check if the image has been updated.  We
consider an image to be updated if the digest in the local storage is
different than the one of the remote image.  If an image must be
updated, Podman pulls it down and restarts the container.  Note that the
restarting sequence relies on systemd.

At container-creation time, Podman looks up the "PODMAN_SYSTEMD_UNIT"
environment variables and stores it verbatim in the container's label.
This variable is now set by all systemd units generated by
`podman-generate-systemd` and is set to `%n` (i.e., the name of systemd
unit starting the container).  This data is then being used in the
auto-update sequence to instruct systemd (via DBUS) to restart the unit
and hence to restart the container.

Note that this implementation of auto-updates relies on systemd and
requires a fully-qualified image reference to be used to create the
container.  This enforcement is necessary to know which image to
actually check and pull.  If we used an image ID, we would not know
which image to check/pull anymore.

Fixes: #3575
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-03-17 17:18:56 +01:00
OpenShift Merge Robot 9ef5d28759
Merge pull request #5449 from baude/manifests
apiv2 addition of manifests
2020-03-17 16:00:05 +01:00
Valentin Rothberg a255d7986a pkg/systemd: add dbus support
Move the dbus-connection code from libpod's healthcheck to pkg/systemd
to allow for sharing the logic.  Needed for the auto-updates work.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-03-17 11:29:37 +01:00
Giuseppe Scrivano cc57b88f77
config: make warning clearer
make clearer that the warning could also happen because the logger is
set to use systemd.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-17 10:31:32 +01:00
Brent Baude abbbeacd68 apiv2 addition of manifests
add endpoints for create, add, remove, inspect, and push.  this allows manifests to be managed through the restful interfaces.

also added go-bindings and tests

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-03-16 10:03:55 -05:00
OpenShift Merge Robot 5288d112bc
Merge pull request #5252 from QiWang19/not-reset-tempdir
Fix bug podman reset to not remove $XDG_RUNTIME_DIR
2020-03-16 13:48:36 +01:00
OpenShift Merge Robot 235f367861
Merge pull request #5469 from giuseppe/no-size-create-container
create: do not calculate image size
2020-03-12 10:20:02 -04:00
Giuseppe Scrivano 8741eb8a92
create: do not calculate image size
calculating the image size can be an expensive operation.  Avoid doing
it when creating a new container since the size is not needed.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-03-12 09:51:17 +01:00
Abhijeet Kasurde eb2d0a2289 Follow up changes from #5244
Code review change suggested by jwhonce in

https://github.com/containers/libpod/pull/5244#pullrequestreview-366574431

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2020-03-12 10:06:51 +05:30
Valentin Rothberg 450361fc64 update systemd & dbus dependencies
Update the outdated systemd and dbus dependencies which are now provided
as go modules.  This will further tighten our dependencies and releases
and pave the way for the upcoming auto-update feature.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-03-10 18:34:55 +01:00
OpenShift Merge Robot 3d48940927
Merge pull request #5307 from QiWang19/security-opt-genkube
fix security-opt generate kube
2020-03-09 22:22:29 +01:00
Matthew Heon 521ff14d83 Revert "exec: get the exit code from sync pipe instead of file"
This reverts commit 4b72f9e401.

Continues what began with revert of
d3d97a25e8 in previous commit.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-03-09 09:50:55 -04:00
Matthew Heon ffce869daa Revert "Exec: use ErrorConmonRead"
This reverts commit d3d97a25e8.

This does not resolve the issues we expected it would, and has
some unexpected side effects with the upcoming exec rework.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-03-09 09:50:40 -04:00
Matthew Heon 6be87b2186 Revert "exec: fix error code when conmon fails"
This reverts commit 4632b81c81.

We are reverting #5373 as well, which lays the foundation for
this commit, so it has to go as well.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-03-09 09:25:56 -04:00
OpenShift Merge Robot f378e82e2d
Merge pull request #5412 from rhatdan/tmpdir
Allow users to set TMPDIR environment
2020-03-08 17:03:59 +01:00
Daniel J Walsh ac354ac94a
Fix spelling mistakes in code found by codespell
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-07 10:30:44 -05:00
Brent Baude 8b5e2a6297 add default network for apiv2 create
during container creation, if no network is provided, we need to add a default value so the container can be later started.

use apiv2 container creation for RunTopContainer instead of an exec to the system podman. RunTopContainer now also returns the container id and an error.

added a libpod commit endpoint.

also, changed the use of the connections and bindings slightly to make it more convenient to write tests.

Fixes: 5366
Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-03-06 14:31:45 -06:00
Dan Williams 74ddc0b696 vendor: update github.com/containernetworking/cni to v0.7.2-0.20200304161608-4fae32b84921
Specifically to get:

https://github.com/containernetworking/cni/pull/735
6f29b0165883b2b52ccd4dcb937162ea4c86927b intercept netplugin std err

But also pulls in some interface name validation and a compatibility
fix for configurations that don't set a CNI version.

Signed-off-by: Dan Williams <dcbw@redhat.com>
2020-03-06 10:03:27 -06:00
Daniel J Walsh cb51707f91
Allow users to set TMPDIR environment
Some users have small /var/tmp directories and need to be able to specify a different location
for temporary files, which includes more space.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-06 10:21:37 -05:00
Valentin Rothberg 593eb7625a golangci: enable goimports
Enable the goimports linter and fix reports.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-03-05 20:03:44 +01:00
Qi Wang d4540e07c7 Fix bug podman reset to not remove $XDG_RUNTIME_DIR
In some older systems we point the temporary directory to /run/user/1000 which leads podman system reset to clear unrelated files under XDG_RUNTIME_DIR. This patch only removes files created by podman if TmpDir is the  same as the XDG_RUNTIME_DIR.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-03-05 09:21:41 -05:00
Peter Hunt 4632b81c81 exec: fix error code when conmon fails
this is a cosmetic change that makes sure podman returns a sane error code when conmon dies underneath it

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2020-03-04 17:10:14 -05:00
Peter Hunt d3d97a25e8 Exec: use ErrorConmonRead
Before, we were using -1 as a bogus value in podman to signify something went wrong when reading from a conmon pipe. However, conmon uses negative values to indicate the runtime failed, and return the runtime's exit code.

instead, we should use a bogus value that is actually bogus. Define that value in the define package as MinInt32 (-1<< 31 - 1), which is outside of the range of possible pids (-1 << 31)

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2020-03-03 15:43:31 -05:00
Peter Hunt 4b72f9e401 exec: get the exit code from sync pipe instead of file
Before, we were getting the exit code from the file, in which we waited an arbitrary amount of time (5 seconds) for the file, and segfaulted if we didn't find it. instead, we should be a bit more certain conmon has sent the exit code. Luckily, it sends the exit code along the sync pipe fd, so we can read it from there

Adapt the ExecContainer interface to pass along a channel to get the pid and exit code from conmon, to be able to read both from the pipe

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2020-03-03 15:35:35 -05:00
Qi Wang 17bab33bd2 fix security-opt generate kube
fix #4950
add selinux options from --security-opt of the container to generate kube result

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-03-03 11:21:14 -05:00
OpenShift Merge Robot 3bc5f431d4
Merge pull request #5206 from rhatdan/capabilities
Allow devs to set labels in container images for default capabilities.
2020-03-03 14:48:10 +01:00
OpenShift Merge Robot 873d64fd6b
Merge pull request #5363 from mheon/add_ctr_validate
Add validate() for containers
2020-03-02 23:52:21 +01:00
Daniel J Walsh b163640c61
Allow devs to set labels in container images for default capabilities.
This patch allows users to specify the list of capabilities required
to run their container image.

Setting a image/container label "io.containers.capabilities=setuid,setgid"
tells podman that the contained image should work fine with just these two
capabilties, instead of running with the default capabilities, podman will
launch the container with just these capabilties.

If the user or image specified capabilities that are not in the default set,
the container will print an error message and will continue to run with the
default capabilities.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-03-02 16:37:32 -05:00
OpenShift Merge Robot 47c4ea3919
Merge pull request #5347 from baude/apiv2wait
rework apiv2 wait endpoint|binding
2020-03-02 20:23:26 +01:00
Matthew Heon e45456223c Add validate() for containers
Until now, we've been validating every part of container
configuration through the With... functions that set the options.
This if fine when we are just validating the options to an
individual function, but things get complicated once we need to
validate conflicts between different options. We don't know the
order in which things were passed, so we need the validation on
both of the potential options that can conflict, resulting in
significant code duplication. To solve this, add a validate()
function for containers, and use this to check whether everything
is in a good state.

We can probably move more into this function (there are other
parts of container creation that also do validation of a sort)
but this is a good start to simplifying our options.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-03-02 10:58:11 -05:00
OpenShift Merge Robot 86ed329ad1
Merge pull request #5320 from sujil02/podtest
Add test to validate prune pod apiv2 binding.
2020-03-02 16:34:40 +01:00
OpenShift Merge Robot 742093c2f2
Merge pull request #5349 from mheon/ensure_exec_suppgroups
Ensure that exec sessions inherit supplemental groups
2020-02-28 20:18:13 +01:00
OpenShift Merge Robot a58bf77d3e
Merge pull request #5244 from Akasurde/i4962
Add cmd flag to show container name in log
2020-02-28 18:55:58 +01:00
Sujil02 bbda410526 Update pod bindings and Add test to validate prune pod apiv2 binding.
Modify the pod inspect bindings to hold current pod status.
Includes test to validate on pod status and added test to check
no or few pods are pruned,if the pods are in exited state.

Signed-off-by: Sujil02 <sushah@redhat.com>
2020-02-28 11:51:02 -05:00
Matthew Heon b41c864d56 Ensure that exec sessions inherit supplemental groups
This corrects a regression from Podman 1.4.x where container exec
sessions inherited supplemental groups from the container, iff
the exec session did not specify a user.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-02-28 11:32:56 -05:00
Brent Baude 0904873100 rework apiv2 wait endpoint|binding
added the ability to wait on a condition (stopped, running, paused...) for a container.  if a condition is not provided, wait will default to the stopped condition which uses the original wait code paths.  if the condition is stopped, the container exit code will be returned.

also, correct a mux issue we discovered.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-28 09:36:53 -06:00
Brent Baude 306b44380f binding tests for volumes
add binding tests for volumes: inspect(get), create, remove, prune, and list

implement filters ability for volumes

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-27 13:11:42 -06:00
Matthew Heon f9fc9a7b7b Add support for multiple CNI networks in podman inspect
When inspecting containers, info on CNI networks added to the
container by name (e.g. --net=name1) should be displayed
separately from the configuration of the default network, in a
separate map called Networks.

This patch adds this separation, improving our Docker
compatibility and also adding the ability to see if a container
has more than one IPv4 and IPv6 address and more than one MAC
address.

Fixes #4907

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-02-25 13:20:25 -05:00
Matthew Heon 4004f646cd Add basic deadlock detection for container start/remove
We can easily tell if we're going to deadlock by comparing lock
IDs before actually taking the lock. Add a few checks for this in
common places where deadlocks might occur.

This does not yet cover pod operations, where detection is more
difficult (and costly) due to the number of locks being involved
being higher than 2.

Also, add some error wrapping on the Podman side, so we can tell
people to use `system renumber` when it occurs.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-02-24 09:29:34 -05:00
OpenShift Merge Robot 75ea3b67c6
Merge pull request #5213 from mheon/remove_db_imagevol
Remove ImageVolumes from database
2020-02-21 13:25:59 -05:00
OpenShift Merge Robot 5bdf5aeb71
Merge pull request #5263 from baude/logsize
implement reverse reader for log reads
2020-02-21 13:12:21 -05:00
OpenShift Merge Robot a554e97adc
Merge pull request #5236 from marusak/filter_by_id
apiv2: Image filtering and fixup docs
2020-02-21 12:17:38 -05:00
Matthew Heon e3a549b7b1 Remove ImageVolumes from database
Before Libpod supported named volumes, we approximated image
volumes by bind-mounting in per-container temporary directories.
This was handled by Libpod, and had a corresponding database
entry to enable/disable it.

However, when we enabled named volumes, we completely rewrote the
old implementation; none of the old bind mount implementation
still exists, save one flag in the database. With nothing
remaining to use it, it has no further purpose.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-02-21 09:37:30 -05:00
OpenShift Merge Robot 4f5b40598f
Merge pull request #5271 from baude/dnsnameuserns
populate resolv.conf with dnsname responses when in usernamespace
2020-02-21 08:55:27 -05:00
Brent Baude e3b31a3ab8 implement reverse reader for log reads
in cases where the log file exceeds the available memory of a system, we had a bug that triggered an oom because the entire logfile was being read when the tail parameter was given.  this reads in chunks and is more or less memory safe.

fixes: #5131

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-20 10:22:45 -06:00
Ed Santiago 29930fae70 podman images: add --filter=since=XX
Looks like a bit of a misunderstanding from early on.

Docker implements --filter=since=IMAGE. Podman implements 'after'
instead of 'since'. Add an equivalent case statement to handle
both, keeping 'after' because we have no way of knowing if it
is used in the field.

Update documentation ... and fix what looks like a complete
misinterpretation of what the code actually does: the man page
claimed that these were time fields, but I don't see any
possible incantation in which a time value works or could
work. Updated docs to reflect IMAGE usage. Also changed
nonworking '==' to single '='.

Added tests. [UPDATE: skip with broken podman-remote]

Fixes: #5040

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-02-20 07:55:29 -07:00
Brent Baude 921f29c902 populate resolv.conf with dnsname responses when in usernamespace
when using usernamespace, dnsname respondes from cni were not making it into the containers /etc/resolv.conf because of a timing issue.  this corrects that behavior.

Fixes: #5256

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-20 08:00:40 -06:00
OpenShift Merge Robot 846405256b
Merge pull request #5241 from mheon/pod_network_opts_add
Add network opts to pods
2020-02-20 10:39:15 +01:00
Matthew Heon 97323808ed Add network options to podman pod create
Enables most of the network-related functionality from
`podman run` in `podman pod create`. Custom CNI networks can be
specified, host networking is supported, DNS options can be
configured.

Also enables host networking in `podman play kube`.

Fixes #2808
Fixes #3837
Fixes #4432
Fixes #4718
Fixes #4770

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-02-19 11:29:30 -05:00
Abhijeet Kasurde 7f411cb325 Review comments
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2020-02-19 17:14:20 +05:30
Abhijeet Kasurde 88a8d9e3fa [WIP] Add cmd flag to show container name in log
This flag allows user to show container name in podman log command

Fixes: #4962

Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2020-02-19 16:58:04 +05:30
Valentin Rothberg b7b9f8d0cf libpod/config: use built-in TOML instead of manually merging
Instead of manually merging the configs, use the built-in features of
TOMP to merge/extend the fields of a data type when encoding a file.
This erases the need for the merge code in libpod/config and also
addresses issues when merging booleans.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-02-19 11:04:02 +01:00
OpenShift Merge Robot c58926e54b
Merge pull request #5243 from Akasurde/misc_typo
Misc typo fixes
2020-02-18 21:58:14 +01:00
Giuseppe Scrivano 170fd7b038
rootless: fix a regression when using -d
when using -d and port mapping, make sure the correct fd is injected
into conmon.

Move the pipe creation earlier as the fd must be known at the time we
create the container through conmon.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-02-18 15:33:38 +01:00
Abhijeet Kasurde 9419807cef Misc typo fixes
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
2020-02-18 16:00:36 +05:30
Matthew Heon 666d8cf1de Add ability for pods to use the host network
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-02-17 16:21:07 -05:00
Matej Marusak d08e0c728f apiv2: Enable filtering images by ID
It is more practical for API usage and also it is more in sync how
filtering of containers works.

Signed-off-by: Matej Marusak <mmarusak@redhat.com>
2020-02-17 18:44:46 +01:00
Sascha Grunert 93358ef915
Refactor image tree for API usage
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-02-17 11:12:35 +01:00
OpenShift Merge Robot 3e0088ce7c
Merge pull request #5207 from rhatdan/selinux
Fix SELinux labels of volumes
2020-02-14 20:49:45 +01:00
Valentin Rothberg 156ce5cd7d add pkg/capabilities
Add pkg/capabibilities to deal with capabilities.  The code has been
copied from Docker (and attributed with the copyright) but changed
significantly to only do what we really need.  The code has also been
simplified and will perform better due to removed redundancy.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-02-14 12:00:45 +01:00
Daniel J Walsh b4fa6f4f08
Fix SELinux labels of volumes
If we attempt to label a volume and the file system
does not support labeling, then just warn.  SELinux
may or may not work, on the volume.

There is no way to setup a private label on a newly
created volume without using the container mountlabel.

If we don't have a mount label at the time of creation of
the volume, the only option we have is to create a shared
label.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-02-13 21:42:57 -05:00
OpenShift Merge Robot cd9e6b4143
Merge pull request #5172 from giuseppe/api-fix-cpu-stats
api: fix the CPU stats reported
2020-02-13 15:42:53 +01:00
Brent Baude 2aacfade75 use quay.io/libpod/fedora-minimal for reliability
Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-02-12 16:45:03 -06:00
Matthew Heon c140ecdc9b Do not copy up when volume is not empty
When Docker performs a copy up, it first verifies that the volume
being copied into is empty; thus, for volumes that have been
modified elsewhere (e.g. manually copying into then), the copy up
will not be performed at all. Duplicate this behavior in Podman
by checking if the volume is empty before copying.

Furthermore, move setting copyup to false further up. This will
prevent a potential race where copy up could happen more than
once if Podman was killed after some files had been copied but
before the DB was updated.

This resolves CVE-2020-1726.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-02-12 10:58:42 -05:00
Giuseppe Scrivano 6215e1bb21
api: fix the CPU stats reported
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-02-11 22:24:14 +01:00
OpenShift Merge Robot 5f34b2150b
Merge pull request #5122 from mtrmac/image-object-creation
Simplify image object creation
2020-02-10 14:28:40 +01:00
OpenShift Merge Robot e2a01603f2
Merge pull request #5064 from mheon/pod_network_opts
Add backend code for pod network options
2020-02-10 14:07:04 +01:00
Miloslav Trmač dafd212870 Modify Runtime.getImage to return a storage.Image
... because both callers only care about that aspect of the
return value.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-02-07 23:36:01 +01:00
Miloslav Trmač 5b5bacbd95 Document an aspect of newFromStorage behavior
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-02-07 23:36:01 +01:00
Miloslav Trmač 972df82632 Introduce a Runtime.newImage constructor
... so that _all_ Image objects are created in a single place
that is easy to update.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-02-07 23:36:01 +01:00
Miloslav Trmač 933edf4a37 Move Image.getLocalImage to Runtime.getLocalImage
Instead of the function updating image.InputName (the only reason for it
to need an image), have it return the updated value separately.

This will allow simplifying the constructors of Image further.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-02-07 23:36:01 +01:00
Miloslav Trmač 1ab4038807 Remove the getLocalImage() call from Image.Size
All ways to create an Image{} have a non-nil .image field, and it
is never set to nil, so this is dead code.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-02-07 23:36:01 +01:00
Miloslav Trmač ede412f40f Use Runtime.NewFromLocal instead of open-coded copies
All code creating an Image by looking up a name now uses
Runtime.NewFromLocal.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-02-07 23:36:01 +01:00
Miloslav Trmač a433b858d2 Trivial simplification
Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-02-07 23:36:01 +01:00
Miloslav Trmač d9bfaf5197 Create two separate newImage instances in Runtime.New
This is not _trivially_ safe because newImage.getLocalImage()
modifies newImage.ImageName, but we overwrite that value anyway.

So, this should not change behavior, and it will make future refactoring
easier to verify.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-02-07 23:36:01 +01:00
Miloslav Trmač 0f0bac4ab3 Call NewImageRuntimeFromStore from NewImageRuntimeFromOptions
... so that there ultimately is only one constructor.

Should not change behavior.

Signed-off-by: Miloslav Trmač <mitr@redhat.com>
2020-02-07 23:36:00 +01:00
Matthew Heon eed2ad9ef2 Only modify conmon cgroup if we have running containers
If there are no running containers - for example, if the pod was
just created - the cgroup in question may not exist (under
certain circumstances that we're not 100% sure about). However,
regardless, we don't need to set a PID limit, as nothing will be
making cleanup processes (no running conmon processes), so not
changing the cgroup is safe regardless.

Fixes #5072

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-02-06 10:20:54 -05:00
OpenShift Merge Robot fb8c49479e
Merge pull request #5052 from mheon/cleanup_net_on_restart
Tear down network when restarting containers
2020-02-05 00:59:07 -08:00
OpenShift Merge Robot 5092c078ec
Merge pull request #5085 from rhatdan/close
Close tarSource when finished using it
2020-02-04 13:57:43 -08:00
OpenShift Merge Robot fac8318cb0
Merge pull request #5082 from baude/spec
[CI:DOCS] Spec proposal
2020-02-04 12:33:33 -08:00
Daniel J Walsh 03faf97aa0
Close tarSource when finished using it
Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1797599

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-02-04 13:12:06 -05:00
Matthew Heon 07a8ab09e0 Add backend code for pod network options
This adds network-related options to the pod in the database. We
are going to add the CLI frontend in further patches.

In short, this should greatly improve the ability of pods to
configure networking, once the CLI parsing is added.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-02-04 10:07:14 -05:00
Matthew Heon 4567f39800 Initial implementation of a spec generator package
The current Libpod pkg/spec has become a victim of the better
part of three years of development that tied it extremely closely
to the current Podman CLI. Defaults are spread across multiple
places, there is no easy way to produce a CreateConfig that will
actually produce a valid container, and the logic for generating
configs has sprawled across at least three packages.

This is an initial pass at a package that generates OCI specs
that will supersede large parts of the current pkg/spec. The
CreateConfig will still exist, but will effectively turn into a
parsed CLI. This will be compiled down into the new SpecGenerator
struct, which will generate the OCI spec and Libpod create
options.

The preferred integration point for plugging into Podman's Go API
to create containers will be the new CreateConfig, as it's less
tied to Podman's command line. CRI-O, for example, will likely
tie in here.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-02-04 08:10:23 -06:00
Sascha Grunert b8a2818e70
Wrap error for failing ImageSize calls
Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-02-04 14:21:59 +01:00
Matthew Heon 6d487c781a Tear down network when restarting containers
This makes restart a bit slower for root containers, but it does
make it more consistent with `podman stop` and `podman start` on
a container. Importantly, `podman restart` will now recreate
firewall rules if they were somehow purged.

Fixes #5051

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-02-02 12:51:03 -05:00
Matthew Heon 5d93c731af Deprecate & remove IsCtrSpecific in favor of IsAnon
In Podman 1.6.3, we added support for anonymous volumes - fixing
our old, broken support for named volumes that were created with
containers. Unfortunately, this reused the database field we used
for the old implementation, and toggled volume removal on for
`podman run --rm` - so now, we were removing *named* volumes
created with older versions of Podman.

We can't modify these old volumes in the DB, so the next-safest
thing to do is swap to a new field to indicate volumes should be
removed. Problem: Volumes created with 1.6.3 and up until this
lands, even anonymous volumes, will not be removed. However, this
is safer than removing too many volumes, as we were doing before.

Fixes #5009

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-01-29 14:04:51 -05:00
Valentin Rothberg c9fb6d1668 history: fix size computing
Get the layer's size whether it relates to the first history entry or
not.  This fixes issues where the first entry would always be shown
to be of size 0.

Fixes: #4916
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-29 14:54:24 +01:00
Brent Baude 31a1f44fe6 honor pull policy in play kube
When a container specification has a pull policy, we should honor it when recreating the pods/containers from yaml.  furthermore, ini kube, if a tag is :latest, then the always pull policy is automatically instituted.

Fixes: #4880

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-01-28 13:36:10 -06:00
Brent Baude 6181faa90d inspect image healthchecks
when a docker image has a defined healthcheck, it should be displayed with inspect.  this is only valid for docker images as oci images are not aware of healthchecks.

Fixes: #4799
Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-01-27 08:36:25 -06:00
OpenShift Merge Robot d07f611885
Merge pull request #4965 from baude/reviewcorrections3
APIv2 review corrections #3
2020-01-25 23:23:39 -08:00
OpenShift Merge Robot c1e2698f81
Merge pull request #4952 from mheon/inspect_default_shares
Default CPUShares in Inspect are 1024
2020-01-25 23:12:57 -08:00
Brent Baude 5da70b04dd APIv2 review corrections #3
The third pass of corrections for the APIv2.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-01-25 15:09:09 -06:00
Brent Baude cf7be58b2c Review corrections pass #2
Add API review comments to correct documentation and endpoints.  Also, add a libpode prune method to reduce code duplication.  Only used right now for the API but when the remote client is wired, we will switch over there too.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-01-23 11:58:26 -06:00
Matthew Heon eb229d526c Default CPUShares in Inspect are 1024
This is purely a display change - we weren't initializing the
default value to display for the CPUShares field, which defaults
to 1024.

Fixes #4822

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-01-23 09:46:11 -05:00
OpenShift Merge Robot 9f146b1b54
Merge pull request #4861 from giuseppe/add-cgroups-disabled-conmon
oci_conmon: do not create a cgroup under systemd
2020-01-22 17:00:48 +01:00
Giuseppe Scrivano 1951ff168a
oci_conmon: do not create a cgroup under systemd
Detect whether we are running under systemd (if the INVOCATION_ID is
set).  If Podman is running under a systemd service, we do not need to
create a cgroup for conmon.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-01-16 20:29:28 +01:00
Matthew Heon ac47e80b07 Add an API for Attach over HTTP API
The new APIv2 branch provides an HTTP-based remote API to Podman.
The requirements of this are, unfortunately, incompatible with
the existing Attach API. For non-terminal attach, we need append
a header to what was copied from the container, to multiplex
STDOUT and STDERR; to do this with the old API, we'd need to copy
into an intermediate buffer first, to handle the headers.

To avoid this, provide a new API to handle all aspects of
terminal and non-terminal attach, including closing the hijacked
HTTP connection. This might be a bit too specific, but for now,
it seems to be the simplest approach.

At the same time, add a Resize endpoint. This needs to be a
separate endpoint, so our existing channel approach does not work
here.

I wanted to rework the rest of attach at the same time (some
parts of it, particularly how we start the Attach session and how
we do resizing, are (in my opinion) handled much better here.
That may still be on the table, but I wanted to avoid breaking
existing APIs in this already massive change.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-01-16 13:49:21 -05:00
Giuseppe Scrivano ba0a6f34e3
podman: add new option --cgroups=no-conmon
it allows to disable cgroups creation only for the conmon process.

A new cgroup is created for the container payload.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-01-16 18:56:51 +01:00
Valentin Rothberg 9d54815c26 refactor top code
Move the top logic from pkg/adapter into the (*libpod.Container).Top().
This way, we drop the dependency from pkg/api on pkg/adapters and have
a clearer separation of concerns.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-15 17:08:22 +01:00
OpenShift Merge Robot d914cc231a
Merge pull request #4859 from giuseppe/not-change-permission-for-rundir-tmpdir
oci_conmon: not make accessible dirs if not needed
2020-01-15 12:45:15 +01:00
Giuseppe Scrivano 68185048cf
oci_conmon: not make accessible dirs if not needed
do not change the permissions mask for the rundir and the tmpdir when
running a container with a user namespace and the current user is
mapped inside the user namespace.

The change was introduced with
849548ffb8, that dropped the
intermediate mount namespace in favor of allowing root into the user
namespace to access these directories.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-01-14 14:45:14 +01:00
Valentin Rothberg cf1f3191d2 make lint: include unit tests
Include the unit tests (i.e., _test.go files) for linting to make the
tests more robust and enforce the linters' coding styles etc.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-14 10:51:59 +01:00
OpenShift Merge Robot 796ae87b1a
Merge pull request #4850 from vrothberg/fix-linting
Fix linting
2020-01-13 21:03:21 +01:00
OpenShift Merge Robot c1d93666d4
Merge pull request #4853 from mheon/do_not_configure_with_slirp
Do not configure CNI when slirp4netns is requested
2020-01-13 20:51:38 +01:00
OpenShift Merge Robot e83a1b87da
Merge pull request #4817 from rhatdan/codespell
Add codespell to validate spelling mistakes in code.
2020-01-13 17:59:58 +01:00
Matthew Heon 6e2ed9ad2e Do not configure CNI when slirp4netns is requested
Our networking code bakes in a lot of assumptions about how
networking should work - that CNI is *always* used with root, and
that slirp4netns is *always* used only with rootless. These are
not safe assumptions. This fixes one particular issue, which
would cause CNI to also be run when slirp4netns was requested as
root.

Fixes: #4687

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-01-13 11:19:31 -05:00
Valentin Rothberg 67165b7675 make lint: enable gocritic
`gocritic` is a powerful linter that helps in preventing certain kinds
of errors as well as enforcing a coding style.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-13 14:27:02 +01:00
OpenShift Merge Robot 9e2e4d7615
Merge pull request #4694 from openSUSE/history-names-in-inspect
Add history names to image inspect data
2020-01-13 08:52:13 +01:00
Daniel J Walsh 4093b2c011
Add codespell to validate spelling mistakes in code.
Fix all errors found by codespell

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-01-11 06:32:19 -05:00
OpenShift Merge Robot 0e9c208d3f
Merge pull request #4805 from giuseppe/log-tag
log: support --log-opt tag=
2020-01-10 23:55:45 +01:00
baude 986feef2e8 fix e2e test failure
it is possible for layers.names to be nil and we must account for that.

Signed-off-by: baude <bbaude@redhat.com>
2020-01-10 13:06:26 -06:00
baude c3956b1974 address review comments before merge
Signed-off-by: baude <bbaude@redhat.com>
2020-01-10 09:47:19 -06:00
Jhon Honce d924494f56 Initial commit on compatible API
Signed-off-by: Jhon Honce <jhonce@redhat.com>

Create service command

Use cd cmd/service && go build .

$ systemd-socket-activate -l 8081 cmd/service/service &
$ curl http://localhost:8081/v1.24/images/json

Signed-off-by: Jhon Honce <jhonce@redhat.com>

Correct Makefile

Signed-off-by: Jhon Honce <jhonce@redhat.com>

Two more stragglers

Signed-off-by: Jhon Honce <jhonce@redhat.com>

Report errors back as http headers

Signed-off-by: Jhon Honce <jhonce@redhat.com>

Split out handlers, updated output

Output aligned to docker structures

Signed-off-by: Jhon Honce <jhonce@redhat.com>

Refactored routing, added more endpoints and types

* Encapsulated all the routing information in the handler_* files.
* Added more serviceapi/types, including podman additions. See Info

Signed-off-by: Jhon Honce <jhonce@redhat.com>

Cleaned up code, implemented info content

* Move Content-Type check into serviceHandler
* Custom 404 handler showing the url, mostly for debugging
* Refactored images: better method names and explicit http codes
* Added content to /info
* Added podman fields to Info struct
* Added Container struct

Signed-off-by: Jhon Honce <jhonce@redhat.com>

Add a bunch of endpoints

containers: stop, pause, unpause, wait, rm
images: tag, rmi, create (pull only)

Signed-off-by: baude <bbaude@redhat.com>

Add even more handlers

* Add serviceapi/Error() to improve error handling
* Better support for API return payloads
* Renamed unimplemented to unsupported these are generic endpoints
  we don't intend to ever support.  Swarm broken out since it uses
  different HTTP codes to signal that the node is not in a swarm.
* Added more types
* API Version broken out so it can be validated in the future

Signed-off-by: Jhon Honce <jhonce@redhat.com>

Refactor to introduce ServiceWriter

Signed-off-by: Jhon Honce <jhonce@redhat.com>

populate pods endpoints

/libpod/pods/..

exists, kill, pause, prune, restart, remove, start, stop, unpause

Signed-off-by: baude <bbaude@redhat.com>

Add components to Version, fix Error body

Signed-off-by: Jhon Honce <jhonce@redhat.com>

Add images pull output, fix swarm routes

* docker-py tests/integration/api_client_test.py pass 100%
* docker-py tests/integration/api_image_test.py pass 4/16
+ Test failures include services podman does not support

Signed-off-by: Jhon Honce <jhonce@redhat.com>

pods endpoint submission 2

add create and others; only top and stats is left.

Signed-off-by: baude <bbaude@redhat.com>

Update pull image to work from empty registry

Signed-off-by: Jhon Honce <jhonce@redhat.com>

pod create and container create

first pass at pod and container create.  the container create does not
quite work yet but it is very close.  pod create needs a partial
rewrite.  also broken off the DELETE (rm/rmi) to specific handler funcs.

Signed-off-by: baude <bbaude@redhat.com>

Add docker-py demos, GET .../containers/json

* Update serviceapi/types to reflect libpod not podman
* Refactored removeImage() to provide non-streaming return

Signed-off-by: Jhon Honce <jhonce@redhat.com>

create container part2

finished minimal config needed for create container.  started demo.py
for upcoming talk

Signed-off-by: baude <bbaude@redhat.com>

Stop server after honoring request

* Remove casting for method calls
* Improve WriteResponse()
* Update Container API type to match docker API

Signed-off-by: Jhon Honce <jhonce@redhat.com>

fix namespace assumptions

cleaned up namespace issues with libpod.

Signed-off-by: baude <bbaude@redhat.com>

wip

Signed-off-by: baude <bbaude@redhat.com>

Add sliding window when shutting down server

* Added a Timeout rather than closing down service on each call
* Added gorilla/schema dependency for Decode'ing query parameters
* Improved error handling
* Container logs returned and multiplexed for stdout and stderr
  * .../containers/{name}/logs?stdout=True&stderr=True
* Container stats
  * .../containers/{name}/stats

Signed-off-by: Jhon Honce <jhonce@redhat.com>

Improve error handling

* Add check for at least one std stream required for /containers/{id}/logs
* Add check for state in /containers/{id}/top
* Fill in more fields for /info
* Fixed error checking in service start code

Signed-off-by: Jhon Honce <jhonce@redhat.com>

get rest  of image tests for pass

Signed-off-by: baude <bbaude@redhat.com>

linting our content

Signed-off-by: baude <bbaude@redhat.com>

more linting

Signed-off-by: baude <bbaude@redhat.com>

more linting

Signed-off-by: baude <bbaude@redhat.com>

pruning

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]apiv2 pods

migrate from using args in the url to using a json struct in body for
pod create.

Signed-off-by: baude <bbaude@redhat.com>

fix handler_images prune

prune's api changed slightly to deal with filters.

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]enabled base container create tests

enabling the base container create tests which allow us to get more into
the stop, kill, etc tests. many new tests now pass.

Signed-off-by: baude <bbaude@redhat.com>

serviceapi errors: append error message to API message

I dearly hope this is not breaking any other tests but debugging
"Internal Server Error" is not helpful to any user.  In case, it
breaks tests, we can rever the commit - that's why it's a small one.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>

serviceAPI: add containers/prune endpoint

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>

add `service` make target

Also remove the non-functional sub-Makefile.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>

add make targets for testing the service

 * `sudo make run-service` for running the service.

 * `DOCKERPY_TEST="tests/integration/api_container_test.py::ListContainersTest" \
 	make run-docker-py-tests`
   for running a specific tests.  Run all tests by leaving the env
   variable empty.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>

Split handlers and server packages

The files were split to help contain bloat. The api/server package will
contain all code related to the functioning of the server while
api/handlers will have all the code related to implementing the end
points.

api/server/register_* will contain the methods for registering
endpoints.  Additionally, they will have the comments for generating the
swagger spec file.

See api/handlers/version.go for a small example handler,
api/handlers/containers.go contains much more complex handlers.

Signed-off-by: Jhon Honce <jhonce@redhat.com>

[CI:DOCS]enabled more tests

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]libpod endpoints

small refactor for libpod inclusion and began adding endpoints.

Signed-off-by: baude <bbaude@redhat.com>

Implement /build and /events

* Include crypto libraries for future ssh work

Signed-off-by: Jhon Honce <jhonce@redhat.com>

[CI:DOCS]more image implementations

convert from using for to query structs among other changes including
new endpoints.

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]add bindings for golang

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]add volume endpoints for libpod

create, inspect, ls, prune, and rm

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]apiv2 healthcheck enablement

wire up container healthchecks for the api.

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]Add mount endpoints

via the api, allow ability to mount a container and list container
mounts.

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]Add search endpoint

add search endpoint with golang bindings

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]more apiv2 development

misc population of methods, etc

Signed-off-by: baude <bbaude@redhat.com>

rebase cleanup and epoch reset

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]add more network endpoints

also, add some initial error handling and convenience functions for
standard endpoints.

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]use helper funcs for bindings

use the methods developed to make writing bindings less duplicative and
easier to use.

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]add return info for prereview

begin to add return info and status codes for errors so that we can
review the apiv2

Signed-off-by: baude <bbaude@redhat.com>

[CI:DOCS]first pass at adding swagger docs for api

Signed-off-by: baude <bbaude@redhat.com>
2020-01-10 09:41:39 -06:00
Giuseppe Scrivano 71341a1948
log: support --log-opt tag=
support a custom tag to add to each log for the container.

It is currently supported only by the journald backend.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-01-10 10:35:19 +01:00
OpenShift Merge Robot 154b5ca85d
Merge pull request #4818 from haircommander/piped-exec-fix
exec: fix pipes
2020-01-09 14:01:42 +01:00
Akihiro Suda 556cc1fadf rootlessport: honor ctr.runtime.config.TmpDir
Previously, rootlessport was using /var/tmp as the tmp dir.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-01-09 14:06:33 +09:00
Peter Hunt 776eb64ab2 exec: fix pipes
In a largely anticlimatic solution to the saga of piped input from conmon, we come to this solution.

When we pass the Stdin stream to the exec.Command structure, it's immediately consumed and lost, instead of being consumed through CopyDetachable().

When we don't pass -i in, conmon is not told to create a masterfd_stdin, and won't pass anything to the container.

With both, we can do

echo hi | podman exec -til cat

and get the expected hi

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2020-01-08 11:09:08 -05:00
Valentin Rothberg 583ff5320f fix lint - ignore image.ImageDeleteResponse definition
Golint claims that image.Image stutters but renaming the type would be a
breaking change which isn't worth the consequences.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-08 15:44:30 +01:00
Valentin Rothberg 0b53ff2902 fix lint - drop else block
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-08 15:44:21 +01:00
Valentin Rothberg baba52c6b5 fix lint: add comment for NameRegex and error
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-08 13:55:14 +01:00
Valentin Rothberg 8ae672632b fix lint: correct func identifier in comment
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-08 13:52:52 +01:00
Valentin Rothberg aaec8b2408 fix lint: "guarantess" is a misspelling of "guarantees"
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-08 13:51:13 +01:00
Akihiro Suda da7595a69f rootless: use RootlessKit port forwarder
RootlessKit port forwarder has a lot of advantages over the slirp4netns port forwarder:

* Very high throughput.
  Benchmark result on Travis: socat: 5.2 Gbps, slirp4netns: 8.3 Gbps, RootlessKit: 27.3 Gbps
  (https://travis-ci.org/rootless-containers/rootlesskit/builds/597056377)

* Connections from the host are treated as 127.0.0.1 rather than 10.0.2.2 in the namespace.
  No UDP issue (#4586)

* No tcp_rmem issue (#4537)

* Probably works with IPv6. Even if not, it is trivial to support IPv6.  (#4311)

* Easily extensible for future support of SCTP

* Easily extensible for future support of `lxc-user-nic` SUID network

RootlessKit port forwarder has been already adopted as the default port forwarder by Rootless Docker/Moby,
and no issue has been reported AFAIK.

As the port forwarder is imported as a Go package, no `rootlesskit` binary is required for Podman.

Fix #4586
May-fix #4559
Fix #4537
May-fix #4311

See https://github.com/rootless-containers/rootlesskit/blob/v0.7.0/pkg/port/builtin/builtin.go

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-01-08 19:35:17 +09:00
OpenShift Merge Robot 9e03aa14b6
Merge pull request #4748 from NevilleC/nc-podname
[Issue #4703] Add the pod name when we use `podman ps -p`
2019-12-29 12:16:43 +01:00
Neville Cain 8bc394ce6e Add the pod name when we use podman ps -p
The pod name does not appear when doing `podman ps -p`.
It is missing as the documentation says:
-p, --pod              Print the ID and name of the pod the containers are associated with

The pod name is added in the ps output and checked in unit tests.

Closes #4703

Signed-off-by: NevilleC <neville.cain@qonto.eu>
2019-12-28 00:03:57 +01:00
Neville Cain 2a5c235f78 Ensure SizeRw is shown when a user does 'inspect --size -t container'.
Currently, if a user requests the size on a container (inspect --size -t container),
the SizeRw does not show up if the value is 0. It's because InspectContainerData is
defined as int64 and there is an omit when empty.

We do want to display it even if the value is empty. I have changed the type of SizeRw to be a pointer to an int64 instead of an int64. It will allow us todistinguish the empty value to the missing value.

I updated the test "podman inspect container with size" to ensure we check thatSizeRw is displayed correctly.

Closes #4744

Signed-off-by: NevilleC <neville.cain@qonto.eu>
2019-12-27 23:49:34 +01:00
baude 4f09cfdacc add struct response for removal of images
when removing an image from storage, we should return a struct that
details what was untagged vs deleted.  this replaces the simple
println's used previously and assists in API development.

Signed-off-by: baude <bbaude@redhat.com>
2019-12-23 10:02:14 -06:00
OpenShift Merge Robot e33d7e9fab
Merge pull request #4727 from rhatdan/pidns
if container is not in a pid namespace, stop all processes
2019-12-20 12:13:22 +01:00
OpenShift Merge Robot a359ca0d18
Merge pull request #4723 from mheon/pod_volume_postremove
Remove volumes after containers in pod remove
2019-12-19 19:37:00 +01:00
OpenShift Merge Robot dde48b44e7
Merge pull request #4684 from vrothberg/systemd-improvements
container config: add CreateCommand
2019-12-19 19:36:52 +01:00
Daniel J Walsh 123b8c627d
if container is not in a pid namespace, stop all processes
When a container is in a PID namespace, it is enought to send
the stop signal to the PID 1 of the namespace, only send signals
to all processes in the container when the container is not in
a pid namespace.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-12-19 13:33:17 -05:00
Matthew Heon 88917e4a93 Remove volumes after containers in pod remove
When trying to reproduce #4704 I noticed that the named volumes
from the Postgres containers in the reproducer weren't being
removed by `podman pod rm -f` saying that the container they were
attached to was still in use. This was rather odd, considering
they were only in use by one container, and that container was in
the process of being removed with the pod.

After a bit of tracing, I realized that the cause is the ordering
of container removal when we remove a pod. Normally, it's done
in removeContainer() before volume removal (which is the last
thing in that function). However, when we are removing a pod, we
remove containers all at once, after removeContainer has already
finished - meaning the container still exists when we try to
remove its volumes, and thus the volume can't be removed.

Solution: collect a list of all named volumes in use by the pod,
and remove them all at once after every container in the pod is
gone. This ensures that there are no dependency issues.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-12-17 21:41:31 -05:00
OpenShift Merge Robot e6b843312b
Merge pull request #4643 from adrianreber/master
Correctly export the root file-system changes
2019-12-17 18:08:36 +01:00
OpenShift Merge Robot 1e440a3a3f
Merge pull request #4681 from jvanz/issue4553
podman: mirror information
2019-12-17 14:05:15 +01:00
Matthew Heon 87194a6f79 Fix F30-F31 migration for Podman 1.7.0
The earlier attempt to re-add config migration only worked with
user-specified configs (podman run --config). This version works
more in line with that we want - the first rootless config file
will be changed from runc to crun.

Verified on my system after an F31 migration - everything seems
to be working well.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2019-12-13 13:51:39 -05:00
José Guilherme Vanz 40f4a00eb3
runtime.go: show registries data and search table
Update podman info command to show the registries data and the search
table.

Signed-off-by: José Guilherme Vanz <jvanz@jvanz.com>
2019-12-13 11:11:28 -03:00
Valentin Rothberg 437bc61f4e container config: add CreateCommand
Store the full command plus arguments of the process the container has
been created with.  Expose this data as a `Config.CreateCommand` field
in the container-inspect data as well.

This information can be useful for debugging, as we can find out which
command has created the container, and, if being created via the Podman
CLI, we know exactly with which flags the container has been created
with.

The immediate motivation for this change is to use this information for
`podman-generate-systemd` to generate systemd-service files that allow
for creating new containers (in contrast to only starting existing
ones).

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-12-13 14:39:45 +01:00
Sascha Grunert 1cdaf45d05
Add history names to image inspect data
During writing the tests I found it would be probably useful to have the
tag history part of the inspect data.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2019-12-13 13:53:30 +01:00
OpenShift Merge Robot 71a0c0f69c
Merge pull request #4692 from mheon/reap_exec_sessions
Reap exec sessions on cleanup and removal
2019-12-13 10:19:31 +01:00
José Guilherme Vanz 95d26e3f6f
runtime.go: show search table in podman info
Updates the podman info command to show registries from v1 config file
in the search table format.

Signed-off-by: José Guilherme Vanz <jvanz@jvanz.com>
2019-12-12 20:54:16 -03:00
José Guilherme Vanz 4f9672e94c
podman: mirror information
Updates the podman info command to show the mirror information

Issue https://github.com/containers/libpod/issues/4553

Signed-off-by: José Guilherme Vanz <jvanz@jvanz.com>
2019-12-12 19:53:46 -03:00
Matthew Heon bd44fd5c81 Reap exec sessions on cleanup and removal
We currently rely on exec sessions being removed from the state
by the Exec() API itself, on detecting the session stopping. This
is not a reliable method, though. The Podman frontend for exec
could be killed before the session ended, or another Podman
process could be holding the lock and prevent update (most
notable in `run --rm`, when a container with an active exec
session is stopped).

To resolve this, add a function to reap active exec sessions from
the state, and use it on cleanup (to clear sessions after the
container stops) and remove (to do the same when --rm is passed).
This is a bit more complicated than it ought to be because Kata
and company exist, and we can't guarantee the exec session has a
PID on the host, so we have to plumb this through to the OCI
runtime.

Fixes #4666

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-12-12 16:35:37 -05:00
OpenShift Merge Robot dd64038192
Merge pull request #4664 from baude/movefilters
move image filters under libpod/images
2019-12-11 16:58:54 +01:00
baude 8be7b466d8 move image filters under libpod/images
to make things more effecient for the api work we are doing, we should
process image filters internally (as opposed to in main).  this allows
for better api responses and more closely affiliated functions.

Signed-off-by: baude <bbaude@redhat.com>
2019-12-10 13:05:18 -06:00
Matthew Heon 0355c28edf Re-add Fedora 31 migration code.
In the process, make everything in the config omitempty in TOML.
We're seeing issues (notably [1]) where, after rewriting
libpod.conf, fields that were not previously populated are
written - and, because they were not previously written, they are
included as empty. This is unfortunately different from not
included at all - it means that we need to assume the user
explicitly unset the value, and we can't use defaults. Setting
omitempty prevents us from writing things that should not be
written as they were not set originally.

[1] https://github.com/containers/libpod/issues/4210

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-12-10 13:50:17 -05:00
Adrian Reber 225c7ae6c9
Correctly export the root file-system changes
When doing a checkpoint with --export the root file-system diff was not
working as expected. Instead of getting the changes from the running
container to the highest storage layer it got the changes from the
highest layer to that parent's layer. For a one layer container this
could mean that the complete root file-system is part of the checkpoint.

With this commit this changes to use the same functionality as 'podman
diff'. This actually enables to correctly diff the root file-system
including tracking deleted files.

This also removes the non-working helper functions from libpod/diff.go.

Signed-off-by: Adrian Reber <areber@redhat.com>
2019-12-09 13:29:36 +01:00
OpenShift Merge Robot 8924a302a2
Merge pull request #4563 from mheon/fix_change_parsing
Fix parsing for arrays of values in image changes
2019-12-06 04:09:06 -08:00
Matthew Heon 60bfa305a8 Add ONBUILD support to --change
Return types had to change a bit for this, but since we can wrap
the old v1.ImageConfig, changes are overall not particularly bad.

At present, I believe this only works with commit, not import.
This matches how things were before we changed to the new parsing
so I think this is fine.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-12-05 15:11:40 -05:00
Matthew Heon c4fbd2fc94 Move Commit() to new parsing for --change
It turns out we had two independent parsing impkementations for
Dockerfile instructions out of --change. My previous commit fixed
the one used in --change, but as I discovered to my dismay,
commit used a different implementation. Remove that and use the
new parsing implementation instead.

While we're at it, fix some bugs in the current commit code. The
addition of anonymous named volumes to Libpod recently means we
can now include those in the image config when committing. Some
changes (VOLUME, ENV, EXPOSE, LABEL) previously cleared the
config of the former image when used; Docker does not do this, so
I removed that behavior.

Still needs fixing: the new implementation does not support
ONBUILD, while the old one did.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-12-05 13:19:47 -05:00
Giuseppe Scrivano 3f1675d902
libpod: fix stats for rootless pods
honor the systemd parent directory when specified.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-12-04 11:13:40 +01:00
OpenShift Merge Robot 5c3af009c6
Merge pull request #4629 from mheon/fix_indirect_netnsctr_lookup
Allow chained network namespace containers
2019-12-03 09:16:31 -08:00
Matthew Heon b0b9103cca Allow chained network namespace containers
The code currently assumes that the container we delegate network
namespace to will never further delegate to another container, so
when looking up things like /etc/hosts and /etc/resolv.conf we
won't pull the correct files from the chained dependency. The
changes to resolve this are relatively simple - just need to keep
looking until we find a container without NetNsCtr set.

Fixes #4626

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-12-03 10:27:15 -05:00
Matthew Heon 689329f749 Ensure volumes reacquire locks on state refresh
After a restart, pods and containers both run a refresh()
function to prepare to run after a reboot. Until now, volumes
have not had a similar function, because they had no per-boot
setup to perform.

Unfortunately, this was not noticed when in-memory locking was
introduced to volumes. The refresh() routine is, among other
things, responsible for ensuring that locks are reserved after a
reboot, ensuring they cannot be taken by a freshly-created
container, pod, or volume. If this reservation is not done, we
can end up with two objects using the same lock, potentially
needing to lock each other for some operations - classic recipe
for deadlocks.

Add a refresh() function to volumes to perform lock reservation
and ensure it is called as part of overall refresh().

Fixes #4605
Fixes #4621

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-12-02 23:06:00 -05:00
Giuseppe Scrivano e13e5502e3
libpod: fix case for executable file not found errors
do not change the runtime error to be lowercase, but use a case
insensitive regex matching.  In this way the original error from the
OCI runtime is reported back.

regression introduced by bc485bce47

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-12-02 18:03:33 +01:00
OpenShift Merge Robot e4275b3453
Merge pull request #4493 from mheon/add_removing_state
Add ContainerStateRemoving
2019-12-02 16:31:11 +01:00
OpenShift Merge Robot 39c705e940
Merge pull request #4558 from rhatdan/reset
Add podman system reset command
2019-11-29 15:05:03 +01:00
OpenShift Merge Robot 7f53178a7d
Merge pull request #4576 from giuseppe/oci-errors-only-match
oci: print only matching part for the errors
2019-11-29 12:22:58 +01:00
Daniel J Walsh 79bf5010ed
Add podman system reset command
This command will destroy all data created via podman.
It will remove containers, images, volumes, pods.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-11-29 05:34:52 -05:00
Adrian Reber 5e43c7cde1
Disable checkpointing of containers started with --rm
Trying to checkpoint a container started with --rm works, but it makes
no sense as the container, including the checkpoint, will be deleted
after writing the checkpoint. This commit inhibits checkpointing
containers started with '--rm' unless '--export' is used. If the
checkpoint is exported it can easily be restored from the exported
checkpoint, even if '--rm' is used. To restore a container from a
checkpoint it is even necessary to manually run 'podman rm' if the
container is not started with '--rm'.

Signed-off-by: Adrian Reber <areber@redhat.com>
2019-11-28 20:25:45 +01:00
Giuseppe Scrivano bc485bce47
oci: print only matching part for the errors
when parsing the OCI error, be sure to discard any other output that
is not matched.  The full output is still printed with
--log-level=debug.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2019-11-28 09:51:58 +01:00
OpenShift Merge Robot 2178875fa7
Merge pull request #4568 from openSUSE/history
Add support for image name history
2019-11-27 15:31:22 +01:00