Commit Graph

3574 Commits

Author SHA1 Message Date
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
KATOH Yasufumi
36c94e0d58 doc: Change default to "-d" in Japanese lxc-start(1)
Update for commit c00f3f3

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-04 15:46:42 -04:00
KATOH Yasufumi
22c36623bb doc: Add -F option to Japanese lxc-start(1)
Update for commit 476d302

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-04 15:46:40 -04:00
Martin Pitt
882ab607fd Install systemd units for Ubuntu
Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-08-04 15:44:49 -04:00
Martin Pitt
2b24e2ff84 systemd: Load AppArmor profiles if necessary/supported
On Ubuntu we need to set up the AppArmor profiles also under systemd.
Add a new helper "lxc-apparmor-load" and integrate it into lxc.service.

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-08-04 15:24:39 -04:00
Martin Pitt
84b3775a09 systemd: Ensure action() is defined
If /etc/rc.d/init.d/functions is not present or does not define an action()
function, provide a simple fallback using "echo".

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-08-04 15:24:20 -04:00
Martin Pitt
65b27d845f Add systemd unit for lxc.net
This is the equivalent of the upstart lxc-net.conf to set up the LXC bridge.

This also drops "lxc.service" from tarballs. It is built source which depends
on configure options, so the statically shipped file will not work on most
systems.

https://launchpad.net/bugs/1312532

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-08-04 15:24:17 -04:00
Martin Pitt
213b0fe063 Get systemd unit dir from pkg-config
Don't install systemd unit files into $(prefix), they won't work there.
Instead, get them from systemd's pkg-config file.

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-08-04 15:24:13 -04:00
Martin Pitt
2ed776214a Move lxcbr0 setup logic into lxc.net script
Factor this out of the lxc-net.conf upstart job, so that it can be used by
init.d scripts and systemd units, too.

Part of https://launchpad.net/bugs/1312532

Signed-off-by: Martin Pitt <martin.pitt@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-08-04 15:24:03 -04:00
Serge Hallyn
a96a8e8c09 use non-thread-safe getpwuid and getpwgid for android
We only call it (so far) after doing a fork(), so this is fine.  If we
ever need such a thing from threaded context, we'll simply need to write
our own version for android.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-07-31 15:58:31 -04:00
Serge Hallyn
97e9cfa02f print a helpful message if creating unpriv container with no idmap
This gives me:

ubuntu@c-t1:~$ lxc-create -t download -n u1
lxc_container: No mapping for container root
lxc_container: Error chowning /home/ubuntu/.local/share/lxc/u1/rootfs to container root
lxc_container: You must either run as root, or define uid mappings
lxc_container: To pass uid mappings to lxc-create, you could create
lxc_container: ~/.config/lxc/default.conf:
lxc_container: lxc.include = /etc/lxc/default.conf
lxc_container: lxc.id_map = u 0 100000 65536
lxc_container: lxc.id_map = g 0 100000 65536
lxc_container: Error creating backing store type (none) for u1
lxc_container: Error creating container u1

when I create a container without having an id mapping defined.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-07-31 14:17:04 -04:00
Dwight Engen
719fae07bf provide an example SELinux policy for older releases
The virtd_lxc_t type provided by the default RHEL/CentOS/Oracle 6.5
policy is an unconfined_domain(), so it doesn't really enforce anything.
This change will provide a link in the documentation to an example
policy that does confine containers.

On more recent distributions with new enough policy, it is recommended
not to use this sample policy, but to use the types already available
on the system from /etc/selinux/targeted/contexts/lxc_contexts, ie:

process = "system_u:system_r:svirt_lxc_net_t:s0"
file = "system_u:object_r:svirt_sandbox_file_t:s0"

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-07-31 14:12:25 -04:00
Stéphane Graber
ab799c0ba9 Add the remaining bits for lxc.environment
This adds the few missing bits so that the new lxc.environment config
entry can be queried, cleared and saved as the others are.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-07-31 13:54:36 -04:00
Matt Palmer
7c6617262d Support providing env vars to container init
It's quite useful to be able to configure containers by specifying
environment variables, which init (or initscripts) can use to adjust the
container's operation.

This patch adds one new configuration parameter, `lxc.environment`, which
can be specified zero or more times to define env vars to set in the
container, like this:

    lxc.environment = APP_ENV=production
    lxc.environment = SYSLOG_SERVER=192.0.2.42
    lxc.environment = SOMETHING_FUNNY=platypus

Default operation is unchanged; if the user doesn't specify any
lxc.environment parameters, the container environment will be what it is
today ('container=lxc').

Signed-off-by: Matt Palmer <mpalmer@hezmatt.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-07-31 13:54:20 -04:00
Stéphane Graber
acabe1faee download: Have wget retry 3 times
This forces wget to retry if it gets a network error.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-07-31 13:47:01 -04:00
Stéphane Graber
c00f3f36e1 lxc-start: Daemonize by default
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-07-31 13:46:51 -04:00
Stéphane Graber
476d302ca2 lxc-start: Add -F (foreground) option
Introduce a new -F option (no-op for now) as an opposite of -d.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-07-31 13:46:31 -04:00
hallyn
b1814e1c69 Merge pull request #285 from martinpitt/master
apparmor: Allow slave bind mounts
2014-07-30 09:53:36 -05:00
Martin Pitt
7987eddb9f apparmor: Allow slave bind mounts
Without this, if the system uses shared subtrees by default (like systemd), you
get a large stream of

  lxc-start: Permission denied - Failed to make /<mountpoint> rslave
  lxc-start: Continuing...

with

  apparmor="DENIED" operation="mount" info="failed flags match" error=-13
  profile="/usr/bin/lxc-start" name="/" pid=17284 comm="lxc-start" flags="rw, slave"

and eventual failure plus a lot of leftover mounts in the host.

https://launchpad.net/bugs/1325468
2014-07-30 16:43:10 +02:00
Trần Ngọc Quân
04cda6d1d3 add help string for ubuntu templete
Signed-off-by: Trần Ngọc Quân <vnwildman@gmail.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-07-29 08:34:23 -05:00
Serge Hallyn
e2dafcdab9 fix typo in btrfs error msg
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-07-27 10:53:54 -05:00
Serge Hallyn
f50b163d1d fix typo
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-07-23 10:19:24 -05:00
Serge Hallyn
0d2047716a Support openvswitch bridges
We detect whether ovs-vsctl is available.  If so, then we support
adding network interfaces to openvswitch bridges with it.

Note that with this patch, veths do not appear to be removed from the
openvswitch bridge.  This seems a bug in openvswitch, as the veths
in fact do disappear from the system.  If lxc is required to remove
the port from the bridge manually, that becomes more complicated
for unprivileged containers, as it would require a setuid-root
wrapper to be called at shutdown.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-07-23 09:43:10 -05:00
Serge Hallyn
8aecd66b49 unprivileged containers: use next available nic name if unspecified
Rather than always using eth0.  Otherwise unpriv containers cannot have
multiple lxc.network.type = veth's without manually setting
lxc.network.name =.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-07-23 09:42:16 -05:00