Commit Graph

2879 Commits

Author SHA1 Message Date
Serge Hallyn
198b363fff apparmor: auto-generate the blacklist rules
This uses the generate-apparmor-rules.py script I sent out some time
ago to auto-generate apparmor rules based on a higher level set of
block/allow rules.

Add apparmor policy testcase to make sure that some of the paths we
expect to be denied (and allowed) write access to are in fact in
effect in the final policy.

With this policy, libvirt in a container is able to start its
default network, which previously it could not.

v2: address feedback from stgraber
	  put lxc-generate-aa-rules.py into EXTRA_DIST
	  add lxc-test-apparmor, container-base and container-rules to .gitignore
	  take lxc-test-apparmor out of EXTRA_DIST
	  make lxc-generate-aa-rules.py pep8-compliant
	  don't automatically generate apparmor rules
	  This is only bc we can't be guaranteed that python3 will be
	  available.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-04-01 13:49:43 -04:00
Serge Hallyn
dc8114afd7 apparmor: don't allow mounting cgroupfs by default
Leave the line to do it (commented out) as some users may not be
using cgmanager, and may in fact still need those mounts.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-04-01 13:49:39 -04:00
Stéphane Graber
e6ee584a15 download: Set a 30s timeout for wget request
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-04-01 09:54:37 -05:00
Stéphane Graber
198a3f10d2 tests: Also propagate the https proxy
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-04-01 09:54:35 -05:00
Stéphane Graber
8afb3e612e Use on_path to find init.lxc
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-31 19:56:16 -04:00
Dwight Engen
ba5783a56a lxc.spec: adjust for move of libexecdir/lxc-init to sbin/lxc.init
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-03-31 18:24:21 -05:00
Dwight Engen
7ceebfd12a add yum plugin to repatch rootfs on yum update
oracle-template: Split patching rootfs vs one time setup into separate
shell functions so the template can be run with --patch.

oracle-template: Update to install the yum plugin and itself (as lxc-patch)
into a container. The plugin just runs lxc-patch --patch <path> so it is
fairly generic, but in this case it is running a copy of the template inside
the container.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-03-29 10:37:48 -05:00
Bogdan Purcareata
261658e800 config_network_type: set macvlan default mode to private
If a default mode is not set, the container requires an explicit
mode specified in the config file, otherwise creating the
container fails.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-03-28 19:09:28 -05:00
Serge Hallyn
718e4f4842 move lxc-init to /sbin/init.lxc
Using the multiarch dir causes problems when running lxc-execute
on amd64 with an i386 container.  /sbin/lxc-init is a more confusing
name and will show up in 'lxc<tab>'.  /sbin/init.lxc should be quite
obvious as an init for lxc.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-27 14:23:55 -04:00
Florian Klink
cd698bdd40 check whether rootfs is shared before running pre-mount hooks
this expands c597baa8f9 and 2c6f3fc932.

Also move the block using detect_ramfs_rootfs() from setup_rootfs() to
lxc_setup()

Signed-off-by: Florian Klink <flokli@flokli.de>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-27 14:19:31 -04:00
Bogdan Purcareata
b343592b45 network.c: Add missing LXC_NET_NONE option + refactor
Add LXC_NET_NONE to known lxc_network_types, so parsing a config
file with lxc.network.type = none does not result in failure
(e.g. doc/examples/lxc-no-netns.conf). Options have also been
reordered to match the enum in conf.h.

Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-03-26 09:41:04 -05:00
Serge Hallyn
6168ff15aa commands: handle epipe
If we start a lxc_wait on a container while it is exiting, it is
possible that we open the command socket, then the command socket
monitor closes all its mainloop sockets and exit, then we send our
credentials. Then we get killed by SIGPIPE.

Handle that case, recognizing that if we get sigpipe then the
container is (now) stopped.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-25 18:38:39 -04:00
Stéphane Graber
70084daff6 userns: Update bind-mounted devices
This updates all configs to include the exact same set of 7 bind-mounted
devices:
 - console
 - full
 - null
 - random
 - tty
 - urandom
 - zero

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-24 18:29:36 -04:00
Stéphane Graber
3f09d6d887 lxc-ls: Optimize things a bit
Don't bother access information that the user didn't request.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-24 18:29:34 -04:00
Stéphane Graber
fe9baa4c87 lxc-ls: Fix memory reporting
This resolves the memory math when memsw is enabled and fixes reporting
of nested containers memory when using cgmanager.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-24 18:29:23 -04:00
Bogdan Purcareata
50dbb8209b lxc-busybox: follow symlinks when inspecting busybox binary
Signed-off-by: Bogdan Purcareata <bogdan.purcareata@freescale.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-03-24 14:19:27 -05:00
Michael H. Warfield
826cde7c21 Added root_password_expired password control tuning knob.
Added the environment variable "root_password_expired" to
control if the initial, temporary, root password is initially
set up as "expired".  If set to "yes" (default), the root password
is set as "expired" and the user must change it at first login.

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-22 20:58:08 -04:00
Michael H. Warfield
779b47fdca Support SIGPWR in Fedora and Centos containers.
Added code to catch SIGPWR for Upstart in Fedora and CentOS
containers as well as for Systemd in Fedora containers.

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-22 20:58:03 -04:00
Michael H. Warfield
f5067ecbcc Set timezone for new container if not previously defined.
If the container does not already contain an /etc/localtime
timezone definition, then copy a definition from the host to
the container.  This is often a symlink to an appropriate
system timezone definition files and is presumed to exist in

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-22 20:57:57 -04:00
Michael H. Warfield
dfb2291eca Fix arch cross-build when running distro cross-build.
Corner case existed when building a cross-arch container (i686 on x86_64)
on a cross-distro host (Fedora container on Ubuntu host).  Fixed the
arch "fixup" code to do the right thing when running from the bootstrap.

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-22 20:57:49 -04:00
Dwight Engen
0d9acb997f fix console stdin,stdout,stderr fds
The fds for stdin,stdout,stderr that we were leaving open for /sbin/init
in the container were those from /dev/tty or lxc.console (if given), which
wasn't right. Inside the container it should only have access to the pty
that lxc creates representing the console.

This was noticed because busybox's init was resetting the termio on its
stdin which was effecting the actual users terminal instead of the pty.
This meant it was setting icanon so were were not passing keystrokes
immediately to the pty, and hence command line history/editing wasn't
working.

Fix by dup'ing the console pty to stdin,stdout,stderr just before
exec()ing /sbin/init. Fix fd leak in error handling that I noticed while
going through this code.

Also tested with lxc.console = none, lxc.console = /dev/tty7 and no
lxc.console specified.

V2: The first version was getting EBADF sometimes on dup2() because
lxc_console_set_stdfds() was being called after lxc_check_inherited()
had already closed the fds for the pty. Fix by calling
lxc_check_inherited() as late as possible which also extends coverage
of open fd checked code.

V3: Don't move lxc_check_inherited() since it needs to be called while
the tmp proc mount is still mounted. Move call to lxc_console_set_stdfds()
just before it.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-21 15:03:55 -04:00
KATOH Yasufumi
c43e979d66 Update Japanese lxc-create(1) for 'best' option
Update for commit a526a632e0

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-21 15:00:22 -04:00
Serge Hallyn
79bff4f886 mutex cgmanager access
It looks like either libdbus or libnih is showing some corruption with
threaded access to the cgmanager-client library.  Until we can
straighten that out, mutex access to the cgmanager.

The worst part of this is having to take and drop the mutex at every
fork.  This also means that we can't keep a connection open for the
duration of container startup, since that would deadlock forks.

If we were going to keep it like this, then we could get rid of some
code in start.c.  However we take a performance hit here which I
really hope we can rectify soon.

The other approach we could take would be to keep a global count of
references to cgroup_manager.  Mutex the open, close, and each use
of the cgroup_manager proxy (and the inc/dec of the refcount).  This
way we could in fact keep the connection open for the duration of
container start.  The atfork handler child_fn would have to close
the connection if open.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-21 10:51:36 -04:00
Holger Amann
23e880832b debian: Symlink /etc/mtab
/etc/mtab doesn’t exist after bootstrapping a debian container, and will
be created as regular file after first start.

That leads to at least two errors:
- output of `mount` is wrong and get messed up the more often you
  start/stop the container
- /dev/pts/ptmx has wrong permissions

Signed-off-by: Holger Amann <holger@sauspiel.de>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-21 10:36:34 -04:00
Serge Hallyn
a526a632e0 lxc-create manpage: specify -B best option
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-21 10:25:20 -04:00
Stéphane Graber
ef53625fe1 lxc-debian: Don't eat the argument after -c
Reported-by: Robie Basak <robie.basak@canonical.com>
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-21 10:25:02 -04:00
Stéphane Graber
0cd97e9658 tests: Don't hardcode the cgroup list
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-13 19:09:06 -04:00
Stéphane Graber
4fd0838c69 tests: daemonize in startone
This should finally silence this test for good :)

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-13 11:31:22 -04:00
KATOH Yasufumi
e9c5dc7ba3 Fix typo to checking newgidmap existing
Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-13 10:10:01 -04:00
Stéphane Graber
612c49e1cd tests: Add missing include
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-12 23:52:20 -04:00
Stéphane Graber
53b11e4538 tests: Silence startone harder
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-12 23:48:12 -04:00
Stéphane Graber
3f458ed004 tests: Support cgmanager
When cgmanager is around, use dbus-send to setup the cgroups, this
allows the tests to work in a container without cgroupfs access.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-12 23:28:05 -04:00
Stéphane Graber
3f5004190a tests: Close all fds in startone
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-12 20:56:23 -04:00
Serge Hallyn
b099e9e9bd support lxc.mount.auto for get_config_item and clear_config_item
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-12 20:16:14 -04:00
Serge Hallyn
787c3ebec6 lxc: tests: use busybox template rather than ubuntu
to speed up tests where it doesn't matter

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-12 20:16:11 -04:00
Dwight Engen
395d87ff23 make failure to connect to cgmanager DEBUG instead of ERROR
You can have both cgmanager and cgfs compiled in, and lxc will fall back
at runtime to cgfs if it cannot connect to cgmanager, so print the failure
to connect as a DEBUG like the code used to do.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-03-11 15:00:01 -05:00
Serge Hallyn
a2868fe90b cgmanager: avoid stray dbus connections
There are two parts to this fix.

First, create a private DBusConnection manually, instead of using
nih_dbus_connect.  The latter always creates a shared connection,
which cannot be closed.  Note: creating an actual shared connection,
mutexing it among all threads, and creating per-thread proxies would
be an alternative - however we don't want long-lived connections as
they tend not to be reliable (especially if cgmanager restarts).

Second, use pthread_setspecific to create per-thread keys which can
be associated with destructors.  Specify a destructor which closes
the dbus connection.  If a thread dies while holding cgmanager,
the connection will be closed.  Otherwise, we close the connection
and unset the key.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-11 10:55:44 -04:00
KATOH Yasufumi
800648d24a doc: Update Japanese lxc-autostart(1) for -A option
update for commit e582991fd0

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-11 10:26:25 -04:00
KATOH Yasufumi
9111aa7932 doc: Update Japanese lxc-autostart(1) for -a and -g options
update for commit e447a8a706

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-11 10:26:22 -04:00
Stéphane Graber
1bc1269ba5
lxc-opensuse: Fix syntax error
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-10 17:33:12 -04:00
Serge Hallyn
ba3f32cf15 cgm_destroy: ignore a NULL d->cgroup_path
Depending on where during container creation we failed, cgroup_path
may be NULL.  Don't try to delete the cgroup in that case.

(Also fix a wrong function name in an ERROR message)

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-10 13:02:58 -04:00
Stéphane Graber
1efaeac9ae
Fix broken XML in previous commit
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-10 10:34:56 -04:00
KATOH Yasufumi
465532c424 doc: Update Japanese lxc-ls(1)
update for commit 860490af5d

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-10 10:29:25 -04:00
KATOH Yasufumi
b5dd93f70c doc: Update Japanese lxc-create(1)
update for commit d3de16bb56

Signed-off-by: KATOH Yasufumi <karma@jazz.email.ne.jp>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2014-03-10 10:29:16 -04:00
Serge Hallyn
4b2f98f5f8 check netnsfd before closing
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-03-07 20:39:14 -06:00
Serge Hallyn
94a18c830e fix leak of netnsfd in recent commit
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-03-07 20:38:20 -06:00
Stéphane Graber
1fc64d22ae Don't trigger SYSERROR for optional mounts
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-07 19:13:09 -05:00
Dwight Engen
36eaa69415 fix fd leak in test-concurrent
Opening a debug log for every thread at every iteration of test-concurrent
causes it to quickly run out of fd's because this fd is leaked. Fix this
by adding a new api: lxc_log_close().

As Caglar noted, the log handling is in general a bit "interesting" because
a logfile can be opened through the per-container api
c->set_config_item("lxc.logfile") but lxc_log_fd is now per-thread data. It
just so happens in test-concurrent that there is a 1:1 mapping of threads
to logfiles.

Split out getting debug logs from quiet since I think they are useful
separately. If debug is specified, get a log of any mode, not just during
start.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2014-03-07 16:56:04 -06:00
Stéphane Graber
d3de16bb56 lxc-create: Require --template be passed
It's often been reported that the behavior of lxc-create without -t is a
bit confusing. This change makes lxc-create require the --template
option and introduces a new "none" special value which when set will
fallback to the old template-less behavior.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-07 17:18:51 -05:00
Stéphane Graber
9ec38a6dd7 lxc-ls: Add interfaces field
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2014-03-07 17:18:50 -05:00