Commit Graph

4488 Commits

Author SHA1 Message Date
Tycho Andersen
fa07124900 c/r: remove random line continuations
No idea how these got there, but let's get rid of them since they're weird.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-12-09 22:56:52 -05:00
Tycho Andersen
aef3d51e61 c/r: add a new ->migrate API call
This patch adds a new ->migrate API call with three commands:

MIGRATE_DUMP: this is basically just ->checkpoint()
MIGRATE_RESTORE: this is just ->restore()
MIGRATE_PRE_DUMP: this can be used to invoke criu's pre-dump command on the
    container.

A small addition to the (pre-)dump commands is the ability to specify a
previous partial dump directory, so that one can use a pre-dump of a
container.

Finally, this new API call uses a structure to pass options so that it can
be easily extended in the future (e.g. to CRIU's --leave-frozen option in
the future, for potentially smarter failure handling on restore).

v2: remember to flip the return code for legacy ->checkpoint and ->restore
    calls

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-12-09 22:53:59 -05:00
Tycho Andersen
6bf5b3da1e c/r: bump criu version requirements
Since we're relying on 1.8 for the seccomp stuff, let's refuse to use
anything lower than that.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-12-09 22:53:34 -05:00
Tycho Andersen
8164f0e253 api wrapper: only reset the current config if this call set it
Instead of *always* resetting the current_config to null, we should only
reset it if this API call set it.

This allows nesting of API calls, e.g. c->checkpoint() can pass stuff into
criu.c, which can call c->init_pid() and not lose the ability to log stuff
afterwards.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-12-09 22:53:31 -05:00
Serge Hallyn
23820d548d prune_init_cgroup: don't dereference NULL
This is to avoid:

https://errors.ubuntu.com/problem/d640a68bf7343705899d7ca8c6bc070d477cd845

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2015-12-07 10:14:40 -06:00
Hiroaki Nakamura
988247d5ad Improve the lxc-copy Japanese manpage
Signed-off-by: Hiroaki Nakamura <hnakamur@gmail.com>
2015-12-05 01:08:22 +09:00
KATOH Yasufumi
86b484e979 doc: Add lxc.monitor.unshare to lxc.container.conf(5)
Update for commit a8dfe4e and 6039eaa

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-12-03 13:53:38 -05:00
KATOH Yasufumi
3c08e89391 Add LXC_TARGET env to Japanese lxc.container.conf(5)
Update for commit c154af9

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-12-03 13:53:36 -05:00
KATOH Yasufumi
842948e416 doc: Add Japanese manpage for lxc-copy
Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-12-03 13:53:34 -05:00
Christian Brauner
ca3995947f Conditional compilation for ARM and PPC
Check if symbols SCMP_ARCH_ARM and SCMP_ARCH_PPC are defined.

Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-12-03 13:52:29 -05:00
Serge Hallyn
7635139aa8 seccomp: support 32-bit arm on arm64, and 32-bit ppc on ppc64
Generally we enforce that a [arch] seccomp section can only be used on [arch].
However, on amd64 we allow [i386] sections for i386 containers, and there we
also take [all] sections and apply them for both 32- and 64-bit.

Do that also for ppc64 and arm64.  This allows seccomp-protected armhf
containers to run on arm64.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-12-03 01:15:40 -05:00
Serge Hallyn
480c876b20 apparmor: support lxc.aa_profile = unchanged
In which case lxc will not update the apparmor profile at all.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-12-03 01:14:37 -05:00
Sungbae Yoo
b035f79209 doc: Add Korean manpage for lxc-copy
Update for commit 2b47bac

Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-12-03 01:14:34 -05:00
fli
f2e206ff47 lxc: let lxc-start support wlan phys
The commit: e5848d395c <netdev_move_by_index: support wlan> only
made netdev_move_by_name support wlan, instead of netdev_move_by_index.

Given netdev_move_by_name is a wrapper of netdev_move_by_index, so here
replacing all of the call to lxc_netdev_move_by_index with lxc_netdev_move_by_name
to let lxc-start support wlan phys.

Signed-off-by: fupan li <fupan.li@windriver.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-12-03 01:14:15 -05:00
Wolfgang Bumiller
6039eaa236 doc: lxc.monitor.unshare requires CAP_SYS_ADMIN
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-12-03 01:14:11 -05:00
Wolfgang Bumiller
a8dfe4e08d Added lxc.monitor.unshare
If manual mounting with elevated permissions is required
this can currently only be done in pre-start hooks or before
starting LXC. In both cases the mounts would appear in the
host's namespace.
With this flag the namespace is unshared before the startup
sequence, so that mounts performed in the pre-start hook
don't show up on the host.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-12-03 01:14:08 -05:00
Tycho Andersen
d16ccca80f log: use the right size for timestamp formatting
v2: get rid of extra debug crap

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-12-03 01:13:00 -05:00
Stéphane Graber
c154af98c1 Export LXC_TARGET env variable in stop hook
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-12-03 01:10:30 -05:00
Stéphane Graber
114387972a
debian: Fix container creation on missing cache
This is currently breaking our daily image builds which happen in a
perfectly clean environment without a Debian keyring and without
anything in /var/cache/lxc

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2015-11-20 00:34:09 -05:00
Stéphane Graber
47eb52be9a Merge pull request #702 from hallyn/2015-11-17/comment
lxc_container struct: add comment about moving member fns
2015-11-18 00:18:54 -05:00
Stéphane Graber
e8f6a15cfa Merge pull request #700 from hallyn/2015-11-17/preserve_ns.2
Better handle preserve_ns behavior
2015-11-18 00:18:24 -05:00
Serge Hallyn
e2ae7f6d8c lxc_container struct: add comment about moving member fns
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2015-11-17 23:05:37 -06:00
Stéphane Graber
9dbcd66833 Add getsubopt implementation for Android
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-17 21:25:46 -05:00
Stéphane Graber
0c233eeec5 Merge pull request #701 from hallyn/fixunexp
lxcapi_clone: restore the unexpanded config len
2015-11-17 18:02:10 -05:00
Serge Hallyn
3b39251985 lxcapi_clone: restore the unexpanded config len
Otherwise it gets shortened with the temporary len but never
restored - which will only break API users which do a clone
then continue to use the original container, meaning this is
a hard one to detect.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2015-11-17 15:05:05 -06:00
Serge Hallyn
ab5e52f6a3 Revert "seccomp: handle inverted arch"
It breaks container starts.

This reverts commit 473ebc77d6.
2015-11-17 14:01:04 -06:00
Serge Hallyn
62d05d9b4b Better handle preserve_ns behavior
Commit b6b2b194a8 preserves the container's namespaces for
possible later use in stop hook.  But some kernels don't have
/proc/pid/ns/ns for all the namespaces we may be interested in.
So warn but continue if this is the case.

Implement stgraber's suggested semantics.

 - User requests some namespaces be preserved:
    - If /proc/self/ns is missing => fail (saying kernel misses setns)
    - If /proc/self/ns/<namespace> entry is missing => fail (saying kernel misses setns for <namespace>)
 - User doesn't request some namespaces be preserved:
    - If /proc/self/ns is missing => log an INFO message (kernel misses setns) and continue
    - If /proc/self/ns/<namespace> entry is missing => log an INFO message (kernel misses setns for <namespace>) and continue

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2015-11-17 13:31:08 -06:00
Stéphane Graber
3afe9d723d Merge pull request #692 from fwilson42/master
lxc-ls: use /usr/bin/env to find an appropriate python3 to run
2015-11-17 11:43:56 -05:00
Stéphane Graber
2c3576e721 Merge pull request #693 from hsoft/debian-keyring
Fetch Debian archive GPG keyrings when they're not available
2015-11-17 11:43:19 -05:00
Stéphane Graber
a3ae59c6b1 Merge pull request #697 from hallyn/2015-11-12/seccomp
seccomp: handle inverted arch
2015-11-17 11:42:14 -05:00
Serge Hallyn
5eea90e850 clone: clear the rootfs out of unexpanded config
Closes #694

When we start cloning container c1 to c2, we first save c1's
configuration in c2's as a starting point.  We long ago cleared
out the lxc.rootfs entry before saving it, so that if we are
killed before we update the rootfs, c2's rootfs doesn't point
to c1's.  Because then lxc-destroy -n c2 would delete c1's rootfs.

But when we introduced the unexpanded_config, we didn't update
this code to clear the rootfs out of the unexpanded_config, which
is what now actually gets saved in write_config().

Do so.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-11-17 11:38:52 -05:00
Christian Brauner
8130ebe80f Improve coding style and coding conventions
Local variables should not have the same name as global variables to avoid
confusion.

Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-17 11:36:57 -05:00
Christian Brauner
b84e8c4bb2 Fix mode when creating temporary directory
When we create a random container directory with mkdtemp() we set the mode to
0770 otherwise do_lxcapi_clone() will complain about not being able to create
the config.

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-17 11:35:46 -05:00
Christian Brauner
dca0532e37 Use correct return when clone fails
When the clone failed we tried to destroy the container. This will lead to a
segfault. Instead simply return -1. Also move the call to free_mnts() after the
put label to free the user specified mounts even when we just goto put.

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-17 11:35:44 -05:00
Christian Brauner
2b47bac3f8 Add manpage for lxc-copy
(A trivial fix for lxc-copy is included.)

Signed-off-by: Christian Brauner <christian.brauner@mailbox.org>
2015-11-17 11:32:53 -05:00
Christian Brauner
43cea62db9 Add lxc-copy executable
This is a complete reimplementation of lxc-clone and lxc-start-ephemeral.
lxc-copy merges the functionalities of lxc-clone + lxc-start-ephemeral.

(1) Cloning containers:

	(a) as copy:

		lxc-copy -n aa -N bb

	(b) as snapshot:

		lxc-copy -n aa -N bb -s

(2) Renaming containers:

	lxc-copy -n aa -N bb -R

(3) Starting ephemeral containers:

Ephemeral containers are created and started by passing the flag -e /
--ephemeral. Whenever this flag is missing a copy of the container is created.
The flag -e / --ephemeral implies -s / --snapshot.

	(a) start ephemeral container daemonized with random name:

		lxc-copy -n aa -e

	(b) start ephemeral container in foreground mode with random name:

		lxc-copy -n aa -e -F

	(c) start ephemeral container with specified name in daemonized mode:
	    Analogous to lxc-start ephemeral containers start in daemonized
            mode per default:

		lxc-copy -n aa -N bb -e

	    One can however also explicitly pass -d / --daemon:

		lxc-copy -n aa -N bb -e -d

	    but both commands are equivalent.

	(d) start non-ephemeral container in daemonized mode:

		lxc-copy -n aa -D -e

	(e) start ephemeral container in daemonized mode and keep the original
	    hostname:

		lxc-copy -n aa -K -e

	(f) start ephemeral container in daemonized mode and keep the
	    MAC-address of the original container:

		lxc-copy -n aa -M -e

	(g) start ephemeral container with custom mounts (additional mounts can
            be of type {bind,aufs,overlay}) in daemonized mode:

		lxc-copy -n aa -e -m bind=/src:/dest:ro,aufs=/src:/dest,overlay=/src:/dest

(4) Other options:

	lxc-copy --help

In order to create a random containername and random upper- and workdirs for
custom mounts we use mkdtemp() to not just create the names but also directly
create the corresponding directories. This will be safer and make the code
considerably shorter.

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-17 11:32:07 -05:00
Tycho Andersen
058b94fe0e don't truncate environment sometimes in setproctitle
Instead, let's just allocate new space for the proctitle to live and point
the kernel at that.

v2: take out testing hunk
v3: check return from realloc

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-17 11:32:02 -05:00
Serge Hallyn
473ebc77d6 seccomp: handle inverted arch
lxc uses uname to check the kernel version.  Seccomp respects userspace.  In the case
of 32-bit userspace on 64-bit kernel, this was a bad combination.

When we run into that case, make sure that the compat seccomp context is 32-bit, and
the lxc->seccomp_ctx is the 64-bit.

Closes #654

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2015-11-12 17:22:48 -06:00
Stéphane Graber
f8b2a49ce0 ubuntu-cloud: Various fixes
- Update list of supported releases
 - Make the fallback release trusty
 - Don't specify the compression algorithm (use auto-detection) so that
   people passing tarballs to the template don't see regressions.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-12 12:59:33 -05:00
Virgil Dupras
f16fb156bb Fetch Debian archive GPG keyrings when they're not available
When running the debian template on a non-debian host, it's usual not to
have debian-archive-keyring.gpg. When that happens, we skip the
signature checking of the release, which is dangerous because it's made over
HTTP.

This commit adds automatic fetching of Debian release keys.

Strongly related to #409

Signed-off-by: Virgil Dupras <hsoft@hardcoded.net>
2015-11-10 17:32:22 -05:00
Fox Wilson
e2f91e3434 Use /usr/bin/env python3 instead of /usr/bin/python3 project-wide
This fixes invocations of certain commands when python3 is installed in
a nonstandard path (/usr/local/bin, for example).

Signed-off-by: Fox Wilson <2016fwilson@tjhsst.edu>
2015-11-10 15:53:33 -05:00
Tycho Andersen
2681c0e7ea utils: dialback setproctitle failure message
This isn't in any way fatal, so let's only warn about it with INFO, not
ERROR.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-09 15:42:40 -05:00
Serge Hallyn
529c24df9b coverity: avoid null pointer dereference in cgmanager
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2015-11-09 14:19:12 -06:00
Tycho Andersen
dc259399a4 c/r: use freezer to seize tasks
Instead of relying on the old ptrace loop, we should instead put all the
tasks in the container into the freezer. This will stop them all at the
same time, preventing fork bombs from causing criu to infinite loop (and is
also simply a lot faster).

Note that this uses --freeze-cgroup which isn't in criu 1.7, so it should
only go into master.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-11-06 23:24:31 -05:00
Tycho Andersen
8d2ede581f define PR_SET_MM_MAP & friends if necessary
PR_SET_MM_MAP only went in to the kernel at 3.18 (or 3.19), so we need to
define these for kernels before then. If there was an error, the code
simply logs the failure and continues on.

Also, we can drop the PR_SET_MM_otherstuff contstants since those were
dropped in 93525c00c7.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-11-06 16:08:26 -05:00
Tycho Andersen
c1fd648dd8 c/r: don't require a veth link to c/r
veths can be unconnected in the container's config, and we should handle
this case.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2015-11-06 15:02:36 -05:00
Tycho Andersen
93525c00c7 use PR_SET_MM_MAP instead of PR_SET_MM
PR_SET_MM_MAP can be called as non-root, which we are in the unprivileged
(or nested) case.

Also, let's not do the strcpy() for the new cmdline until after we're sure
the prctl succeeded. This means that even if it does fail, we won't
mutilate the command line like we did before, it just won't be as pretty.

v2: remember to chop off bits of the string that are too long

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-06 14:48:28 -05:00
Christian Brauner
d546aa0e7e Fix calculations in clone_update_unexp_hooks()
Changes v3:
(1) Fix typo (q --> p).

(1) This commit fixes the calculations when updating paths in lxc.hooks.*
    entries. We now also update conf->unexpandend_alloced which hasn't been
done prior to this commit.

(2) Also we use the stricter check:

    	if (p >= lend)
    		continue;

    This should deal better with invalid config files.

(3) Insert some spaces between operators to increase readability.

(4) Use gotos to simplify function and increase readability.

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-06 13:28:23 -05:00
Christian Brauner
030ce9a965 Update absolute paths for overlay and aufs mounts
When using overlay and aufs mounts with lxc.mount.entry users have to specify
absolute paths for upperdir and workdir which will then get created
automatically by mount_entry_create_overlay_dirs() and
mount_entry_create_aufs_dirs() in conf.c. When we clone a container with
overlay or aufs lxc.mount.entry entries we need to update these absolute paths.
In order to do this we add the function update_ovl_paths() in
lxccontainer.c. The function updates the mounts in two locations:

        1) lxc_conf->mount_list

and

        2) lxc_conf->unexpanded_config (by calling clone_update_unexp_ovl_dir())

If we were to only update 2) we would end up with wrong upperdir and workdir
mounts as the absolute paths would still point to the container that serves as
the base for the clone. If we were to only update 1) we would end up with wrong
upperdir and workdir lxc.mount.entry entries in the clone's config as the
absolute paths in upperdir and workdir would still point to the container that
serves as the base for the clone. Updating both will get the job done.

NOTE: This function does not sanitize paths apart from removing trailing
slashes. (So when a user specifies //home//someone/// it will be cleaned to
//home//someone. This is the minimal path cleansing which is also done by
lxc_container_new().) But the mount_entry_create_overlay_dirs() and
mount_entry_create_aufs_dirs() functions both try to be extremely strict about
when to create upperdirs and workdirs. They will only accept sanitized paths,
i.e. they require /home/someone. I think this is a (safety) virtue and we
should consider sanitizing paths in general. In short: update_ovl_paths() does
update all absolute paths to the new container but
mount_entry_create_overlay_dirs() and mount_entry_create_aufs_dirs() will still
refuse to create upperdir and workdir when the updated path is unclean. This
happens easily when e.g. a user calls lxc-clone -o OLD -n NEW -P
//home//chb///.

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-06 13:28:23 -05:00
Christian Brauner
329b36256a Add clone_update_unexp_ovl_paths() function
This functions updates absolute paths for overlay upper- and workdirs so users
can simply clone and start new containers without worrying about absolute paths
in lxc.mount.entry overlay entries.

Signed-off-by: Christian Brauner <christianvanbrauner@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2015-11-06 13:28:23 -05:00