Commit graph

1488 commits

Author SHA1 Message Date
Matthew Heon
d34b1e7ad5 Ensure rootless containers without a passwd can start
We want to modify /etc/passwd to add an entry for the user in
question, but at the same time we don't want to require the
container provide a /etc/passwd (a container with a single,
statically linked binary and nothing else is perfectly fine and
should be allowed, for example). We could create the passwd file
if it does not exist, but if the container doesn't provide one,
it's probably better not to make one at all. Gate changes to
/etc/passwd behind a stat() of the file in the container
returning cleanly.

Fixes #7515

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-09-01 10:59:34 -04:00
Ed Santiago
8b38d27ebd system tests: podman-remote, image tree
- new sanity checks for podman-remote:
  - first, confirm that when PODMAN is "-remote",
    we actually talk to a server (validated by
    presence of "Server:" string in "podman version").
  - second, add test for #7212, in which we run
    "podman --remote" (podman with --remote flag,
    not podman-remote command) and make sure --remote
    is allowed both as the first option and also
    with other flag options preceding.

- new test for "podman image tree" (piggybacking on
  top of a "podman build" test, because that gives
  us lots of layers).

- skip "podman exec - basic test" when remote. It is consistently
  causing CI failures, breaking all of CI, due to #7241.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-08-30 12:11:19 +02:00
Jhon Honce
33cf7aec51 Refactor parsing to not require --remote to be first
Use cobra.Command.FParseErrWhitelist to no longer require --remote to be
the first argument in flags when using CLI

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-08-30 12:11:19 +02:00
Ed Santiago
a60b4cc1d8 run test: use explicit uid/gid
Fixes Fedora gating test failure: if the host tests are running
under UID 1000, --userns=keep-id will (of course) add current
user as 1000, and the in-container 'adduser' will assign 1001.
To prevent that, assign UID 4242 (and hope that that's not
our calling user's UID).

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-08-25 07:26:23 -06:00
Brent Baude
23251149ab error when adding container to pod with network information
because a pod's network information is dictated by the infra container at creation, a container cannot be created with network attributes.  this has been difficult for users to understand.  we now return an error when a container is being created inside a pod and passes any of the following attributes:

* static IP (v4 and v6)
* static mac
* ports -p (i.e. -p 8080:80)
* exposed ports (i.e. 222-225)
* publish ports from image -P

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

<MH: Fixed cherry pick conflicts and compile>

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-08-24 11:31:37 -04:00
OpenShift Merge Robot
11372c4c4d
Merge pull request #7363 from mheon/lets_try_this_again
Lets try this again: v2.0.5 backports, round 2
2020-08-21 12:58:55 +02:00
Paul Holzinger
7fc3c25410 fix pod creation with "new:" syntax followup + allow hostname
Fixes: 4c75fe3f70 ("fix pod creation with "new:" syntax")

Commit 4c75fe3f70 passes all net options to the pod but forgot
to unset the options for the container creation. This leads to
erros when using flags like `--ip` since we tried setting
the ip on the pod and container which obviously fails.

I didn't notice the bug because we don't throw an error when
specifing port bindings on a container which joins the pods
network namespace. (#7373)

Also allow the use of `--hostname` and pass that option to the
pod and unset it for the container. The container has to use
the pods hostname anyway. This would error otherwise.

Added tests to prevent regression.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-08-20 14:59:21 -04:00
Matthew Heon
7fc0fbfb65 Fix a system test failure
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-08-20 14:17:48 -04:00
Daniel J Walsh
4e31c8136d
Cleanup handling of podman mount/unmount
We should default to the user name unmount rather then the internal
name of umount.

Also User namespace was not being handled correctly. We want to inform
the user that if they do a mount when in rootless mode that they have
to be first in the podman unshare state.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-08-20 13:35:11 -04:00
Paul Holzinger
d3ef4770d4 fix podman version output to include git commit and builttime
Add the go module version v2 to the libpod path.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-08-20 12:24:16 -04:00
Jhon Honce
ee956b04b0 [WIP] Refactor podman system connection
* Add support to manage multiple connections
  * Add connection
  * Remove connection
  * Rename connection
  * Set connection as default
  * Add markdown/man pages
* Fix recursion in hack/xref-helpmsgs-manpages

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

<MH: Fixed build after rebase>

Signed-off-by: Matt Heon <matthew.heon@pm.me>
2020-08-20 12:16:53 -04:00
Matthew Heon
e2a1242cee Fix one import path pointing to containers/podman
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-08-20 12:16:53 -04:00
Jhon Honce
35d2db8072 Default .Repository and .Tag values to <none>
Refactor the processing of Repository and Tag fields to default to <none>
when printing via --format flag. Previously, the default format would
print <none> but --format {{.Tag}} would not in some cases.

Fixes #7123

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-08-20 12:16:53 -04:00
Daniel J Walsh
fc24c0cc10 Fix handling of working dir
Buildah and podman build can create images without a working dir.

FROM fedora
WORKDIR /test

If you build this image with caching twice, the second time the image
will not have a working dir.

Similarly if you execute

podman run --workdir /foobar fedora

It blows up since the workingdir is not created automatically.

Finally there was duplicated code for getting the workingdir
out of an image, that this PR removes.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-08-20 12:16:53 -04:00
Matthew Heon
32f0c8f624 Do not use image CMD if user gave ENTRYPOINT
This matches Docker behavior, and seems to make sense - the CMD
may have been specific to the original entrypoint and probably
does not make sense if it was changed.

While we're in here, greatly simplify the logic for populating
the SpecGen's Command. We create the full command when making the
OCI spec, so the client should not be doing any more than setting
it to the Command the user passed in, and completely ignoring
ENTRYPOINT.

Fixes #7115

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-08-20 12:16:53 -04:00
Matthew Heon
d4c3365454 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-20 12:16:53 -04:00
Sascha Grunert
66fcafa4d4 Allow specifying seccomp profiles for privileged containers
To sync the behavior between AppArmor and seccomp it is now possible to
also specify seccomp profiles for privileged containers.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
2020-08-20 12:16:53 -04:00
Brent Baude
c539091bb0 Replace deepcopy on history results
the deepcopy in the remote history code path was throwing an uncaught error on a type mismatch.  we now manually do the conversion and fix the type mismatch on the fly.

Fixes: #7122

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-08-20 12:16:52 -04:00
zhangguanzhang
09bd563e2b Add parameter verification for api creation network
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
2020-08-20 12:16:52 -04:00
Qi Wang
34f4a892e4 podman save use named pipe
podman save uses named pipe as output path, not directly using /dev/stdout.
fix #7017

Signed-off-by: Qi Wang <qiwan@redhat.com>

<MH: Corrected imports during cherry-pick>

Signed-off-by: Matt Heon <matthew.heon@pm.me>
2020-08-20 12:16:52 -04:00
Antonio Ojea
5e50ba3ecb podman support for IPv6 networks
podman containers using IPv6 were missing the default route, breaking
deployments trying to use them.

The problem is that the default route was hardcoded to IPv4, this
takes into consideration the podman subnet IP family to generate
the corresponding default route.

Signed-off-by: Antonio Ojea <aojea@redhat.com>
2020-08-20 12:16:52 -04:00
Ed Santiago
3f2cab8643 system tests: invoke with abs path to podman
Reversion of one part of #6679: my handling of 'realpath'
would not work when $PODMAN is 'podman-remote --url etc'.
Trying to handle that case got unmaintainable; so instead
let's just force 'make {local,remote}system' to invoke
with a full PODMAN path. This breaks down if someone
runs the tests with a manual 'bats' invocation, but I
think I'm the only one who ever does that.

Since podman path will now be very long in the logs,
add code to logformatter to abbreviate it like we do
for the ginkgo logs.

And, one thing that has bugged me for a long time:
in the error logs, show a different prompt ('#' vs '$')
to distinguish root vs rootless. This should make it
much easier to see at-a-glance whether a log file
is root or not. Add tests for it.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-08-11 15:10:51 +02:00
Matthew Heon
ca00601b14 Make changes to /etc/passwd on disk for non-read only
Bind-mounting /etc/passwd into the container is problematic
becuase of how system utilities like `useradd` work. They want
to make a copy and then rename to try to prevent breakage; this
is, unfortunately, impossible when the file they want to rename
is a bind mount. The current behavior is fine for read-only
containers, though, because we expect useradd to fail in those
cases.

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

Fixes #6953

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-08-11 15:06:37 +02:00
Daniel J Walsh
3dfd8630a5 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-08-11 14:58:29 +02:00
Paul Holzinger
895e0d0e2e fix pod creation with "new:" syntax
When you execute podman create/run with the --pod new:<name> syntax
the pod was created but the namespaces where not shared and
therefore containers could not communicate over localhost.

Add the default namespaces and pass the network options to the
pod create options.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-08-11 13:53:23 +02:00
Jhon Honce
1752851958 Add versioned _ping endpoint
Fixes #7008

Signed-off-by: Jhon Honce <jhonce@redhat.com>
2020-08-11 13:53:23 +02:00
zhangguanzhang
8931e99a18 API returns 500 in case network is not found instead of 404
Backported-by: Valentin Rothberg <rothberg@redhat.com>
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
2020-08-11 13:53:23 +02:00
Daniel J Walsh
5b4952395b Handle podman-remote run --rm
We need to remove the container after it has exited for
podman-remote run --rm commands.  If we don't remove this
container at this step, we open ourselves up to race conditions.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-08-11 13:53:23 +02:00
Brent Baude
43527de53e correct go-binding key for volumes
the go binding for remove container was using 'vols' for a key to remove volumes associated to the container.  the correct key should be "v" and is documented as such.

Fixes: #7128

Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-08-11 13:53:23 +02:00
Ed Santiago
9b591e11d5 cherry-pick: Reenable remote system tests
NOTE: the remote tests are not reenabled but the changes are applied.
Future commits depend on some of the changes and having the commit
applied will likely facilitate future backports as well.

podman-remote is in better shape now. Let's see what needs
to be done to reenable remote system tests.

 - logs test: skip multilog, it doesn't work remote

 - diff test: use -l only when local, not with remote

 - many other tests: skip_if_remote, with 'FIXME: pending #xxxx'
   where xxxx is a filed issue.

Unrelated: added new helper to skip_if_remote and _if_rootless,
where we check if the source message includes "remote"/"rootless"
and insert it if missing. This is a minor usability enhancement
to make it easier to understand at-a-glance why a skip triggers.

Backported-by: Valentin Rothberg <rothberg@redhat.com>
Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-08-11 13:52:08 +02:00
Ed Santiago
589627b0ca system tests: new tests for run, exec
- Issue #6735 : problem with multiple namespaces; confirms
   combinations of --userns=keep-id, --privileged, --user=XX

 - Issue #6829 : --userns=keep-id will add a /etc/passwd entry

 - Issue #6593 : podman exec, with --userns=keep-id, errors
   (test is currently skipped because issue remains live)

...and, addendum: add new helper function, remove_same_dev_warning.
Some CI systems issue a warning on podman run --privileged:

   WARNING: The same type, major and minor should not be used for multiple devices.

We already had special-case code to ignore than in the SELinux
test, but now we're seeing it in the new run tests I added, so
I've refactored the "ignore this warning" code and written
tests for the removal code.

Signed-off-by: Ed Santiago <santiago@redhat.com>
2020-08-11 13:37:35 +02:00
zhangguanzhang
85d7cb5fd4 implement the exitcode when start a container with attach
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
2020-08-11 12:15:24 +02:00
Matthew Heon
d6442f5f57 Do not set host IP on ports when 0.0.0.0 requested
Docker and CNI have very different ideas of what 0.0.0.0 means.
Docker takes it to be 0.0.0.0/0 - that is, bind to every IPv4
address on the host. CNI (and, thus, root Podman) take it to mean
the literal IP 0.0.0.0. Instead, CNI interprets the empty string
("") as "bind to all IPs".

We could ask CNI to change, but given this is established
behavior, that's unlikely. Instead, let's just catch 0.0.0.0 and
turn it into "" when we parse ports.

Fixes #7014

Signed-off-by: Matthew Heon <mheon@redhat.com>
2020-08-11 12:15:24 +02:00
Qi Wang
a53b97beb3 fix bug podman sign storage path
- fix the bud podman not using specified --directory as signature storage.
- use manifest and image referce to set repo@digest.
close #6994
close #6993

Backported-by: Valentin Rothberg <rothberg@redhat.com>
Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-08-11 12:15:12 +02:00
Brent Baude
c5646acf4a podman-remote send name and tag
when loading an image with podman-remote load, we need to send a name and a tag to the endpoint

Fixes: #7124

Backported-by: Valentin Rothberg <rothberg@redhat.com>
Signed-off-by: Brent Baude <bbaude@redhat.com>
2020-08-11 11:17:27 +02:00
Matthew Heon
729e0aa0d1 Ensure that exec errors write exit codes to the DB
In local Podman, the frontend interprets the error and exit code
given by the Exec API to determine the appropriate exit code to
set for Podman itself; special cases like a missing executable
receive special exit codes.

Exec for the remote API, however, has to do this inside Libpod
itself, as Libpod will be directly queried (via the Inspect API
for exec sessions) to get the exit code. This was done correctly
when the exec session started properly, but we did not properly
handle cases where the OCI runtime fails before the exec session
can properly start. Making two error returns that would otherwise
not set exit code actually do so should resolve the issue.

Fixes #6893

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-08-11 11:15:38 +02:00
Paul Holzinger
d9c86fd0f2 fix podman logs --tail when log is bigger than pagesize
Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2020-08-11 11:14:56 +02:00
Valentin Rothberg
c72bb4f8fe generate systemd: fix error handling
Fix a bug in the error handling which returned nil instead of an error
and ultimately lead to nil dereferences in the client.  To prevent
future regressions, add a test and check for the error message.

Fixes: #7271
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-08-11 11:12:44 +02:00
Ashley Cui
3b22faa24b Publish IP from YAML (podman play kube)
podman play kube didn't set host ip correctly from YAML

Signed-off-by: Ashley Cui <acui@redhat.com>
2020-08-04 16:52:32 -04:00
Matthew Heon
a9a55be991 Disable a nonfunctional build test
The amount of drift in the system tests on v2.0 is starting to
become difficult to deal with. 2.1.0 can't come soon enough.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-31 12:39:55 -04:00
Giuseppe Scrivano
2d71540518 volumes: do not recurse when chowning
keep the file ownership when chowning and honor the user namespace
mappings.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

<MH: Fixed conflicts from cherry pick>

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-31 11:45:58 -04:00
Ashley Cui
2cc9af3692 add {{.RunningFor}} placeholder in ps --format
For docker compatibility

Signed-off-by: Ashley Cui <acui@redhat.com>
2020-07-31 11:44:53 -04:00
Matthew Heon
da752a7ed3 Binding the same container port to >1 host port is OK
The initial version of the new port code mistakenly restricted
this, so un-restrict it. We still need to maintain the map of
container ports, unfortunately (need to verify if the port in
question is a duplicate, for example).

Fixes #7062

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-31 11:41:05 -04:00
Daniel J Walsh
828b547491 Specifying --ipc=host --pid=host is broken
For some reason we were overwriting memory when handling both
--pid=host and --ipc=host.  Simplified the code to handle this
correctly, and add test to make sure it does not happen again.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-31 11:40:25 -04:00
Daniel J Walsh
8c6a528693 Fix building from http or '-' options
When copying from a URL, podman will download and create a context
directory in a temporary file.  The problem was that this directory
was being removed as soon as the function that created it was returned.

Later the build code would look for content in the temporary directory
and fail to find it, blowing up the build.

By pulling the extraction code back into the build function, we keep the
temporary directory around until the build completes.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-31 13:01:45 +02:00
Valentin Rothberg
e2cb457e5f test/apiv2: add a simple events test
Add a simple test to exercise the events API without the "filters"
parameter.  Prevents regressing on #7078.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-27 15:33:26 +02:00
Matthew Heon
2faeb2189f Drop a nonfunctional test in test/apiv2
I'm somewhat reluctant to do this, but the file has diverged
majorly from master, and the amount of stuff we've backported
(versus not backported) makes me very hesitant to try cherry
picking more from master in the hope that it will start working.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2020-07-22 16:34:39 -04:00
Daniel J Walsh
4d7626cc89 Fix handling of entrypoint
If a user specifies an entrypoint of "" then we should not use the images
entrypoint.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-22 14:53:26 -04:00
zhangguanzhang
f9526cf02b fix API: Create container with an invalid configuration
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
2020-07-22 14:48:01 -04:00
Valentin Rothberg
1fb32b9b2f version/info: format: allow more json variants
Allow more variants to yield json output for `podman version` and
`podman info`.  Instead of comparing strings, use a regex and add
unit and e2e tests.

Fixes: #6927
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-22 14:42:53 -04:00