Commit Graph

3097 Commits

Author SHA1 Message Date
Sergio Jimenez
9eaf8a596e Fixed mismatch on ipvX gateway
Signed-off-by: Sergio Jimenez <tripledes@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-10-27 17:42:11 -04:00
Simon Deziel
df7216f664 Create the apt proxy in the cache instead of the 1st container
This addresses https://github.com/lxc/lxc/issues/280.

Signed-off-by: Simon Deziel <simon@sdeziel.info>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-10-27 17:39:24 -04:00
Serge Hallyn
edf77341a5 overlay and aufs clone_paths: be more robust
Currently when we clone a container, bdev_copy passes NULL as dst argument
of bdev_init, then sees bdev->dest (as a result) is NULL, and sets
bdev->dest to $lxcpath/$name/rootfs.  so $ops->clone_paths() can
assume that "/rootfs" is at the end of the path.  The overlayfs and
aufs clonepaths do assume that and index to endofstring-6 and append
delta0.  Let's be more robust by actually finding the last / in
the path.

Then, instead of always setting oldbdev->dest to $lxcpath/$name/rootfs,
set it to oldbdev->src.  Else dir_clonepaths fails when mounting src
onto dest bc dest does not exist.  We could also fix that by creating
bdev->dest if needed, but that addes an empty directory to the old
container.

This fixes 'lxc-clone -o x1 -n x2' if x1 has lxc.rootfs = /var/lib/lxc/x1/x
and makes the overlayfs and aufs paths less fragile should something else
change.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-10-27 17:38:13 -04:00
Serge Hallyn
cfa70b8824 attach: don't use confstr(_CS_PATH)
It is not system-definable, rather glibc sets that to bin:/usr/bin, which is
simply too restrictive.  So just always set our preferred path.

This was reported at:
https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1384327

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-10-27 17:02:07 -04:00
Serge Hallyn
48921d92b5 lxc_global_config_value: simplify the theme
Rather than try to free all the not-being-returned items at
each if clause where we assign one to return value, just NULL
the one we are returning so we can safely free all the
values.  This should fix the newly reported coverity memory
leak

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-10-27 16:55:24 -04:00
Serge Hallyn
6a0c909a37 lxc-start: don't re-try to mount rootfs if we already did so
If we are root using a user namespace and are mounting a blockdev as rootfs,
then we do this before unsharing the userns, because we are not allowed to
do it in a userns.  But after unsharing the userns, we unconditionally
retried mounting the rootfs, resulting in failure.  stop that.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-10-27 16:54:41 -04:00
Tycho Andersen
0080bebf31 c/r: put lxc-restore-net in /usr/share
On restore, we pass criu a script to manage the network interfaces (i.e. the
full path to lxc-restore-net), which we previously installed into
/var/lib/<tuple>/lxc. However, this is also the directory that is the default
for use in mounting the rootfs locally before pivot_root()ing. So, we mounted
the rootfs and then happliy called criu, pointing it to this directory which
didn't have lxc-restore-net any more, it just had the container's rootfs.
Instead, we should put lxc-restore-net somewhere else, so that criu can still
see it after the rootfs is mounted.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-27 11:31:38 -04:00
Dark Templar
bf1e863682 Make legacy lxc-ls more robust
Behave well when /etc/lxc/${name} is a symlink to directory

Signed-off-by: Dark Templar <dark_templar@hotbox.ru>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-27 08:33:04 -05:00
Serge Hallyn
145832ba8b do_rootfs_setup: fix return bugs
Fix return value on bind mount failure.

If we've already mounted the rootfs, exit after the bind mount
rather than re-trying the rootfs mount.  The only case where
this happens is when root is starting a container in a user
namespace and with a block device backing store.

In that case, pre-mount hooks will be executed in the initial
user namespace.  That may be worth fixing.  Or it may be what
we want.  We should think about it and fix it.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-26 22:01:30 -05:00
Serge Hallyn
9fd376e8bc lxc-start: return 0 rather than error if container is already running
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-22 10:54:36 -05:00
Dark Templar
3d8b68b1d5 Fix another gentoo template typo
I've found one more typo in the gentoo template, configuration in the
generated file /etc/conf.d/hostname was not valid, but it didn't impact
me due to "lxc.utsname" being set in the configuration file of container
and hostname service being not used. Anyway, I've made a patch and
sending it with this mail.

Signed-off-by: Dark Templar <dark_templar@hotbox.ru>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-22 09:35:08 -05:00
Bogdan Purcareata
12c3b43fbe busybox template: mount fstab when available
When running unprivileged, lxc-create will touch a fstab file, with bind-mounts
for the ttys and other devices. Add this entry in the container config.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-22 09:18:14 -05:00
Bogdan Purcareata
a542dd3c1a busybox template: support for unprivileged containers
Apply the changes found in templates/lxc-download to the busybox template as
well. Change ownership of the config and fstab files to the unprivileged user,
and the ownership of the rootfs to root in the new user namespace.

Eliminate the "unsupported for userns" flag.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-22 09:18:05 -05:00
KATOH Yasufumi
5e1c5795a3 lxc_global_config_value can return the default lxc.cgroup.pattern whether root or non-root
>>> On Tue, 30 Sep 2014 19:48:09 +0000
    in message   "Re: [lxc-devel] [PATCH] lxc-config can show lxc.cgroup.(use|pattern)"
                  Serge Hallyn-san wrote:

> I think it would be worth also augmenting
> lxc_global_config_value() to return a default lxc.cgroup.use
> for 'all', and a default lxc.cgroup.pattern ("/lxc/%n" for root
> or "%n" for non-root).

lxc.cgroup.pattern is like this? (^_^;)

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-20 16:45:20 -05:00
KATOH Yasufumi
0c3720a336 lxc-config can show lxc.cgroup.(use|pattern)
Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-20 16:45:20 -05:00
Dark Templar
4167102e93 Fix typo in lxc-gentoo template
Signed-off-by: Dark Templar <dark_templar@hotbox.ru>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-20 16:38:32 -05:00
Serge Hallyn
7196c7b37c apparmor: check for mount feature at a better time
Check for it when we check for apparmor being enabled, rather
than doing it during the middle of a container setup.

This avoid the need to try mounting /sys and /sys/kernel/security
in the middle of startup, which we may not be allowed to anyway.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
2014-10-20 16:34:45 -05:00
Serge Hallyn
cc4ae28dd6 fix typo (spurious ';')
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-17 16:43:48 +02:00
Tycho Andersen
e311a56235 c/r: use sizeof instead of magic numbers
Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-17 15:22:02 +02:00
Tycho Andersen
fed29fad60 c/r: refactor the way we pass data to criu/scripts
We previously wrote a bunch of files (eth*, veth*, and bridge*) as hard coded
files which we used as the names of interfaces to restore via criu's
--veth-pair. This meant that if people, e.g. gave a different bridge on their
new host, we would use our saved bridge in bridge* and try to restore to the
wrong bridge. Instead, we can just generate a new veth id (if the user hasn't
provided one), and use whatever the user configured values for the interface
name and bridge are.

This allows people to switch the bridge that they restore onto simply by
migrating the rootfs and config, and then changing the bridge name in the
container's configuration before running lxc-checkpoint.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-17 15:22:02 +02:00
Tycho Andersen
bbd4e13ea5 c/r: factor out network dump/restore code
Break the monolithic ->checkpoint and ->restore functions into smaller ones.
This is in preparation for the checkpoint/restore tty work, which has a similar
need to dump information outside of criu.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-17 15:22:02 +02:00
Serge Hallyn
e5848d395c netdev_move_by_index: support wlan
The python lxc-device supported adding wlan devices, so add that
support as well.  Since the python one did not support 'del',
I didn't try adding that support, though it should be trivial to
add.

We should be able to do the wlan adding using netlink, but I
went ahead and used 'iw' as the netlink path looked more
complicated than it does for other nics.  Patches to switch that
over would be very welcome.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-15 23:22:41 +02:00
Serge Hallyn
e0f5918984 lxccontainer.c: rename enter_to_ns to enter_net_ns
because that's what it does

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-15 12:47:29 +02:00
Dongsheng Yang
ea46796945 lxc-device: rewrite lxc-device.
As there is a function named attach_interface to pass
a interface to container now, we do not need to relay on
python impolementation for lxc-device any more.

changelog: 10/15/2014: serge: fail immediately if run as non-root.
changelog: 10/15/2014: serge: add explicit error message on bad usage (fix build failure)

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-15 12:47:09 +02:00
Dongsheng Yang
cbf535294c python-lxc: Add [at|de]tach_interface() to python binding.
Changelog: 10/15/2014: serge: make ifname mandatory for detach_interface.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-15 12:20:06 +02:00
Dongsheng Yang
e58fae8f29 container: introduce two functions named as {at/de}tach_interface().
Currently, we depends on ip command to attach interface to container.
It means we only implemented it by python.

This patch implement adding and removing interface by c and added
them in struct container.

Changelog: 10/15/2014 (serge): return error if ifname is NULL.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-15 12:17:19 +02:00
Dongsheng Yang
51d0854cd6 utils: move useful helper functions from lxccontainer to utils.
Function of enter_to_ns() is useful but currently is static for
lxccontainer.c.

This patch split it into two parts named as switch_to_newuser()
and switch_to_newnet() into utils.c.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-15 12:02:34 +02:00
Dongsheng Yang
efa1cf45a2 network: introduce a interface named lxc_netdev_isup().
When we need to know some info about a netdev, such as is_up or not,
we need to read the flag for the netdev.

This patch introduce a interface function named lxc_netdev_isup()
to check is a netdev up or down.

And introduce a network private function named netdev_get_flag()
to get flag for netdev by netlink.

Changelog: 10/15/2015: Return failure if name==NULL to avoid later strlen fun

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-15 12:01:59 +02:00
Dongsheng Yang
8d357196c4 network: allow lxc_network_move_by_index() rename netdev in moving.
In netlink, we can set the dest_name of netdev when move netdev
between namespaces in one netlink request. And moving a netdev of
a src_name to a netdev with a dest_name is a common usecase.

So this patch add a parametaer to lxc_network_move_by_index() to
indicate the dest_name for the movement. NULL means same with
the src_name.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-15 11:54:44 +02:00
Dongsheng Yang
312f9c5dfe lxc_start: ERROR if container is already running.
We should exit with a error when starting a running container.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-15 11:54:44 +02:00
Dongsheng Yang
49428bf306 network: check result of if_nametoindex().
When we want to get index of a ifname which does not
exist, we should return a -EINVAL in this case.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-15 11:54:44 +02:00
Dongsheng Yang
599781664b network: convert param ifname to const.
We should not modify ifname in lxc_netdev_move_by_name(),
making it as const in param list will make our code more
robust.

Signed-off-by: Dongsheng Yang <yangds.fnst@cn.fujitsu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-15 11:54:44 +02:00
Stéphane Graber
ecec0126b5
conf.c: Define MS_PRIVATE for Android
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-10-13 12:50:20 +02:00
Serge Hallyn
d9192f5df7 fix lxc.mount.auto clearing
the way config_mount was structured, sending 'lxc.mount.auto = '
ended up actually clearing all lxc.mount.entrys.  Fix that by
moving the check for an empty value to after the subkey checks.
Then, actually do the clearing of auto_mounts in config_mount_auto.

The 'strlen(subkey)' check being removed was bogus - the subkey
either known to be 'lxc.mount.entry', else subkey would have been
NULL (and forced a return in the block above).

This would have been clearer if the config_mount() and helper
fns were structured like the rest of confile.c.  It's tempting
to switch it over, but there are subtleties in there so it's
not something to do without a lot of thought and testing.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-09 12:31:46 -05:00
Serge Hallyn
efdca59e49 lxc-test-apparmor-mount: don't clear out /etc/lxc/lxc-usernet
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-09 12:15:14 -05:00
Serge Hallyn
e2ef635e68 lxc-test-unpriv: test for different cgroups per subsystem
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-09 11:24:37 -05:00
Dwight Engen
f3b8088dd8 systemd/selinux init scripts fixups
- RHEL/OL 7 doesn't have the ifconfig command by default so have the
  lxc-net script check for its existence before use, and fall back
  to using the ip command if ifconfig is not available

- When lxc-net is run from systemd on a system with selinux enabled,
  the mkdir -p ${varrun} will create /run/lxc as init_var_run_t which
  dnsmasq can't write its pid into, so we restorecon it
  after creation (to var_run_t)

- The lxc-net systemd .service file needs an [Install] section so that
  "systemctl enable lxc-net" will work

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
2014-10-08 17:57:33 -04:00
Tycho Andersen
7943ec56e9 lxc-checkpoint: close stdout/stdin when daemonizing
If we don't close these running lxc-checkpoint via:

ssh host "sudo lxc-checkpoint ..."

just hangs. We leave stderr open so that subesquent errors will print correctly
(and also because for whatever reason it doesn't break ssh :).

Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-08 15:18:53 -05:00
Tycho Andersen
2ba7a42989 restore: create cgroups for criu
Previously, we let criu create the cgroups for a container as it was restoring
things. In some cases (i.e. migration across hosts), if the container being
migrated was in /lxc/u1-3, it would be migrated to the target host in
/lxc/u1-3, even if there was no /lxc/u1-2 (or worse, if there was already an
alive container in u1-3).

Instead, we use lxc's cgroup_create, and then tell criu where to restore to.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-08 12:47:30 -05:00
Tycho Andersen
dbb51a4361 restore: Hoist handler to function level
On Tue, Oct 07, 2014 at 07:33:07PM +0000, Tycho Andersen wrote:
> This commit is in preparation for the cgroups create work, since we will need
> the handler in both the parent and the child. This commit also re-works how
> errors are propagated to be less verbose.

Here is an updated version:

From 941623498a49551411ccf185146061f3f37d3a67 Mon Sep 17 00:00:00 2001
From: Tycho Andersen <tycho.andersen@canonical.com>
Date: Tue, 7 Oct 2014 19:13:51 +0000
Subject: [PATCH 1/2] restore: Hoist handler to function level

This commit is in preparation for the cgroups create work, since we will need
the handler in both the parent and the child. This commit also re-works how
errors are propagated to be less verbose.

v2: rename error to has_error, handle it correctly, and remove some diff noise

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-08 12:47:22 -05:00
Tycho Andersen
2566a14517 criu: DECLARE_ARG should check for null arguments
This is in preparation for the cgroups creation work, but also probably just a
good idea in general. The ERROR message is handy since we print line nos. it
will to give people an indication of what arg was null.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-10-08 12:47:13 -05:00
Serge Hallyn
9a64d3cf9f lxc-test-unpriv: don't clear out /etc/lxc/lxc-usernet
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-08 11:31:52 -05:00
Andrey Vagin
91e93c71c7 lxc: don't call pivot_root if / is on a ramfs
pivot_root can't be called if / is on a ramfs. Currently chroot is
called before pivot_root. In this case the standard well-known
'chroot escape' technique allows to escape a container.

I think the best way to handle this situation is to make following actions:
* clean all mounts, which should not be visible in CT
* move CT's rootfs into /
* make chroot into /

I don't have a host, where / is on a ramfs, so I can't test this patch.

Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-08 11:24:52 -05:00
Serge Hallyn
956f113bf0 cgmanager: several fixes
These all fix various ways that cgroup actions could fail if an
unprivileged user's cgroup paths were not all the same for all
controllers.

1. in cgm_{g,s}et, use the right controller, not the first in the list,
   to get the cgroup path.

2. when we pass 'all' to cgmanager for a ${METHOD}_abs, make sure that all
   cgroup paths are the same.  That isn't necessary for methods not
   taking an absolute path, so split up the former
   cgm_supports_multiple_controllers() function into two booleans, one
   telling whether cgm supports it, and another telling us whether
   cgm supports it AND all controller cgroup paths are the same.

3. separately, do_cgm_enter with abs=true couldn't work if all
   cgroup paths were not the same.  So just ditch that helper and
   call lxc_cgmanager_enter() where needed, because the special
   cases would be more complicated.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-10-08 00:14:26 -05:00
Joshua Brunner
f422613e69 fix: grep not match interface listed by ip link list
Interfaces listed by `ip link list` are prefixed with the index
identifier. The pattern "^$BRNAME" does not match.

 - dependencies to ifconfig and ip removed
 - wait until interface flagged with IFF_UP

Ref: https://github.com/torvalds/linux/blob/master/include/uapi/linux/if.h

Signed-off-by: Joshua Brunner <j.brunner@nexbyte.com>
2014-10-06 12:06:27 -04:00
Stéphane Graber
2ba5eb93b8
tests: Fix unpriv test
Don't use $TUSER as it's not defined. Also don't include
lxc-test-usernic in extra_DIST.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-10-02 14:59:35 -04:00
Stéphane Graber
e356822da4
change version to 1.1.0.alpha1 in configure.ac
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-10-01 14:23:41 -04:00
Serge Hallyn
7981ea4684 pivot_root: umount ., not /
This fixes pivot_root on 3.11 and older kernels.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-09-29 18:57:08 -04:00
Stéphane Graber
888cf064dd
sysconfig/lxc: Reverse sourcing logic
This prevents scripts running with -e to fail when lxc-net doesn't
exist.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-09-29 18:43:36 -04:00
Jamie Strandboge
807f4c9e1e apparmor: restrict signal and ptrace for processes
Restrict signal and ptrace for processes running under the container
profile. Rules based on AppArmor base abstraction. Add unix rules for
processes running under the container profile.

Signed-off-by: Jamie Strandboge <jamie@canonical.com>
Acked-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-09-29 12:40:52 -04:00