Commit Graph

3097 Commits

Author SHA1 Message Date
Serge Hallyn
6ad22d063a Update the openvswitch bridge attach code
1. don't determine ovs-vsctl path at configure time, do it at runtime

2. lxc-user-nic: set a sane path to protect from unpriv users

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-22 16:48:31 -05:00
S.Çağlar Onur
361e0e3c08 use lxcpath as unprivileged containers log directory
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-22 16:48:29 -05:00
Serge Hallyn
614305f397 statvfs: do nothing if statvfs does not exist (android/bionic)
If statvfs does not exist, then don't recalculate mount flags
at remount.

If someone does need this, they could replace the code (only
if !HAVE_STATVFS) with code parsing /proc/self/mountinfo (which
exists in the recent git history)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-22 16:47:32 -05:00
Serge Hallyn
e2a7e8dc47 lxc_mount_auto_mounts: honor existing nodev etc at remounts
Same problem as we had with mount_entry().  lxc_mount_auto_mounts()
sometimes does bind mount followed by remount to change options.
With recent kernels it must pass any preexisting NODEV/NOSUID/etc
flags.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-22 14:05:37 -05:00
Serge Hallyn
2938f7c82b mount_entry: use statvfs
Use statvfs instead of parsing /proc/self/mountinfo to check for the
flags we need to and into the msbind mount flags.  This will be faster
and the code is cleaner.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-22 14:05:35 -05:00
Daniel Miranda
d79067a726 build: Fix support for split build and source dirs
Building LXC in a separate target directory, by running configure from
outside the source tree, failed with multiple errors, mostly in the
Python and Lua extensions, due to assuming the source dir and build dir
are the same in a few places. To fix that:

- Pre-process setup.py with the appropriate directories at configure
  time
- Introduce the build dir as an include path in the Lua Makefile
- Link the default container configuration file from the alternatives
  in the configure stage, instead of setting a variable and using it
  in the Makefile

Signed-off-by: Daniel Miranda <danielkza2@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-22 14:05:27 -05:00
Serge Hallyn
d5752559f8 chmod container dir to 0770 (v2)
This prevents u2 from going into /home/u1/.local/share/lxc/u1/rootfs
and running setuid-root applications to get write access to u1's
container rootfs.

v2: set umask to 002 for the mkdir.  Otherwise if umask happens to be,
say, 022, then user does not have write permissions under the container
dir and creation of $containerdir/partial file will fail.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-22 13:58:25 -05:00
Serge Hallyn
d08779d49d load_config_locked: update unexp network
When we read a lxc.network.hwaddr line, if it contained any 'x's then
those get quitely filled in at config_network_hwaddr.  If that happens
then we want to save the autogenerated hwaddr in the unexpanded config
so that when we write it to disk, it is saved.

This patch dumbly re-generates the network configuration in the
unexp configuration every time we load a config file, just as we do
after every clone.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-22 13:58:15 -05:00
S.Çağlar Onur
2eef2bda81 ignore SIGKILL (CTRL-C) and SIGQUIT (CTRL-\) - issue #313
Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-08-22 13:55:07 -05:00
S.Çağlar Onur
cf03f973a8 show additional info if btrfs subvolume deletion fails (issue #315)
Unprivileged users require "-o user_subvol_rm_allowed" mount option for btrfs.
Make the INFO level message to ERROR to make it clear, which now says following;

[caglar@qop:~] lxc-destroy -n rubik
lxc_container: Is the rootfs mounted with -o user_subvol_rm_allowed?
lxc_container: Error destroying rootfs for rubik
Destroying rubik failed

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-08-22 13:52:28 -05:00
Serge Hallyn
61c237221d lxc_map_ids: don't do bogus chekc for newgidmap
If we didn't find newuidmap, then simply require the caller to be
root and write to /proc/self/uidmap manually.  Checking for
newgidmap to exist is bogus.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-08-21 22:50:36 -05:00
TAMUKI Shoichi
ea00a202cd Update plamo template
- If "installpkg" command does not exist, lxc-plamo temporarily
  install the command with static linked tar command into the lxc
  cache directory.  The tar command does not refer to passwd/group
  files, which means that only a few files/directories are extracted
  with wrong user/group ownership.  To avoid this, the installpkg
  command now uses the standard tar command in the system.
- Change mode to 666 for $rootfs/dev/null to allow write access for
  all users.
- Small fix in usage message.

Signed-off-by: TAMUKI Shoichi <tamuki@linet.gr.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
2014-08-19 07:49:01 -04:00
KATOH Yasufumi
8b3374e5e7 doc: Fix Japanese translation of lxc.containers.conf(5)
Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-18 09:01:25 -04:00
Stéphane Graber
c6b861ba64
tests: Call sync before testing a shutdown
This should avoid tests failure when the machine running the tests has
either very slow disks or a lot of data waiting to be flushed.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-18 00:00:59 -04:00
Serge Hallyn
6fd5e7699f do_mount_entry: add nexec, nosuid, nodev, rdonly flags if needed at remount
See http://lkml.org/lkml/2014/8/13/746 and its history.  The kernel now refuses
mounts if we don't add ro,nosuid,nodev,noexec flags if they were already there.

Also use the newly found info to skip remount if unneeded.  For background, if
you want to create a read-only bind mount, then you must first mount(2) with
MS_BIND to create the bind mount, then re-mount(2) again to get the new mount
options to apply.  So if this wasn't a bind mount, or no new mount options were
introduced, then we don't do the second mount(2).

null_endofword() and get_field() were not changed, only moved up in
the file.

(Note, while I can start containers inside a privileged container with
this patch, most of the lxc tests still fail with the kernel in question;
Andy's patch seems to still be needed - a kernel with which is available
at https://launchpad.net/~serge-hallyn/+archive/ubuntu/userns-natty
ppa:serge-hallyn/userns-natty)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-17 23:40:28 -04:00
Serge Hallyn
073135baa7 monitor: fix sockname calculation for long lxcpaths
A long enough lxcpath (and small PATH_MAX through crappy defines) can cause
the creation of the string to be hashed to fail.  So just use alloca to
get the size string we need.

More importantly, while I can't explain it, if lxcpath is too long, setting
sockname[sizeof(addr->sun_path)-2] to \0 simply doesn't seem to work.  So set
sockname[sizeof(addr->sun_path)-3] to \0, which does work.

With this, and with

lxc.lxcpath = /opt/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789/lxc0123456789

in /etc/lxc/lxc.conf, I can run lxc-wait just fine.  Without it, it fails
(as does lxc-start -d, which uses lxc_wait to verify the container started)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-17 23:39:02 -04:00
Serge Hallyn
e85898415c command socket: use hash if needed
The container command socket is an abstract unix socket containing
the lxcpath and container name.  Those can be too long.  In that case,
use the hash of the lxcpath and lxcname.  Continue to use the path and
name if possible to avoid any back compat issues.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-17 23:38:56 -04:00
Stéphane Graber
da8c55e6ec Revert "chmod container dir to 0770"
This commit broke the testsuite for unprivileged containers as the
container directory is now 0750 with the owner being the container root
and the group being the user's group, meaning that the parent user can
only enter the directory, not create entries in there.

This reverts commit c86da6a3ac.
2014-08-16 17:16:36 -04:00
Stéphane Graber
4a7e5f4f20
Fix typo in the previous commit...
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-15 21:32:34 -04:00
Micahel J. Evans
c08220e9d1 Add extra debugging
This is an hybrid between Micahel's original patch and me making the new
debugging statements look like our existing ones.

Signed-off-by: "Micahel J. Evans" <mjevans1983@gmail.com>
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-15 21:21:05 -04:00
Denis Pynkin
a9ae28a05a Updated template for ALTLinux.
- Added predefined package list if /etc/lxc/profiles/default is absent.
- Fixed syntax mistake in options list.

Signed-off-by: Denis Pynkin <dans@altlinux.ru>
Acked-by: Stéphne Graber <stgraber@ubuntu.com>
2014-08-15 21:09:34 -04:00
Lars Wikberg
70bb1a9ca7 doc: language correction
Signed-off-by: Lars Wikberg <lars.wikberg@anvia.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-15 21:08:23 -04:00
Jean-Tiare LE BIGOT
1c90734de6 As discussed on ML, do not clean autodev dir on reboot
Signed-off-by: Jean-Tiare LE BIGOT <jean-tiare.le-bigot@ovh.net>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-15 21:07:35 -04:00
Jean-Tiare LE BIGOT
f0d029502f clean autodev dir on container exit
When "lxc.autodev = 1", LXC creates automatically a "/dev/.lxc/<name>.<hash>"
folder to put container's devices in so that they are visible from both
the host and the container itself.

On container exit (ne it normal or not), this folder was not cleaned
which made "/dev" folder grow continuously.

We fix this by adding a new `int lxc_delete_autodev(struct lxc_handler
*handler)` called from `static void lxc_fini(const char *name, struct
lxc_handler *handler)`.

Signed-off-by: Jean-Tiare LE BIGOT <jean-tiare.le-bigot@ovh.net>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-15 21:07:21 -04:00
Serge Hallyn
c86da6a3ac chmod container dir to 0770
This prevents u2 from going into /home/u1/.local/share/lxc/u1/rootfs
and running setuid-root applications to get write access to u1's
container rootfs.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
2014-08-15 21:05:20 -04:00
Serge Hallyn
9e43c35232 cgmanager get/set: clean up child (v2)
(Thanks, Dwight, this one look right?)

Make sure we reap our child at cgm_{s,g}et.

Changelog: Fix change in behavior on empty read from the do_cgm_get()
           helper that was spotted by Dwight.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Dwight Engen <dwight.engen@oracle.com>
2014-08-15 21:05:09 -04:00
S.Çağlar Onur
1c1bb85ad2 introduce --with-distro=raspbian
Raspberry Pi kernel finally supports all the bits required by LXC [1]

This patch makes "./configure --with-distro=raspbian" to install lxcbr0
based config file and upstart jobs.
Also src/lxc/lxc.net now checks the existence of the lxc-dnsmasq user
(and fallbacks to dnsmasq)

RPI users still need to pass
"MIRROR=http://archive.raspbian.org/raspbian/" parameter to lxc-create
to pick the correct packages

MIRROR=http://archive.raspbian.org/raspbian/ lxc-create -t debian -n rpi

[Could be applied to stable-1.0 if you cherry-pick
7157a508ba3015b830877a5e4d6ca9debb3fd064]

[1] https://github.com/raspberrypi/linux/issues/176

Signed-off-by: S.Çağlar Onur <caglar@10ur.org>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-08-15 21:04:35 -04:00
Serge Hallyn
3ad30ff74f lxc-test-unpriv: test lxc-clone -s
This would have caught a regression in Ubuntu's 3.16 kernel.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-15 21:03:16 -04:00
Serge Hallyn
8873e65ea9 coverity: malloc the right size for btrs_node tree
We were allocating sizeof(tree) instead of sizeof(*tree).

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-15 21:03:14 -04:00
Serge Hallyn
05d53f4c0d coverity: don't use newname after null check
Actually, get rid of the temporary variables, and set newname
and lxcpath to usable values if they were NULL.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-15 21:03:12 -04:00
KATOH Yasufumi
48e60dfeef doc: add lxc.console.logpath to Japanese lxc.container.conf(5)
Update for commit 96f15ca

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-15 21:03:09 -04:00
Stéphane Graber
206a255e17
ubuntu: Check that btrfs is actually available
Before calling btrfs and playing with subvolumes, let's make sure the
btrfs command is available.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-15 19:59:45 -04:00
Serge Hallyn
b91f00d347 log_path: free on lxc_conf free (for master)
This is for the master branch, to fix a memleak on conf free.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-08 14:34:50 -04:00
Jean-Tiare LE BIGOT
7e40254ab7 Ensure /dev/pts directory exists on pts setup
When `lxc.autodev = 0` and empty tmpfs is mounted on /dev
and private pts are requested, we need to ensure '/dev/pts'
exists before attempting to mount devpts on it.

Signed-off-by: Jean-Tiare LE BIGOT <jean-tiare.le-bigot@ovh.net>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-08 12:20:19 -04:00
Vincent Giersch
3603af1bc7 Fix a file descriptor leak in the monitord spawn
Signed-off-by: Vincent Giersch <vincent.giersch@ovh.net>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-08 12:19:39 -04:00
Vincent Giersch
9581b4b739 Fix a file descriptor leak in the daemonization
Especially when using the Python API, the child process inherits of
the file descriptiors of the script.

Signed-off-by: Vincent Giersch <vincent.giersch@ovh.net>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-08 12:19:26 -04:00
Jean-Tiare LE BIGOT
a90842e41e fix '--log-priority' --> '--logpriority' in main
Signed-off-by: Jean-Tiare LE BIGOT <jean-tiare.le-bigot@ovh.net>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-08 12:17:45 -04:00
rabisg
b69e7bf14e Use portageq to determine portage distdir
Signed-off-by: Rabi Shanker Guha <guha.rabishankar@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-08 12:17:02 -04:00
Kalman Olah
91c5c53f59 Include hostname in DHCP requests
With the current old CentOS template, dnsmasq was not able to resolve
the hostname of an lxc container after it had been created. This minor
change rectifies that.

Signed-off-by: Kalman Olah <hello@kalmanolah.net>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-08 12:15:07 -04:00
Nikolay Martynov
b78b2e23a1 ssh: send hostname to dhcp server
Send container's hostname to dhcp server when getting ip address.

Signed-off-by: Nikolay Martynov <mar.kolya@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-08 12:14:19 -04:00
Michael Werner
4849ab991b templates: switch from arch command to uname -m
Signed-off-by: Michael Werner <xaseron@googlemail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-08 12:12:21 -04:00
Serge Hallyn
cdd01be26e Do not allow snapshots of LVM backed containers
They don't work right now, so until we fix that, don't allow it.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-08 11:40:06 -04:00
Serge Hallyn
68c36a303f ubuntu templates: don't check for $rootfs/run/shm
/dev/shm must be turned from a directory into a symlink to /run/shm.
The templates do this only if they find -d $rootfs/run/shm.  Since /run
will be a tmpfs, checking for it in the rootfs is silly.  It also is
currently broken as ubuntu cloud images have an empty /run.

(this should fix https://bugs.launchpad.net/ubuntu/+source/lxc/+bug/1353734)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-08 11:40:03 -04:00
Serge Hallyn
96f15ca18c add lxc.console.logpath
v2: add get_config_item

clear_config_item is not supported, as it isn't for lxc.console, bc
you can do 'lxc.console.logfile =' to clear it.  Likewise save_config
is not needed because the config is now just written through the
unexpanded char*.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-06 18:43:34 -04:00
Stéphane Graber
281b843648
Add lxc.net to the dist tarball
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-04 16:15:46 -04:00
Serge Hallyn
6b0d553864 unexpanded config file: turn into a string
Originally, we only kept a struct lxc_conf representing the current
container configuration.  This was insufficient because lxc.include's
were expanded, so a clone or a snapshot would contain the expanded
include file contents, rather than the original "lxc.include".  If
the host's include files are updated, clones and snapshots would not
inherit those updates.

To address this, we originally added a lxc_unexp_conf, which mirrored
the lxc_conf, except that lxc.include was not expanded.

This has its own cshortcomings, however,  In particular, if a lxc.include
has a lxc.cgroup setting, and you use the api to say:

c.clear_config_item("lxc.cgroup")

this is not representable in the lxc_unexp_conf.  (The original problem,
which was pointed out to me by stgraber, was slightly different, but
unlike this problem it was not unsolvable).

This patch changes the unexpanded configuration  to be a textual
representation of the configuration.  This allows us *order* the
configuration commands, which is what was not possible using the
struct lxc_conf *lxc_unexp_conf.

The write_config() now becomes a simple fwrite.  However, lxc_clone
is slightly complicated in parts, the worst of which is the need to
rewrite the network configuration if we are changing the macaddrs.

With this patch, lxc-clone and clear_config_item do the right thing.
lxc-test-saveconfig and lxc-test-clonetest both pass.

There is room for improvement - multiple calls to

c.append_config_item("lxc.network.link", "lxcbr0")

will result in multiple such lines in the configuration file.  In that
particular case it is harmless.  There may be cases where it is not.

Overall, this should be a huge improvement in terms of correctness.

Changelog: Aug 1: updated to current lxc git head.  All lxc-test* and
   python api test passed.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-04 15:50:44 -04:00
Serge Hallyn
ff462013b6 btrfs: support recursive subvolume deletion (v2)
Pull the #defines and struct definitions for btrfs into a separate
.h file to not clutter bdev.c

Implement btrfs recursive delete support

A non-root user isn't allow to do the ioctls needed for searching (as you can
verify with 'btrfs subvolume list').  So for an unprivileged user, if the
rootfs has subvolumes under it, deletion will fail.  Otherwise, it will
succeed.

Changelog: Aug 1:
  . Fix wrong objid passing when determining directory paths
  . In do_remove_btrfs_children, avoid dereferencing NULL dirid
  . Fix memleak in error case.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-04 15:48:40 -04:00
KATOH Yasufumi
3ca73691b9 doc: Add 'zfs' to the parameter of -B option in lxc-create(1)
Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-04 15:46:49 -04:00
KATOH Yasufumi
03c315afc1 doc: Update the description of SELinux in Japanese lxc.container.conf(5)
Update for commit 719fae0

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-04 15:46:47 -04:00
KATOH Yasufumi
9231d3a4bb doc: Add the description of lxc.environment to Japanese lxc.container.conf(5)
Update for commit 7c66172

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-04 15:46:45 -04:00