111 Commits

Author SHA1 Message Date
a364b656ea Add lock manager to libpod runtime
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2019-01-04 09:51:09 -05:00
75578aad61 add container-init support
Add support for executing an init binary as PID 1 in a container to
forward signals and reap processes.  When the `--init` flag is set for
podman-create or podman-run, the init binary is bind-mounted to
`/dev/init` in the container and "/dev/init --" is prepended to the
container's command.

The default base path of the container-init binary is `/usr/libexec/podman`
while the default binary is catatonit [1].  This default can be changed
permanently via the `init_path` field in the `libpod.conf` configuration
file (which is recommended for packaging) or temporarily via the
`--init-path` flag of podman-create and podman-run.

[1] https://github.com/openSUSE/catatonit

Fixes: #1670
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2019-01-04 11:42:03 +01:00
31edf47285 Support podman image trust command
Display the trust policy of the host system. The trust policy is stored in the /etc/containers/policy.json file and defines a scope of registries or repositories.

Signed-off-by: Qi Wang <qiwan@redhat.com>
2018-12-19 13:36:11 -05:00
4c70b8a94b Add "podman volume" command
Add support for podman volume and its subcommands.
The commands supported are:
	podman volume create
	podman volume inspect
	podman volume ls
	podman volume rm
	podman volume prune

This is a tool to manage volumes used by podman. For now it only handle
named volumes, but eventually it will handle all volumes used by podman.

Signed-off-by: umohnani8 <umohnani@redhat.com>
2018-12-06 10:17:16 +00:00
50e754cd57 Merge pull request #1918 from mheon/use_db_paths
Use paths written in DB instead if they differ from our defaults
2018-12-05 00:55:48 -08:00
aba52cf588 Merge pull request #1939 from mheon/no_firewall_if_rootless
Don't initialize CNI when running as rootless
2018-12-04 12:55:40 -08:00
32aa45e344 Don't initialize CNI when running as rootless
We don't use CNI to configure networks for rootless containers,
so no need to set it up. It may also cause issues with inotify,
so disabling it resolves some potential problems.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-04 14:57:06 -05:00
e3882cfa2d Use runtime lockDir in BoltDB state
Instead of storing the runtime's file lock dir in the BoltDB
state, refer to the runtime inside the Bolt state instead, and
use the path stored in the runtime.

This is necessary since we moved DB initialization very far up in
runtime init, before the locks dir is properly initialized (and
it must happen before the locks dir can be created, as we use the
DB to retrieve the proper path for the locks dir now).

Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-04 13:58:51 -05:00
a4b483c848 libpod/container_internal: Deprecate implicit hook directories
Part of the motivation for 800eb863 (Hooks supports two directories,
process default and override, 2018-09-17, #1487) was [1]:

> We only use this for override. The reason this was caught is people
> are trying to get hooks to work with CoreOS. You are not allowed to
> write to /usr/share... on CoreOS, so they wanted podman to also look
> at /etc, where users and third parties can write.

But we'd also been disabling hooks completely for rootless users.  And
even for root users, the override logic was tricky when folks actually
had content in both directories.  For example, if you wanted to
disable a hook from the default directory, you'd have to add a no-op
hook to the override directory.

Also, the previous implementation failed to handle the case where
there hooks defined in the override directory but the default
directory did not exist:

  $ podman version
  Version:       0.11.2-dev
  Go Version:    go1.10.3
  Git Commit:    "6df7409cb5a41c710164c42ed35e33b28f3f7214"
  Built:         Sun Dec  2 21:30:06 2018
  OS/Arch:       linux/amd64
  $ ls -l /etc/containers/oci/hooks.d/test.json
  -rw-r--r--. 1 root root 184 Dec  2 16:27 /etc/containers/oci/hooks.d/test.json
  $ podman --log-level=debug run --rm docker.io/library/alpine echo 'successful container' 2>&1 | grep -i hook
  time="2018-12-02T21:31:19-08:00" level=debug msg="reading hooks from /usr/share/containers/oci/hooks.d"
  time="2018-12-02T21:31:19-08:00" level=warning msg="failed to load hooks: {}%!(EXTRA *os.PathError=open /usr/share/containers/oci/hooks.d: no such file or directory)"

With this commit:

  $ podman --log-level=debug run --rm docker.io/library/alpine echo 'successful container' 2>&1 | grep -i hook
  time="2018-12-02T21:33:07-08:00" level=debug msg="reading hooks from /usr/share/containers/oci/hooks.d"
  time="2018-12-02T21:33:07-08:00" level=debug msg="reading hooks from /etc/containers/oci/hooks.d"
  time="2018-12-02T21:33:07-08:00" level=debug msg="added hook /etc/containers/oci/hooks.d/test.json"
  time="2018-12-02T21:33:07-08:00" level=debug msg="hook test.json matched; adding to stages [prestart]"
  time="2018-12-02T21:33:07-08:00" level=warning msg="implicit hook directories are deprecated; set --hooks-dir="/etc/containers/oci/hooks.d" explicitly to continue to load hooks from this directory"
  time="2018-12-02T21:33:07-08:00" level=error msg="container create failed: container_linux.go:336: starting container process caused "process_linux.go:399: container init caused \"process_linux.go:382: running prestart hook 0 caused \\\"error running hook: exit status 1, stdout: , stderr: oh, noes!\\\\n\\\"\""

(I'd setup the hook to error out).  You can see that it's silenly
ignoring the ENOENT for /usr/share/containers/oci/hooks.d and
continuing on to load hooks from /etc/containers/oci/hooks.d.

When it loads the hook, it also logs a warning-level message
suggesting that callers explicitly configure their hook directories.
That will help consumers migrate, so we can drop the implicit hook
directories in some future release.  When folks *do* explicitly
configure hook directories (via the newly-public --hooks-dir and
hooks_dir options), we error out if they're missing:

  $ podman --hooks-dir /does/not/exist run --rm docker.io/library/alpine echo 'successful container'
  error setting up OCI Hooks: open /does/not/exist: no such file or directory

I've dropped the trailing "path" from the old, hidden --hooks-dir-path
and hooks_dir_path because I think "dir(ectory)" is already enough
context for "we expect a path argument".  I consider this name change
non-breaking because the old forms were undocumented.

Coming back to rootless users, I've enabled hooks now.  I expect they
were previously disabled because users had no way to avoid
/usr/share/containers/oci/hooks.d which might contain hooks that
required root permissions.  But now rootless users will have to
explicitly configure hook directories, and since their default config
is from ~/.config/containers/libpod.conf, it's a misconfiguration if
it contains hooks_dir entries which point at directories with hooks
that require root access.  We error out so they can fix their
libpod.conf.

[1]: https://github.com/containers/libpod/pull/1487#discussion_r218149355

Signed-off-by: W. Trevor King <wking@tremily.us>
2018-12-03 12:54:30 -08:00
795fbba769 Revert changes to GetDefaultStoreOptions
We don't need this for anything more than rootless work in Libpod
now, but Buildah still uses it as it was originally written, so
leave it intact as part of our API.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-03 15:48:20 -05:00
677c444463 Ensure directory where we will make database exists
Ensure that the directory where we will create the Podman db
exists prior to creating the database - otherwise creating the DB
will fail.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-03 11:10:02 -05:00
03229239b0 Do not initialize locks dir in BoltDB
We already create the locks directory as part of the libpod
runtime's init - no need to do it again as part of BoltDB's init.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-02 15:32:06 -05:00
562fa57dc9 Move rootless storage config into libpod
Previous commits ensured that we would use database-configured
paths if not explicitly overridden.

However, our runtime generation did unconditionally override
storage config, which made this useless.

Move rootless storage configuration setup to libpod, and change
storage setup so we only override if a setting is explicitly
set, so we can still override what we want.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-02 15:21:35 -05:00
92ff83f5b9 Set default paths from DB if not explicitly overridden
If the DB contains default paths, and the user has not explicitly
overridden them, use the paths in the DB over our own defaults.

The DB validates these paths, so it would error and prevent
operation if they did not match. As such, instead of erroring, we
can use the DB's paths instead of our own.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-02 14:21:22 -05:00
aa7ce33b7a Add a struct indicating if some Runtime fields were set
To configure runtime fields from the database, we need to know
whether they were explicitly overwritten by the user (we don't
want to overwrite anything that was explicitly set). Store a
struct containing whether the variables we'll grab from the DB
were explicitly set by the user so we know what we can and can't
overwrite.

This determines whether libpod runtime and static dirs were set
via config file in a horribly hackish way (double TOML decode),
but I can't think of a better way, and it shouldn't be that
expensive as the libpod config is tiny.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-02 14:06:33 -05:00
137e0948ae Make DB config validation an explicit step
Previously, we implicitly validated runtime configuration against
what was stored in the database as part of database init. Make
this an explicit step, so we can call it after the database has
been initialized. This will allow us to retrieve paths from the
database and use them to overwrite our defaults if they differ.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-02 13:38:36 -05:00
b0f79ff4df Move DB configuration up in runtime setup
When we configure a runtime, we now will need to hit the DB early
on, so we can verify the paths we're going to use for c/storage are correct.

Signed-off-by: Matthew Heon <mheon@redhat.com>
2018-12-02 13:38:36 -05:00
a6aca6d106 rootless: create libpod.conf when it doesn't exist
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-11-19 12:11:05 +01:00
1c4880d3ef Sync default config with libpod.conf
Only changed libpod.conf file, which might not even be in use.

Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
2018-10-29 19:11:47 +01:00
fba494de8e Use more reliable check for rootless for firewall init
We probably won't be able to initialize a firewall plugin when we
are not running as root, so we shouldn't even try. Replace the
less-effect EUID check with the rootless package's better check
to make sure we don't accidentally set up the firewall in these
cases.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2018-10-23 10:33:38 -04:00
2444ac9926 Move rootless directory handling to the libpod/pkg/util directory
This should allow us to share this code with buildah.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2018-10-22 09:43:59 -04:00
2f73a9b0f6 rootless: always set XDG_RUNTIME_DIR
it is used internally by containers/image to locate the auth file.

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

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-10-03 10:41:47 +02:00
28fe7003ac runtime: fix message which assumes the runtime is runc
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-10-01 11:15:28 +02:00
fbfcc7842e Add new field to libpod to indicate whether or not to use labelling
Also update some missing fields libpod.conf obtions in man pages.

Fix sort order of security options and add a note about disabling
labeling.

When a process requests a new label.  libpod needs to reserve all
labels to make sure that their are no conflicts.

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

Closes: #1406
Approved by: mheon
2018-09-20 16:01:29 +00:00
800eb86338 Hooks supports two directories, process default and override
ALso cleanup files section or podman man page

Add description of policy.json
Sort alphabetically.
Add more info on  oci hooks

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

Closes: #1487
Approved by: umohnani8
2018-09-17 16:28:28 +00:00
95a374100b Add a way to disable port reservation
We've increased the default rlimits to allow Podman to hold many
ports open without hitting limits and crashing, but this doesn't
solve the amount of memory that holding open potentially
thousands of ports will use. Offer a switch to optionally disable
port reservation for performance- and memory-constrained use
cases.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2018-09-13 14:42:47 -04:00
6e263fed35 Explicitly set default CNI network name in libpod.conf
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #1438
Approved by: TomSweeneyRedHat
2018-09-12 19:18:24 +00:00
9405e3704f Vendor CNI plugins firewall code
The upstream CNI project has a PR open for adding iptables and
firewalld support, but this has been stalled for the better part
of a year upstream.

On advice of several maintainers, we are vendoring this code into
libpod, to perform the relevant firewall configuration ourselves.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #1431
Approved by: baude
2018-09-10 18:53:27 +00:00
807f6f8d8f rootless: check uid with Geteuid() instead of Getuid()
change the tests to use chroot to set a numeric UID/GID.

Go syscall.Credential doesn't change the effective UID/GID of the
process.

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

Closes: #1372
Approved by: mheon
2018-09-04 14:36:57 +00:00
14c0f9d63c rootless: be in an userns to initialize the runtime
be sure to be in an userns for a rootless process before initializing
the runtime.  In case we are not running as uid==0, take advantage of
"podman info" that creates the runtime.

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

Closes: #1372
Approved by: mheon
2018-09-04 14:36:57 +00:00
720eb85ba5 rootless: fix exec
We cannot re-exec into a new user namespace to gain privileges and
access an existing as the new namespace is not the owner of the
existing container.

"unshare" is used to join the user namespace of the target container.

The current implementation assumes that the main process of the
container didn't create a new user namespace.

Since in the setup phase we are not running with euid=0, we must skip
the setup for containers/storage.

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

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

Closes: #1331
Approved by: rhatdan
2018-08-26 07:22:42 +00:00
3473701de2 rootless: allow to override policy.json by the user
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1336
Approved by: mheon
2018-08-24 18:56:19 +00:00
2a7449362f Change pause container to infra container
Signed-off-by: haircommander <pehunt@redhat.com>

Closes: #1187
Approved by: mheon
2018-08-23 18:16:28 +00:00
d5e690914d Added option to share kernel namespaces in libpod and podman
A pause container is added to the pod if the user opts in. The default pause image and command can be overridden. Pause containers are ignored in ps unless the -a option is present. Pod inspect and pod ps show shared namespaces and pause container. A pause container can't be removed with podman rm, and a pod can be removed if it only has a pause container.

Signed-off-by: haircommander <pehunt@redhat.com>

Closes: #1187
Approved by: mheon
2018-08-23 18:16:28 +00:00
d20f3a5146 switch projectatomic to containers
Need to get some small changes into libpod to pull back into buildah
to complete buildah transition.

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

Closes: #1270
Approved by: mheon
2018-08-16 17:12:36 +00:00
8dd755fbf5 Remove unused function in runtime.go
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #1264
Approved by: mheon
2018-08-14 01:37:36 +00:00
7d116f5f73 Merge pull request #1254 from mheon/systemd_cgroups_default
Switch default CGroup manager to systemd
2018-08-11 15:07:29 -04:00
3d7e401d4e Swap default CGroup manager to systemd
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2018-08-10 14:09:46 -04:00
7366697175 Make errors during refresh nonfatal
During refresh, we cannot hard-fail, as that would mean leaving a
partially-configured state behind, leaving libpod unable to start
without manual intervention.

Instead, log errors refreshing individual containers and pods and
continue. Individual containers and pods may be unusable and need
to be removed manually, but libpod itself will continue to
function.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #1252
Approved by: rhatdan
2018-08-10 17:49:09 +00:00
486c5c87bc Add missing runtime.go lines to set namespace
Also add namespace to inspect output to verify its presence

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2018-07-24 16:12:31 -04:00
e838dcb4bf Add constraint that dependencies must be in the same ns
Dependency containers must be in the same namespace, to ensure
there are never problems resolving a dependency.

Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
2018-07-24 16:12:31 -04:00
673465a747 Merge pull request #1075 from giuseppe/rootless-no-symlinks-into-storage-path
rootless: fix usage on Fedora Silverblue/CoreOS
2018-07-13 14:15:54 -04:00
4f699db8da Support multiple networks
This is a refresh of Dan William's PR #974 with a rebase and proper
vendoring of ocicni and containernetworking/cni.  It adds the ability
to define multiple networks as so:

podman run --network=net1,net2,foobar ...

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

Closes: #1082
Approved by: baude
2018-07-12 21:45:47 +00:00
0066374fc3 runtime: delete unused function
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-07-11 09:38:43 +02:00
340becf542 rootless: propagate errors from GetRootlessRuntimeDir()
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
2018-07-11 09:38:04 +02:00
4cc4c7137d rootless: add /run/user/$UID to the lookup paths
when XDG_RUNTIME_DIR is not set, still attempt to use /run/user/$UID
before looking up other directories.

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

Closes: #1048
Approved by: mheon
2018-07-05 13:30:15 +00:00
e38272047f rootless: always set XDG_RUNTIME_DIR
containers/image uses XDG_RUNTIME_DIR to locate the auth file.

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

Closes: #1048
Approved by: mheon
2018-07-05 13:30:15 +00:00
3306d3e120 rootless: use $HOME/.config/containers/libpod.conf
If the file exists, use it to read the configuration.

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

Closes: #936
Approved by: rhatdan
2018-06-27 14:07:17 +00:00
4415bad6fe oci: set XDG_RUNTIME_DIR to the runtime from GetRootlessRuntimeDir()
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #936
Approved by: rhatdan
2018-06-27 14:07:17 +00:00
5ff90677c8 rootless: add management for the userNS
When running podman as non root user always create an userNS and let
the OCI runtime use it.

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

Closes: #936
Approved by: rhatdan
2018-06-27 14:07:17 +00:00