Commit graph

193 commits

Author SHA1 Message Date
Daniel J Walsh 348f2df0c0
Support max_size logoptions
Docker supports log-opt max_size and so does conmon (ALthough poorly).
Adding support for this allows users to at least make sure their containers
logs do not become a DOS vector.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-10-05 17:51:45 -04:00
Ashley Cui b6176d8987 Add support for slirp network for pods
flag --network=slirp4netns[options] for root and rootless pods

Signed-off-by: Ashley Cui <acui@redhat.com>
2020-09-25 21:34:23 -04:00
Daniel J Walsh b3d6383f25
Fix podman pod create --infra-command and --infra-image
Currently infr-command and --infra-image commands are ignored
from the user.  This PR instruments them and adds tests for
each combination.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-09-16 07:42:19 -04:00
OpenShift Merge Robot d7db1da789
Merge pull request #7600 from rhatdan/codespell
Fix up errors found by codespell
2020-09-11 11:30:05 -04:00
OpenShift Merge Robot 881f2dfe92
Merge pull request #7403 from QiWang19/runtime-flag
Add global options --runtime-flags
2020-09-11 11:00:11 -04:00
Daniel J Walsh 526f01cdf5
Fix up errors found by codespell
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-09-11 06:14:25 -04:00
Giuseppe Scrivano 686f6eccee
libpod: read mappings when joining a container userns
when joining an existing container user namespace, read the existing
mappings so the storage can be created with the correct ownership.

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

Signed-off-by: Giuseppe Scrivano <giuseppe@scrivano.org>
2020-09-10 19:17:01 +02:00
Qi Wang 6b0864434a Add global options --runtime-flags
Add global options --runtime-flags for setting options to container runtime.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-09-04 15:04:36 -04:00
Matthew Heon a071939893 Ensure pod infra containers have an exit command
Most Libpod containers are made via `pkg/specgen/generate` which
includes code to generate an appropriate exit command which will
handle unmounting the container's storage, cleaning up the
container's network, etc. There is one notable exception: pod
infra containers, which are made entirely within Libpod and do
not touch pkg/specgen. As such, no cleanup process, network never
cleaned up, bad things can happen.

There is good news, though - it's not that difficult to add this,
and it's done in this PR. Generally speaking, we don't allow
passing options directly to the infra container at create time,
but we do (optionally) proxy a pre-approved set of options into
it when we create it. Add ExitCommand to these options, and set
it at time of pod creation using the same code we use to generate
exit commands for normal containers.

Fixes #7103

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-08-13 14:03:57 -04:00
Matthew Heon 333d9af77a Ensure WORKDIR from images is created
A recent crun change stopped the creation of the container's
working directory if it does not exist. This is arguably correct
for user-specified directories, to protect against typos; it is
definitely not correct for image WORKDIR, where the image author
definitely intended for the directory to be used.

This makes Podman create the working directory and chown it to
container root, if it does not already exist, and only if it was
specified by an image, not the user.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-08-03 14:44:52 -04:00
Daniel J Walsh a5e37ad280
Switch all references to github.com/containers/libpod -> podman
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-28 08:23:45 -04:00
Ashley Cui d4d3fbc155 Add --umask flag for create, run
--umask sets the umask inside the container
Defaults to 0022

Co-authored-by: Daniel J Walsh <dwalsh@redhat.com>
Signed-off-by: Ashley Cui <acui@redhat.com>
2020-07-21 14:22:30 -04:00
Qi Wang 020d81f113 Add support for overlay volume mounts in podman.
Add support -v for overlay volume mounts in podman.

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

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-07-20 09:48:55 -04:00
Giuseppe Scrivano 9be7029cdd
libpod: pass down network options
do not pass network specific options through the network namespace.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-07-16 22:37:27 +02:00
Matthew Heon c4627b5846 Fix container and pod create commands for remote create
In `podman inspect` output for containers and pods, we include
the command that was used to create the container. This is also
used by `podman generate systemd --new` to generate unit files.

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

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

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-10 11:22:23 -04:00
Daniel J Walsh 6c6670f12a
Add username to /etc/passwd inside of container if --userns keep-id
If I enter a continer with --userns keep-id, my UID will be present
inside of the container, but most likely my user will not be defined.

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

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

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

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

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

Signed-off-by: Joseph Gooch <mrwizard@dok.org>
2020-07-06 17:47:18 +00:00
OpenShift Merge Robot 9532509c50
Merge pull request #6836 from ashley-cui/tzlibpod
Add --tz flag to create, run
2020-07-06 13:28:20 -04:00
Valentin Rothberg 8489dc4345 move go module to v2
With the advent of Podman 2.0.0 we crossed the magical barrier of go
modules.  While we were able to continue importing all packages inside
of the project, the project could not be vendored anymore from the
outside.

Move the go module to new major version and change all imports to
`github.com/containers/libpod/v2`.  The renaming of the imports
was done via `gomove` [1].

[1] https://github.com/KSubedi/gomove

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-06 15:50:12 +02:00
Ashley Cui 9a1543caec Add --tz flag to create, run
--tz flag sets timezone inside container
Can be set to IANA timezone as well as `local` to match host machine

Signed-off-by: Ashley Cui <acui@redhat.com>
2020-07-02 13:30:59 -04:00
OpenShift Merge Robot c2a0ccd394
Merge pull request #6747 from giuseppe/fix-user-volumes
container: move volume chown after spec generation
2020-06-30 12:01:40 -04:00
Giuseppe Scrivano b32172e20b
container: move volume chown after spec generation
move the chown for newly created volumes after the spec generation so
the correct UID/GID are known.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-29 17:58:50 +02:00
Giuseppe Scrivano 6ee5f740a4
podman: add new cgroup mode split
When running under systemd there is no need to create yet another
cgroup for the container.

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

- supervisor
- container

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

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2020-06-25 17:16:12 +02:00
Qi Wang f61a7f25a8 Add --preservefds to podman run
Add --preservefds to podman run. close https://github.com/containers/libpod/issues/6458

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-06-19 09:40:13 -04:00
OpenShift Merge Robot 7b00e49f65
Merge pull request #6560 from mheon/fix_exec_logdriver
Do not share container log driver for exec
2020-06-17 17:17:27 -04:00
Matthew Heon 6f1440a3ec Add support for the unless-stopped restart policy
We initially believed that implementing this required support for
restarting containers after reboot, but this is not the case.
The unless-stopped restart policy acts identically to the always
restart policy except in cases related to reboot (which we do not
support yet), but it does not require that support for us to
implement it.

Changes themselves are quite simple, we need a new restart policy
constant, we need to remove existing checks that block creation
of containers when unless-stopped was used, and we need to update
the manpages.

Fixes #6508

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-17 11:16:12 -04:00
Matthew Heon 0e171b7b33 Do not share container log driver for exec
When the container uses journald logging, we don't want to
automatically use the same driver for its exec sessions. If we do
we will pollute the journal (particularly in the case of
healthchecks) with large amounts of undesired logs. Instead,
force exec sessions logs to file for now; we can add a log-driver
flag later (we'll probably want to add a `podman logs` command
that reads exec session logs at the same time).

As part of this, add support for the new 'none' logs driver in
Conmon. It will be the default log driver for exec sessions, and
can be optionally selected for containers.

Great thanks to Joe Gooch (mrwizard@dok.org) for adding support
to Conmon for a null log driver, and wiring it in here.

Fixes #6555

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-06-17 11:11:46 -04: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
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 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
Matthew Heon c57c560d90 Fix bug where pods would unintentionally share cgroupns
This one was a massive pain to track down.

The original symptom was an error message from rootless Podman
trying to make a container in a pod. I unfortunately did not look
at the error message closely enough to realize that the namespace
in question was the cgroup namespace (the reproducer pod was
explicitly set to only share the network namespace), else this
would have been quite a bit shorter.

I spent considerable effort trying to track down differences
between the inspect output of the two containers, and when that
failed I was forced to resort to diffing the OCI specs. That
finally proved fruitful, and I was able to determine what should
have been obvious all along: the container was joining the cgroup
namespace of the infra container when it really ought not to
have.

From there, I discovered a variable collision in pod config. The
UsePodCgroup variable means "create a parent cgroup for the pod
and join containers in the pod to it". Unfortunately, it is very
similar to UsePodUTS, UsePodNet, etc, which mean "the pod shares
this namespace", so an accessor was accidentally added for it
that indicated the pod shared the cgroup namespace when it really
did not. Once I realized that, it was a quick fix - add a bool to
the pod's configuration to indicate whether the cgroup ns was
shared (distinct from UsePodCgroup) and use that for the
accessor.

Also included are fixes for `podman inspect` and
`podman pod inspect` that fix them to actually display the state
of the cgroup namespace (for container inspect) and what
namespaces are shared (for pod inspect). Either of those would
have made tracking this down considerably quicker.

Fixes #6149

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-05-08 18:00:42 -04:00
Brent Baude e78e66c5b9 enable volume integration tests
enabled integration tests for volumes.  there are two exceptions that still need work because of something not yet implemented.

also, add code to deal with the fact that containers conf appears to set a local volume driver where it used to be simply blank.

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-04-27 16:12:06 -05:00
Brent Baude ba430bfe5e podman v2 remove bloat v2
rid ourseleves of libpod references in v2 client

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-04-16 12:04:46 -05: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
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
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
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
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
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
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
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
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 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
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 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
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
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 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