Commit graph

1971 commits

Author SHA1 Message Date
Valentin Rothberg 8d8746adee generate systemd: create pod template
Create a new template for generating a pod unit file. Eventually, this
allows for treating and extending pod and container generation
seprately.

The `--new` flag now also works on pods.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-06-11 11:01:13 +02:00
Valentin Rothberg 35ae53067f generate systemd: refactor
Refactor the systemd-unit generation code and move all the logic into
`pkg/systemd/generate`.  The code was already hard to maintain but I
found it impossible to wire the `--new` logic for pods in all the chaos.

The code refactoring in this commit will make maintaining the code
easier and should make it easier to extend as well.  Further changes and
refactorings may still be needed but they will easier.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-06-11 11:01:13 +02:00
Valentin Rothberg b4a410215e add (*Pod).CreateCommand()
Add a method to Pod to easily access its .config.CreateCommand.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-06-11 11:01:13 +02:00
Valentin Rothberg 402c68b41d pod create: add --infra-conmon-pidfile
Add an `--infra-conmon-pidfile` flag to `podman-pod-create` to write the
infra container's conmon process ID to a specified path.  Several
container sub-commands already support `--conmon-pidfile` which is
especially helpful to allow for systemd to access and track the conmon
processes.  This allows for easily tracking the conmon process of a
pod's infra container.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-06-11 11:01:13 +02:00
Valentin Rothberg 636881ece5 pod config: add a CreateCommand field
Add a `CreateCommand` field to the pod config which includes the entire
`os.Args` at pod-creation.  Similar to the already existing field in a
container config, we need this information to properly generate generic
systemd unit files for pods.  It's a prerequisite to support the `--new`
flag for pods.

Also add the `CreateCommand` to the pod-inspect data, which can come in
handy for debugging, general inspection and certainly for the tests that
are added along with the other changes.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-06-11 11:01:13 +02:00
Will Haines 86ffa552d2 Fixed bug where 'podman log <container>' would truncate some lines.
Signed-off-by: Will Haines <william.haines@colorado.edu>
2020-06-10 15:08:48 -06:00
Giuseppe Scrivano 6c27e27b8c
container: do not set hostname when joining uts
do not set the hostname when joining an UTS namespace, as it could be
owned by a different userns.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-10 14:52:10 +02:00
Giuseppe Scrivano a389eab8d1
container: make resolv.conf and hosts accessible in userns
when running in a new userns, make sure the resolv.conf and hosts
files bind mounted from another container are accessible to root in
the userns.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-10 14:46:48 +02:00
Daniel J Walsh 4bb43b898d
Fixup issues found by golint
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-06-10 05:49:41 -04:00
Matthew Heon 9d964ffb9f Ensure Conmon is alive before waiting for exit file
This came out of a conversation with Valentin about
systemd-managed Podman. He discovered that unit files did not
properly handle cases where Conmon was dead - the ExecStopPost
`podman rm --force` line was not actually removing the container,
but interestingly, adding a `podman cleanup --rm` line would
remove it. Both of these commands do the same thing (minus the
`podman cleanup --rm` command not force-removing running
containers).

Without a running Conmon instance, the container process is still
running (assuming you killed Conmon with SIGKILL and it had no
chance to kill the container it managed), but you can still kill
the container itself with `podman stop` - Conmon is not involved,
only the OCI Runtime. (`podman rm --force` and `podman stop` use
the same code to kill the container). The problem comes when we
want to get the container's exit code - we expect Conmon to make
us an exit file, which it's obviously not going to do, being
dead. The first `podman rm` would fail because of this, but
importantly, it would (after failing to retrieve the exit code
correctly) set container status to Exited, so that the second
`podman cleanup` process would succeed.

To make sure the first `podman rm --force` succeeds, we need to
catch the case where Conmon is already dead, and instead of
waiting for an exit file that will never come, immediately set
the Stopped state and remove an error that can be caught and
handled.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-06-08 13:48:29 -04:00
Matthew Heon 644a7b78ff Ensure that containers in pods properly set hostname
When we moved to the new Namespace types in Specgen, we made a
distinction between taking a namespace from a pod, and taking it
from another container. Due to this new distinction, some code
that previously worked for both `--pod=$ID` and
`--uts=container:$ID` has accidentally become conditional on only
the latter case. This happened for Hostname - we weren't properly
setting it in cases where the container joined a pod.
Fortunately, this is an easy fix once we know to check the
condition.

Also, ensure that `podman pod inspect` actually prints hostname.

Fixes #6494

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-04 16:32:10 -04:00
OpenShift Merge Robot 8cf74a79e3
Merge pull request #6470 from mheon/fix_stats_nonet
Properly follow linked namespace container for stats
2020-06-04 14:46:49 +02:00
Brent Baude d023909c0b add socket information to podman info
this is step 1 to self-discovery of remote ssh connections.  we add a remotesocket struct to info to detect what the socket path might be.

Co-authored-by: Jhon Honce <jhonce@redhat.com>
Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-06-03 15:20:37 -05:00
OpenShift Merge Robot 26bb48951f
Merge pull request #6468 from mheon/remote_detached_exec
Enable detached exec for remote
2020-06-03 00:02:20 +02:00
Matthew Heon 42505f64d2 Properly follow linked namespace container for stats
Podman containers can specify that they get their network
namespace from another container. This is automatic in pods, but
any container can do it.

The problem is that these containers are not guaranteed to have a
network namespace of their own; it is perfectly valid to join the
network namespace of a --net=host container, and both containers
will end up in the host namespace. The code for obtaining network
stats did not account for this, and could cause segfaults as a
result. Fortunately, the fix is simple - the function we use to
get said stats already performs appropriate checks, so we just
need to recursively call it.

Fixes #5652

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-02 17:58:52 -04:00
Matthew Heon e0d9404634 Enable detached exec for remote
The biggest obstacle here was cleanup - we needed a way to remove
detached exec sessions after they exited, but there's no way to
tell if an exec session will be attached or detached when it's
created, and that's when we must add the exit command that would
do the removal. The solution was adding a delay to the exit
command (5 minutes), which gives sufficient time for attached
exec sessions to retrieve the exit code of the session after it
exits, but still guarantees that they will be removed, even for
detached sessions. This requires Conmon 2.0.17, which has the new
`--exit-delay` flag.

As part of the exit command rework, we can drop the hack we were
using to clean up exec sessions (remove them as part of inspect).
This is a lot cleaner, and I'm a lot happier about it.

Otherwise, this is just plumbing - we need a bindings call for
detached exec, and that needed to be added to the tunnel mode
backend for entities.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-02 15:30:42 -04:00
Qi Wang 77e4b077b9 check --user range for rootless containers
Check --user range if it's a uid for rootless containers. Returns error if it is out of the range. From https://github.com/containers/libpod/issues/6431#issuecomment-636124686

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-06-02 11:28:58 -04:00
Valentin Rothberg dc80267b59 compat handlers: add X-Registry-Auth header support
* Support the `X-Registry-Auth` http-request header.

 * The content of the header is a base64 encoded JSON payload which can
   either be a single auth config or a map of auth configs (user+pw or
   token) with the corresponding registries being the keys.  Vanilla
   Docker, projectatomic Docker and the bindings are transparantly
   supported.

 * Add a hidden `--registries-conf` flag.  Buildah exposes the same
   flag, mostly for testing purposes.

 * Do all credential parsing in the client (i.e., `cmd/podman`) pass
   the username and password in the backend instead of unparsed
   credentials.

 * Add a `pkg/auth` which handles most of the heavy lifting.

 * Go through the authentication-handling code of most commands, bindings
   and endpoints.  Migrate them to the new code and fix issues as seen.
   A final evaluation and more tests is still required *after* this
   change.

 * The manifest-push endpoint is missing certain parameters and should
   use the ABI function instead.  Adding auth-support isn't really
   possible without these parts working.

 * The container commands and endpoints (i.e., create and run) have not
   been changed yet.  The APIs don't yet account for the authfile.

 * Add authentication tests to `pkg/bindings`.

Fixes: #6384
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-05-29 15:39:37 +02:00
Daniel J Walsh 7b188f7b5b
podman version --format ... was not working
This patch fixes the podman --version --format command.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-05-21 16:31:34 -04:00
Daniel J Walsh 17171aecf4
Display human build date in podman info
Currently we are displaying the Seconds since EPOCH
this will change to displaying date, similar to `podman version`

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-05-21 16:31:34 -04:00
OpenShift Merge Robot 9d3b46624b
Merge pull request #6323 from rhatdan/shrink
Remove github.com/libpod/libpod from cmd/pkg/podman
2020-05-21 19:55:58 +02:00
Daniel J Walsh 0d0565f55e
Remove github.com/libpod/libpod from cmd/pkg/podman
By moving a couple of variables from libpod/libpod to libpod/libpod/define
I am able shrink the podman-remote-* executables by another megabyte.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-05-21 12:09:01 -04:00
OpenShift Merge Robot 363f8820bc
Merge pull request #6312 from rhatdan/image
Fix remote handling of podman images calls
2020-05-21 17:13:36 +02:00
OpenShift Merge Robot feb97bb105
Merge pull request #6281 from rhatdan/fips
Fix mountpont in SecretMountsWithUIDGID
2020-05-21 17:05:11 +02:00
Giuseppe Scrivano e51bccec0c
vendor: update seccomp/containers-golang to v0.4.1
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-05-21 16:16:09 +02:00
OpenShift Merge Robot 6668b131eb
Merge pull request #6304 from baude/v2remotehctests
Fix remote integration for healthchecks
2020-05-21 16:05:47 +02:00
Daniel J Walsh a4c8198afd
Fix remote handling of podman images calls
Enable three more tests
Fix handling of image filters

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-05-21 09:28:42 -04:00
Matthew Heon 6b9e9610d8 Enable cleanup processes for detached exec
The cleanup command creation logic is made public as part of this
and wired such that we can call it both within SpecGen (to make
container exit commands) and from the ABI detached exec handler.
Exit commands are presently only used for detached exec, but
theoretically could be turned on for all exec sessions if we
wanted (I'm declining to do this because of potential overhead).

I also forgot to copy the exit command from the exec config into
the ExecOptions struct used by the OCI runtime, so it was not
being added.

There are also two significant bugfixes for exec in here. One is
for updating the status of running exec sessions - this was
always failing as I had coded it to remove the exit file *before*
reading it, instead of after (oops). The second was that removing
a running exec session would always fail because I inverted the
check to see if it was running.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-05-20 16:11:05 -04:00
Matthew Heon 5ec56dc790 Add ability to clean up exec sessions with cleanup
We need to be able to use cleanup processes to remove exec
sessions as part of detached exec. This PR adds that ability. A
new flag is added to `podman container cleanup`, `--exec`, to
specify an exec session to be cleaned up.

As part of this, ensure that `ExecCleanup` can clean up exec
sessions that were running, but have since exited. This ensures
that we can come back to an exec session that was running but has
since stopped, and clean it up.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-05-20 16:11:05 -04:00
Matthew Heon 43413887c0 Add backend code for detached exec
As part of the massive exec rework, I stubbed out a function for
non-detached exec, which is implemented here. It's largely
similar to the existing exec functions, but missing a few pieces.

This also involves implemented a new OCI runtime call for
detached exec. Again, very similar to the other functions, but
with a few missing pieces.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-05-20 16:11:05 -04:00
Matthew Heon e7f4e98c45 Add exit commands to exec sessions
These are required for detached exec, where they will be used to
clean up and remove exec sessions when they exit.

As part of this, move all Exec related functionality for the
Conmon OCI runtime into a separate file; the existing one was
around 2000 lines.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-05-20 16:11:05 -04:00
Brent Baude 141b34f6be Fix remote integration for healthchecks
the one remaining test that is still skipped do to missing exec function

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-05-20 14:43:01 -05:00
Peter Hunt 92acb3676c oci conmon: tell conmon to log container name
specifying `-n=ctr-name` tells conmon to log CONTAINER_NAME=name if the log driver is journald

add this, and a test!

also, refactor the args slice creation to not append() unnecessarily.

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2020-05-20 10:07:54 -04:00
Daniel J Walsh 35829854a2
Fix mountpont in SecretMountsWithUIDGID
In FIPS Mode we expect to work off of the Mountpath not the Rundir path.
This is causing FIPS Mode checks to fail.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-05-19 16:33:24 -04:00
OpenShift Merge Robot bfcec3203e
Merge pull request #6231 from mheon/fix_coverity
Fix two coverity issues (unchecked null return)
2020-05-17 04:03:54 -07:00
Matthew Heon ab25f70dad Drop a debug line which could print very large messages
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-05-15 14:35:10 -04:00
Matthew Heon 50ed292aee Remove duplicated exec handling code
During the initial workup of HTTP exec, I duplicated most of the
existing exec handling code so I could work on it without
breaking normal exec (and compare what I was doing to the nroaml
version). Now that it's done and working, we can switch over to
the refactored version and ditch the original, removing a lot of
duplicated code.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-05-14 17:32:44 -04:00
Matthew Heon a6d9cf9a5e Fix lint
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-05-14 17:01:49 -04:00
Matthew Heon 0f0abe2909 Prune stale exec sessions on inspect
The usual flow for exec is going to be:
- Create exec session
- Start and attach to exec session
- Exec session exits, attach session terminates
- Client does an exec inspect to pick up exit code

The safest point to remove the exec session, without doing any
database changes to track stale sessions, is to remove during the
last part of this - the single inspect after the exec session
exits.

This is definitely different from Docker (which would retain the
exec session for up to 10 minutes after it exits, where we will
immediately discard) but should be close enough to be not
noticeable in regular usage.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-05-14 16:56:02 -04:00
Matthew Heon 0c3bed119b Remove exec sessions on container restart
With APIv2, we cannot guarantee that exec sessions will be
removed cleanly on exit (Docker does not include an API for
removing exec sessions, instead using a timer-based reaper which
we cannot easily replicate). This is part 1 of a 2-part approach
to providing a solution to this. This ensures that exec sessions
will be reaped, at the very least, on container restart, which
takes care of any that were not properly removed during the run
of a container.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-05-14 16:56:02 -04:00
Matthew Heon 2b08359faf Fix start order for APIv2 exec start endpoint
This makes the endpoint (mostly) functional.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-05-14 16:56:02 -04:00
Matthew Heon c76cf1735c Don't fail when saving exec status fails on removed ctr
We can't save the exec session, but it's because the container
is entirely gone, so no point erroring.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-05-14 16:56:01 -04:00
Matthew Heon 4d410b7cb7 Ensure that Streams are set to defaults for HTTP attach
If not overridden, we should use the attach configuration given
when the exec session was first created.

Also, setting streams should not conflict with a TTY - the two
are allowed together with Attach and should be allowed together
here.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-05-14 16:56:01 -04:00
Matthew Heon 50cc56bc4a Add an initial implementation of HTTP-forwarded exec
This is heavily based off the existing exec implementation, but
does not presently share code with it, to try and ensure we don't
break anything.

Still to do:
- Add code sharing with existing exec implementation
- Wire in the frontend (exec HTTP endpoint)
- Move all exec-related code in oci_conmon_linux.go into a new
  file
- Investigate code sharing between HTTP attach and HTTP exec.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-05-14 16:51:57 -04:00
Matthew Heon 892d81685c Ensure that cleanup runs before we set Removing state
Cleaning up the OCI runtime is not allowed in the Removing state.
To ensure it is actually cleaned up, when calling cleanup() as
part of removing a container, do so before we set the Removing
state, so we can successfully remove.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-05-14 11:58:02 -04:00
Matthew Heon 5694aba9e3 Fix two coverity issues (unchecked null return)
Theoretically these should never happen, but it never hurts to be
sure and check. Add a check to one, make the other one a
create-if-not-exist (it was just adding, not checking the
contents).

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-05-14 11:17:34 -04:00
Matthew Heon 83a1e2e5d2 Cleanup OCI runtime before storage
Some runtimes (e.g. Kata containers) seem to object to having us
unmount storage before the container is removed from the runtime.
This is an easy fix (change the order of operations in cleanup)
and seems to make more sense than the way we were doing things.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-05-14 09:39:41 -04:00
Jhon Honce b6113e2b9e WIP V2 attach bindings and test
* Add ErrLostSync to report lost of sync when de-mux'ing stream
* Add logus.SetLevel(logrus.DebugLevel) when `go test -v` given
* Add context to debugging messages

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-05-13 11:49:17 -07:00
OpenShift Merge Robot d8c6cc1684
Merge pull request #6169 from vrothberg/fix-6164
shm_lock_test: add nil check
2020-05-11 15:34:44 +02:00
Valentin Rothberg 64a12898ad shm_lock_test: add nil check
Fixes: #6164
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-05-11 13:20:32 +02:00