Commit graph

61 commits

Author SHA1 Message Date
W. Trevor King 89430ffe65 hooks: Order injection by collated JSON filename
We also considered ordering with sort.Strings, but Matthew rejected
that because it uses a byte-by-byte UTF-8 comparison [1] which would
fail many language-specific conventions [2].

There's some more discussion of the localeToLanguage mapping in [3].
Currently language.Parse does not handle either 'C' or 'POSIX',
returning:

  und, language: tag is not well-formed

for both.

[1]: https://github.com/projectatomic/libpod/pull/686#issuecomment-387914358
[2]: https://en.wikipedia.org/wiki/Alphabetical_order#Language-specific_conventions
[3]: https://github.com/golang/go/issues/25340

Signed-off-by: W. Trevor King <wking@tremily.us>

Closes: #686
Approved by: mheon
2018-05-11 16:26:35 +00:00
W. Trevor King 4b22913e11 libpod: Add HooksDirNotExistFatal
And add an argument to WithHooksDir to set it.

If the hook dir doesn't exist, the new hooks package considers that a
fatal error.  When a podman caller sets
--hooks-dir-path=/some/typoed/directory, a fatal error is more helpful
than silently not loading any hooks.  However, callers who call podman
without setting --hooks-dir-path may not need hooks at all.  We don't
want to pester those callers with not-exist errors.  With this commit,
we:

* Assume the caller knows what they're doing if they set
  --hooks-dir-path and set HooksDirNotExistFatal.

* If the caller does not explicitly set --hooks-dir-path, assume they
  won't mind if the hook directory is missing and set
  HooksDirNotExistFatal false.

We also considered checking for the directory's existence in the code
calling WithHooksDir or from within WithHooksDir, but checks there
would race with the underlying ioutil.ReadDir in the hooks package.
By pushing the warn/error decision down into libpod's implementation,
we avoid a racy "do we expect this to work once libpod gets to it?"
pre-check.

I've also added a check to error if WithHooksDir is called with an
empty-string argument, because we haven't defined the semantics of
that (is it clearing a previous value?  Is it effectively the same as
the current directory?).  I agree with Matthew that a separate
WithNoHooks, or a *string argument to WithHooks, or some such would be
a better API for clearing previous values [1].  But for now, I'm just
erroring out to fail early for callers who might otherwise be
surprised that libpod ignores empty-string HooksDir.

[1]: https://github.com/projectatomic/libpod/pull/686#issuecomment-385119370

Signed-off-by: W. Trevor King <wking@tremily.us>

Closes: #686
Approved by: mheon
2018-05-11 16:26:35 +00:00
W. Trevor King 68eb128fb0 pkg/hooks: Version the hook structure and add 1.0.0 hooks
This shifts the matching logic out of libpod/container_internal and
into the hook package, where we can reuse it after vendoring into
CRI-O.  It also adds unit tests with almost-complete coverage.  Now
libpod is even more isolated from the hook internals, which makes it
fairly straightforward to bump the hook config file to 1.0.0.  I've
dubbed the old format 0.1.0, although it doesn't specify an explicit
version.  Motivation for some of my changes with 1.0.0:

* Add an explicit version field.  This will make any future JSON
  structure migrations more straightforward by avoiding the need for
  version-guessing heuristics.

* Collect the matching properties in a new When sub-structure.  This
  makes the root Hook structure easier to understand, because you
  don't have to read over all the matching properties when wrapping
  your head around Hook.

* Replace the old 'hook' and 'arguments' with a direct embedding of
  the runtime-spec's hook structure.  This provides access to
  additional upstream properties (args[0], env, and timeout) and
  avoids the complication of a CRI-O-specific analog structure.

* Add a 'when.always' property.  You can usually accomplish this
  effect in another way (e.g. when.commands = [".*"]), but having a
  boolean explicitly for this use-case makes for easier reading and
  writing.

* Replace the previous annotations array with an annotations map.  The
  0.1.0 approach matched only the values regardless of key, and that
  seems unreliable.

* Replace 'cmds' with 'when.commands', because while there are a few
  ways to abbreviate "commands", there's only one way to write it out
  in full ;).  This gives folks one less thing to remember when
  writing hook JSON.

* Replace the old "inject if any specified condition matches" with
  "inject if all specified conditions match".  This allows for more
  precise targeting.  Users that need more generous targeting can
  recover the previous behavior by creating a separate 1.0.0 hook file
  for each specified 0.1.0 condition.

I've added doc-compat support for the various pluralizations of the
0.1.0 properties.  Previously, the docs and code were not in
agreement.  More on this particular facet in [1].

I've updated the docs to point out that the annotations being matched
are the OCI config annotations.  This differs from CRI-O, where the
annotations used are the Kubernetes-supplied annotations [2,3].  For
example, io.kubernetes.cri-o.Volumes [4] is part of CRI-O's runtime
config annotations [5], but not part of the Kubernetes-supplied
annotations CRI-O uses for matching hooks.

The Monitor method supports the CRI-O use-case [6].  podman doesn't
need it directly, but CRI-O will need it when we vendor this package
there.

I've used nvidia-container-runtime-hook for the annotation examples
because Dan mentioned the Nvidia folks as the motivation behind
annotation matching.  The environment variables are documented in [7].
The 0.1.0 hook config, which does not allow for environment variables,
only works because runc currently leaks the host environment into the
hooks [8].  I haven't been able to find documentation for their usual
annotation trigger or hook-install path, so I'm just guessing there.

[1]: https://github.com/kubernetes-incubator/cri-o/pull/1235
[2]: https://github.com/kubernetes-incubator/cri-o/blob/v1.10.0/server/container_create.go#L760
[3]: https://github.com/kubernetes-incubator/cri-o/blob/v1.10.0/server/container_create.go#L772
[4]: https://github.com/kubernetes-incubator/cri-o/blob/v1.10.0/pkg/annotations/annotations.go#L97-L98
[5]: https://github.com/kubernetes-incubator/cri-o/blob/v1.10.0/server/container_create.go#L830-L834
[6]: https://github.com/kubernetes-incubator/cri-o/pull/1345/
[7]: https://github.com/NVIDIA/nvidia-container-runtime/tree/v1.3.0-1#environment-variables-oci-spec
[8]: https://github.com/opencontainers/runc/pull/1738

Signed-off-by: W. Trevor King <wking@tremily.us>

Closes: #686
Approved by: mheon
2018-05-11 16:26:35 +00:00
Matthew Heon 177c27e75d Do not error trying to remove cgroups that don't exist
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #507
Approved by: baude
2018-05-11 14:43:57 +00:00
Matthew Heon c4c5c1a3e1 Remove parent cgroup we create with cgroupfs
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #507
Approved by: baude
2018-05-11 14:43:57 +00:00
Matthew Heon 853c5c41f1 Add --cgroup-manager flag to Podman binary
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #507
Approved by: baude
2018-05-11 14:43:57 +00:00
Matthew Heon df83d361e4 Major fixes to systemd cgroup handling
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #507
Approved by: baude
2018-05-11 14:43:57 +00:00
Matthew Heon 15ca5f2687 Add validation for CGroup parents. Pass CGroups path into runc
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #507
Approved by: baude
2018-05-11 14:43:57 +00:00
Giuseppe Scrivano 522a7197a8 podman, userNS: configure an intermediate mount namespace
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #690
Approved by: mheon
2018-05-04 17:15:55 +00:00
Giuseppe Scrivano 73078fabcf networking, userNS: configure the network namespace after create
so that the OCI runtime creates the network namespace from the correct
userNS.

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

Closes: #690
Approved by: mheon
2018-05-04 17:15:55 +00:00
Daniel J Walsh b51d737998 Begin wiring in USERNS Support into podman
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #690
Approved by: mheon
2018-05-04 17:15:55 +00:00
baude 8dfebd4607 varlink containers
first pass at adding in the container related endpoints/methods for the libpod
backend. Couple of important notes:

* endpoints that can use a console are not going to be done until we have "remote" console
* several of the container methods should probably be able to stream as opposed to a one-off return

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

Closes: #708
Approved by: baude
2018-05-03 17:31:33 +00:00
Matthew Heon ab7e2a6956 Store user Volumes, Entrypoint, Command in database
We need these for commit, and they cannot be properly deduced
from just the OCI spec, so save them in the database so we can
retrieve them for commit.

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

Closes: #700
Approved by: rhatdan
2018-05-03 12:23:12 +00:00
Matthew Heon 1ece5d3db7 Update hooks to use config bool to detect volume mounts
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #700
Approved by: rhatdan
2018-05-03 12:23:12 +00:00
umohnani8 6ac8a24db4 Add --default-mounts-file hidden flag
The hidden flag is used to override the path of the default mounts file
for testing purposes.
Also modified the secrets pkg to allow for this override to happen.

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #678
Approved by: mheon
2018-04-26 16:33:25 +00:00
umohnani8 cf41dc70b3 Modify --user flag for podman create and run
If an integer is passed into the --user flag, i.e --user=1234
don't look up the user in /etc/passwd, just assign the integer as the uid.

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #652
Approved by: mheon
2018-04-24 14:28:33 +00:00
umohnani8 57afb7514d Add FIPS mode secret
If the host is in FIPS mode and /etc/system-fips exists
/run/secrets/system-fips is created in the container so that
the container can run in FIPS mode as well.

Signed-off-by: umohnani8 <umohnani@redhat.com>
2018-04-23 13:17:12 -04:00
umohnani8 27107fdac1 Vendor in latest containers/image and contaners/storage
Made necessary changes to functions to include contex.Context wherever needed

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #640
Approved by: baude
2018-04-19 14:08:47 +00:00
Nathan Williams 94f20cdd00 - reverse host field order (ip goes first)
- fix host string split to permit IPv6

Signed-off-by: Nathan Williams <nath.e.will@gmail.com>

Closes: #635
Approved by: rhatdan
2018-04-18 10:58:24 +00:00
TomSweeneyRedHat 6c5ebb0315 Change container.locked to batched
Signed-off-by: TomSweeneyRedHat <tsweeney@redhat.com>

Closes: #619
Approved by: mheon
2018-04-16 15:18:38 +00:00
umohnani8 998fd2ece0 Functionality changes to the following flags
--group-add
	--blkio-weight-device
	--device-read-bps
	--device-write-bps
	--device-read-iops
	--device-write-iops

--group-add now supports group names as well as the gid associated with them.
All the --device flags work now with moderate changes to the code to support both
bps and iops.
Added tests for all the flags.

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #590
Approved by: mheon
2018-04-06 00:09:46 +00:00
Daniel J Walsh fdcf633a33 Add hooks support to podman
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>

Closes: #155
Approved by: mheon
2018-04-05 14:13:49 +00:00
Matthew Heon 98b19aeb0c Refactor dependency checks from init() into public API
Instead of checking during init(), which could result in major
locking issues when used with pods, make our dependency checks in
the public API instead. This avoids doing them when we start pods
(where, because of the dependency graph, we can reasonably say
all dependencies are up before we start a container).

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

Closes: #577
Approved by: rhatdan
2018-04-03 14:57:16 +00:00
Matthew Heon 489d977b22 Ensure dependencies are running before initializing containers
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #577
Approved by: rhatdan
2018-04-03 14:57:16 +00:00
Matthew Heon 0edfce5269 Change errorf to warnf in warning removing ctr storage
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #571
Approved by: rhatdan
2018-04-02 14:22:57 +00:00
Matthew Heon 4553f2914c More gracefully handle unexpected storage deletion
We have other tools using containers/storage. They can delete our
containers in c/storage without us knowing. Try and handle this
better by warning instead of erroring when delete our storage and
it is already gone.

This does not handle cases where libpod thinks the container is
mounted, but it is not. This is harder to check for, because
c/storage Mount() and Unmount() take a layer, image, or container
and that complicates our "container no longer exists" question.
Further work is needed here.

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

Closes: #571
Approved by: rhatdan
2018-04-02 14:22:57 +00:00
umohnani8 8a96b4acbc Add secrets patch to podman
Adds support for mounting secrets especially on RHEL where the container
can use the host subsription to run yum

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #544
Approved by: rhatdan
2018-03-29 14:15:27 +00:00
Daniel J Walsh c54816dfc3 Check for duplicate names when generating new container and pod names.
This fixes the situation where we fail to create a container when a name already exists.

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

Closes: #517
Approved by: baude
2018-03-29 01:55:20 +00:00
Matthew Heon 3f5da4d0dd Make container env variable conditional
Add only when it's not already present.

Add a more specific version in podman spec generation
so we get 'container=podman' not 'container=libpod'

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

Closes: #540
Approved by: baude
2018-03-23 17:28:09 +00:00
Matthew Heon 8ca3bcc85d Add CONTAINER environment variable
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #533
Approved by: baude
2018-03-23 15:22:01 +00:00
Matthew Heon 5fc5b4eacb Document .containerenv in manpages. Move it to /run.
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #533
Approved by: baude
2018-03-23 15:22:01 +00:00
Matthew Heon 75f9fdf21c Add .containerenv file
This will allow programs to easily identify they are running in a
container

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

Closes: #533
Approved by: baude
2018-03-23 15:22:01 +00:00
baude d0835493d5 Migrate podman inspect and tag to image library
Signed-off-by: baude <bbaude@redhat.com>

Closes: #525
Approved by: baude
2018-03-21 19:14:50 +00:00
baude 38a1b2f16d Image library stage 4 - create and commit
Migrate the podman create and commit subcommandis to leverage the images library.  I also had
to migrate the cmd/ portions of run and rmi.

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

Closes: #498
Approved by: mheon
2018-03-20 16:20:12 +00:00
Matthew Heon 1856703e38 Add additional debug logging
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #482
Approved by: baude
2018-03-15 17:45:11 +00:00
Matthew Heon 55f2f58145 Add StartAndAttach() API endpoint for containers
This solves our prior problems with attach races by ensuring the
order is correct.

Also contains substantial cleanups to the attach code.

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

Closes: #482
Approved by: baude
2018-03-15 17:45:11 +00:00
Matthew Heon 02a26c2934 Implement container restarting
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #482
Approved by: baude
2018-03-15 17:45:11 +00:00
baude b85b217f55 Stage3 Image Library
This represents the stage3 implementation for the image library.  At this point, we
are moving the image-centric functions to pkg/image including migration of args and
object-oriented references.  This is a not a one-for-one migration of funcs and some
funcs will need to continue to reside in runtime_img as they are overly specific to
libpod and probably not useful to others.

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

Closes: #484
Approved by: baude
2018-03-14 20:21:31 +00:00
Matthew Heon 40d302be8f Modify pod API to move Init() into Start()
Separate Init() and Start() does not make sense on the pod side,
where we may have to start containers in order to initialize
others due to dependency orders.

Also adjusts internal containers API for more code sharing.

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

Closes: #478
Approved by: rhatdan
2018-03-13 13:54:45 +00:00
Matthew Heon 54f32f2cc0 Convert bind mounts to use DB field
Refactors creation of bind mounts into a separate function that
can be called from elsewhere (e.g. pod start or container
restart). This function stores the mounts in the DB using the
field established last commit.

Spec generation now relies upon this field in the DB instead of
manually enumerating files to be bind mounted in.

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

Closes: #462
Approved by: baude
2018-03-08 16:40:21 +00:00
Matthew Heon fcc3663355 Move internal function resizeTty to container_internal
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #462
Approved by: baude
2018-03-08 16:40:21 +00:00
Matthew Heon 221a3ab2b5 Make WriteStringToRundir internal
We don't want this in our public API - better to let us control
what gets put in container storage and where.

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

Closes: #462
Approved by: baude
2018-03-08 16:40:21 +00:00
Matthew Heon d23b9fd4ed Refactor saving OCI spec to disk into separate function
It will be needed for restarting containers

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

Closes: #462
Approved by: baude
2018-03-08 16:40:21 +00:00
Matthew Heon edb1609c61 Update DB to hold CNI network information
Replace our old IP and Subnet fields in state with CNI types that
contain a lot more information. Retrieve these structs from the
CNI plugins themselves.

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

Closes: #440
Approved by: baude
2018-03-02 19:20:26 +00:00
Matthew Heon c5dc7f81fc Replace usage of runc with runtime
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #412
Approved by: baude
2018-03-01 21:17:51 +00:00
Matthew Heon 83d7ae6506 Fix gofmt & golint
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #412
Approved by: baude
2018-03-01 21:17:51 +00:00
Matthew Heon 8b87a17f56 Add tracking for exec session IDs
Exec sessions now have an ID generated and assigned to their PID
and stored in the database state. This allows us to track what
exec sessions are currently active.

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

Closes: #412
Approved by: baude
2018-03-01 21:17:51 +00:00
baude 6831db7f10 Do not override user mounts
Podman should not override users mounts with default mounts
for /etc/hostname, /etc/resolv.conf, and /etc/hosts.

Resolves issue #388

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

Closes: #401
Approved by: mheon
2018-02-26 18:46:44 +00:00
Matthew Heon eafbe76ebe Refactor spec generation in libpod into a function
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>

Closes: #386
Approved by: baude
2018-02-23 04:25:47 +00:00
umohnani8 3d395767d8 Implement --image-volumes for create and run
--image-volumes tells podman what to do with the image volumes in the image config
There are 3 options: bind, tmpfs, and ignore
bind puts the volume contents in /var/lib/containers/storage/container-id/volumes/vol-dir
and bind mounts it into the container at /vol-dir
tmpfs mounts /vol-dir as a tmps into the container
ignore doesn't mount the image volumes onto the container

Signed-off-by: umohnani8 <umohnani@redhat.com>

Closes: #377
Approved by: rhatdan
2018-02-22 15:14:00 +00:00