Commit Graph

1311 Commits

Author SHA1 Message Date
Purcareata Bogdan-B43198
c94e60d16b Add Dropbear SSH support for lxc-busybox template
Dropbear implements lightweight SSH2 server and client functionality and
is likely to be included in embedded Linux distros.

Signed-off-by: Purcareata Bogdan <B43198@freescale.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-15 12:18:36 -05:00
Serge Hallyn
f6d3e3e470 Implement userid mappings (enable user namespaces)
The 3.8 kernel now supporst uid mappings, so I believe it's appropriate
to proceed with this patchset.
The container config supports new entries of the form:
 lxc.id_map = U 100000 0 10000
 lxc.id_map = G 100000 0 10000
meaning map 'virtual' uids (in the container) 0-10000 to uids
100000-110000 on the host, and same for gids.  So long as there are
mappings specified in the container config, then CONFIG_NEWUSER will
be used when the container is cloned.  This means that container
setup is no longer done with root privilege on the host, only root
privilege in the container.  Therefore cgroup setup is moved from the
init task to the monitor task.

To use this patchset, you currently need to either use the raring
kernel at ppa:serge-hallyn/usern-natty, or build your own kernel
from either git://kernel.ubuntu.com/serge/quantal-userns.git.
(Alternatively you can use Eric's tree at the latest userns-always-map-*
branch at
git://git.kernel.org/pub/scm/linux/kernel/git/ebiederm/user-namespace.git
but you will likely want to at least enable tmpfs mounts in user namespaces)

You also need to chown the files in the container rootfs into the
mapped range.  There is a utility at
https://code.launchpad.net/~serge-hallyn/+junk/nsexec to do this.
uidmapshift does the chowning, while the container-userns-convert
script nicely wraps that program.  So I simply

	sudo lxc-create -t ubuntu -n r1
	sudo container-userns-convert r1 200000

will create a container which is shifted so uid 0 in the container
is uid 200000 on the host.

TODO: when doing setuid(0), need to only do that if 0 is one of the
ids we map to.  Similarly, when dropping capabilities, need to only
not do that if 0 is one of the ids we map to.  However, the question
of what to do for 'weird' containers in private user namespaces is
one I'm punting for later.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-15 12:09:33 -05:00
Serge Hallyn
544a48a0bd setup cgroups from parent
This is a first step to enabling user namespaces.  When starting a
container in a new user namespace, the child will not have the
rights to write to the cgroup fs.  (We can give it that right, but
don't always want to have to).

At the parent, we don't want to setup_cgroups() before the child
has set itself up.  But we also don't want to wait until it has
started running it's init, since that is racy.

Therefore introduce a new sync point.  The child will let the
parent know when it is ready to be confined, and wait for the
parent to respond that it has done so.  Then the child will finish
constraining itself with LSM and seccomp and execute init.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-15 11:57:02 -05:00
Serge Hallyn
c4ea60dff6 clean up syncs
Always unblock parent when child setup fails, rather than just
exiting.

Also remove a duplicate call to setup_cgroup().  We'll want it
close to there for userns, but not right there - that's too late,
and could happen after container init has done something bad
without cgroup restrictions.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-15 11:51:32 -05:00
Christian Seiler
8538f38806 Multiple IP addresses: add them in the correct order
Make sure that when configuring containers that have interfaces containing
multiple IP addresses they are added in the order of the configuration file
(i.e. the first being the primary one) and not the reverse order.

Signed-off-by: Christian Seiler <christian@iwakd.de>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-15 11:36:33 -05:00
Michael H. Warfield
f7bee6c6f3 MAKEDEV call, add autodev hooks, add environment variables for hook scripts.
Ok...  Here's the patch again.  Since Serge is removing the loglevel
structure member, this patch no longer references that element.

From the original description:

1) Removes run_makedev() and the call to it from conf.c per discussion.

2) Adds an lxc.hook.autodev hook.

Note: This hook is very close (one routine level abstracted) from where
the run_makedev was called.  Anyone really rrreeeaaalllyyy needing
MAKEDEV can add it in with a small shim script to do whatever they want
under whatever distro they're using, so no functionality is lost there.

3) Added a number of environment variables for all the hook scripts to
reference to assist in execution.  Things like LXC_ROOTFS_MOUNT could be
very useful but others were added as well.  Room for more if anyone has
an itch.  All in one spot in lxc_start.c.

4) clearenv and putenv( "container=lxc" ) calls were moved to just after
the "start" hook in the container just prior to actually firing up the
container so we could use environment variables prior to that and have
them flushed them before firing up init.  Nice side effect is that you
can define environment variables and then call lxc-start and have them
show up in those hooks scripts.

5) I actually DID update the man page for lxc.conf!  I guess I lied when
I said I wouldn't get that done.

[... and ...]

I added the rcfile to the lxc_conf structure as suggested and moved the
setenv bundle from lxc-start.c over to start.c just prior to calling
run_lxc_hooks for the pre-start hook.

Signed-off-by: Michael H. Warfield <mhw@WittsEnd.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-01-14 14:04:09 -06:00
Serge Hallyn
9ea87d5ded remove logfile and loglevel from struct lxc_conf
The options are still supported in the lxc configuration file.
However they are stored only in local variables in src/lxc/log.c,
which can be read using two new functions:
	int lxc_log_get_level(void);
	const char *lxc_log_get_file(void);

Changelog: jan 14:
 have lxc_log_init use lxc_log_set_file(), have lxc_log_set_file() take
 a const char *, and have it keep its own strdup'd copy of the filename.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-01-14 14:03:57 -06:00
Stéphane Graber
f15b77ca27 lxcutmp.c: Fix typo causing build failure
In a previous change I added an ifdef for HAVE_SYS_TIMERFD_h
rather than HAVE_SYS_TIMERFD_H, leading to a missing include of
sys/timerfd.h on platforms that support it and ultimately to a build
failure.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-13 15:29:26 -05:00
Stéphane Graber
740ee8c775 Fix check for openpty
The previous implementation of the openpty check was always returning
'no' as openpty is typically defined in util.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-11 15:59:33 -05:00
Stéphane Graber
e316c08539 Build lxcutmp.c without timerfd.h or utmpx.h
This adds a local implementation of the bits we need form timerfd.h and
utmpx.h so that the LXC utmp watch can be used with libc that don't implement
the same functions as eglibc.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-11 15:14:51 -05:00
Stéphane Graber
565c2d76a3 Rename utmp.c/utmp.h to lxcutmp.c/lxcutmp.h
This avoids conflict with the system header utmp.h.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-11 15:14:47 -05:00
Stéphane Graber
9be380b07b Add check for sys/timerfd.h
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-11 15:14:44 -05:00
Stéphane Graber
a45bbcedb2 Fix header name in lxcmntent.h
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-11 15:14:41 -05:00
Dwight Engen
59ec0a36c7 use pkg-config to ensure python3-devel is installed
The Python.h header varies in location by distribution, so instead use
pkg-config to ensure the python3 devel package is installed. Tested with
Ubuntu 12.04 and Fedora 17. Fixes --enable-python on Fedora 17.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-11 12:45:48 -05:00
Alexander Vladimirov
1483153487 Add 'config' option to lxc-archlinux template and fix getopt string
This option allows user to control installation repository and options
using alternative pacman configuration file.
Also remove unnecessary sed invocation during container configuration.

Signed-off-by: Alexander Vladimirov <alexander.idkfa.vladimirov@gmail.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-11 12:45:35 -05:00
Stéphane Graber
f298ee50b8 utmp.h: Don't fail when utmpx.h isn't present
Following a comment on the mailing-list, I made utmp.h return -1
when it's disabled, the problem with that is that it prevents the
container from starting completely, which isn't quite what I wanted.

This change makes the function succeed, the container will therefore
start but without utmp handler.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-10 17:41:40 -05:00
Stéphane Graber
cbec003096 Define PR_CAPBSET_READ when missing
PR_CAPBSET_READ isn't defined in bionic, so define it if it's not.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-10 15:38:56 -05:00
Dwight Engen
ed34a67d01 oracle template: fix lxc-shutdown with upstart SIGPWR handler
OL6 uses upstart init and needs a handler for the SIGPWR that
lxc-shutdown sends it so that a container can shut down cleanly.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-09 15:12:39 -05:00
Dwight Engen
e9f2c74c3d fix lxc-shutdown argument parsing
processing of -w or -r shifts an argument that isn't there, messing up
other argument processing

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 15:12:29 -05:00
Stéphane Graber
7af3759fea Makefile.am: Add missing liblxc symlink
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:22:54 -05:00
Stéphane Graber
c1dc38c2e8 Don't call setup_mount_entries if the list is empty
There's no good reason to call setup_mount_entries if we don't have any
lxc.mount.entry. This also avoids an issue on bionic where the tmpfile()
call in setup_mount_entries requires the presence of /tmp which isn't the
case by default.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:22:54 -05:00
Stéphane Graber
fd5c4f9058 tests/Makefile.am: Update for bionic
-lpthread doesn't exist and isn't necessary on bionic.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:22:54 -05:00
Stéphane Graber
5c0f1b3b2f lxc_unshare: Replace getpw*_r by getpw*
Bionic and maybe some other libc implementations lack the _r nss functions.
This replaces our current getpwnam_r and getpwuid_r calls by getpwnam and
getpwuid.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:22:54 -05:00
Stéphane Graber
72f919c42a conf.c: Cleanup __S_ISTYPE
__S_ISTYPE doesn't exist in all C libraries, so define it if it's missing.
Additionaly, replace one occurence where it wasn't actually needed.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:22:54 -05:00
Stéphane Graber
edaf8b1bf1 Add local implementation of mntent.h
Bionic (at least) is missing some of the usual mntent functions.
This adds code defining those that we need when they're missing from the C
library.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:22:48 -05:00
Stéphane Graber
c4b790845d caps.h: Rename __errno to ___errno
At least bionic defines __errno, so this was causing a conflict in caps.h
leading to build failure. Renaming to ___errno avoids that conflicting
definition.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:14:34 -05:00
Stéphane Graber
956edc5496 Replace strdupa call by standard strdup
strdupa appears to only exist in the standard glibc but at least not in bionic.
Replace the two strdupa calls we have by a standard strdup.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:14:20 -05:00
Stéphane Graber
da9dd0f14d Add a bionic_alphasort function on bionic
alphasort doesn't have the right signature on bionic which causes the build to
fail. This implements a new bionic_alphasort function when building on bionic
providing the right signature and a functional equivalent of glibc's alphasort.

This signature problem with alphasort was fixed in upstream bionic but hasn't
been released yet. This commit can therefore be reverted as soon as the
following commit hits the Android NDK: 40e467ec668b59be25491bd44bf348a884d6a68d

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:14:10 -05:00
Stéphane Graber
ffbf58150c Make utmpx.h optional
This adds code detecting the presence of utmpx.h and in its absence, turns the
utmp related functions into no-ops.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:13:59 -05:00
Stéphane Graber
2d76d1d7e5 Workaround missing functions in other libc
Some libc implementation (bionic) is lacking some of the syscall functions
that are present in the glibc.

For those, detect at build time the they are missing and implement a minimal
syscall() wrapper that will essentially give the same result as the glibc
function.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:13:45 -05:00
Stéphane Graber
6ff05e18a3 personality.h: Make the personality code optional
Some platforms don't have personality.h in their C library, this change
adds buildtime detection for the header and turns off the personality setting
code in those cases.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:13:41 -05:00
Stéphane Graber
495d2046f6 Don't hard depend on capability.h and libcap
In the effort to make LXC work with non-standard Linux distros, this change
allows for the user to build LXC without capability support through a new
--disable-capabilities option to configure.

This effectively will cause LXC not to link against libcap and will turn all
the _cap_ functions into no-ops.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:11:56 -05:00
Stéphane Graber
e827ff7e2f tty.h: Ship our own minimal openpty.h
bionic is missing an openpty() function, so ship our own and only
build it and use it on bionic.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:10:32 -05:00
Stéphane Graber
1f1665e6ca clone: Support bionic's clone() defintion
The clone() call in bionic is very slightly different.
This updates namespace.h to support both glibc and bionic.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:10:26 -05:00
Stéphane Graber
9818cae412 conf.c: Define LO_FLAGS_AUTOCLEAR if it's not
LO_FLAGS_AUTOCLEAR isn't defined on bionic, so add an extra ifndef
and set it to its usual value if it's not.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:10:22 -05:00
Stéphane Graber
8173e600ef Add/remove extra includes
While cross-building with bionic, a number of failures were triggered by some
missing includes and in a few cases by extra unused includes.

This commit updates the various headers based on those observations.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:10:18 -05:00
Stéphane Graber
d2717c14d8 Replace get_current_dir_name by getcwd
get_current_dir_name appears to be specific to glibc. Replace that call
by an equivalent getcwd call.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:10:13 -05:00
Stéphane Graber
20d2e91bd3 No need to link against rt and util on bionic
When building on bionic, -lrt and -lutil only cause a build failure.
Dropping those fixes the build, so it appears that the symbols are defined
in the main library.

This commit moves -lrt and -lutil under a !IS_BIONIC check.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:10:02 -05:00
Stéphane Graber
1ba0013f21 Support both getline and fgetln
Some libc implementations don't have the getline function but instead
have an equivalent fgetln function.

Add code to detect both and use whatever is available.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 10:09:36 -05:00
Stéphane Graber
7c11d57a22 Replace all reference to ushort by unsigned short
ushort appears to be a glibc specific type which doesn't exist in
bionic, this commit simply replace all occurences by the equivalent
unsigned short type.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 09:36:46 -05:00
Stéphane Graber
8aa4885c22 configure.ac: Cleanup, comments, indent, ...
This commit doesn't do any functional change to configure.ac but does a fair
amount of cleaning up.

It re-orders the various blocks by type (options, checks, expands, ...).
It also consistently uses tabs for indents.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 09:36:25 -05:00
Stéphane Graber
a6168a17ee configure.ac: Add code to detect bionic C library
This adds a new IS_BIONIC define that can be used to detect whether we are
building with eglibc or with bionic.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-09 09:35:19 -05:00
Alexander Vladimirov
3a32201c5a Set umask before populating /dev and restore it after.
According to docs, mknod clears each permission bit whose
corresponding bit in the process umask is set, so we should fix it
before creating device nodes.

Signed-off-by: Alexander Vladimirov <alexander.idkfa.vladimirov@gmail.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-08 12:07:34 -05:00
Dwight Engen
c5b908a262 oracle template: use url arg to wget repo file
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-08 12:06:59 -05:00
Dwight Engen
d378aebe3d oracle template: drop additional capabilities
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-08 12:06:57 -05:00
Dwight Engen
768487891f document lxc-console escape sequence and argument
Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-08 12:05:43 -05:00
Maximilian Seesslen
29e18143a0 fixed RELEASE_URL for fedora releases higher than 16
The Url for the fedora-release RPM changed in release 17.

Signed-off-by: Maximilian Seesslen <mes@seesslen.net>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-01-04 12:22:14 -05:00
Natanael Copa
bd9a66b20c lxc-ps: fix order of output and fix --lxc opt
We must output the lines from 'ps' in same order for tree views.

Fix also --lxc option to only show processes from containers.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-04 10:11:19 -05:00
Natanael Copa
bc2333ebec lxc-checkconfig: fix colors when using dash
The \e did not work as expected on dash. Replace with proper posix \033

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-04 09:57:22 -05:00
Dwight Engen
d27b0806cd fix lxc-wait waiting forever for FREEZING, FROZEN, THAWED states
These states are kept by the kernel in the freezer.state cgroup item, and
are never set in handler->state with lxc_set_state(). If lxc transitions
a container to/from the freezer after an lxc-wait for one of the above
states has already started, the lxc-wait will never see the new state. This
change has lxc send the new state to the lxc-monitor socket.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-01-03 18:14:07 -05:00