Commit Graph

6411 Commits

Author SHA1 Message Date
Christian Brauner
e749acdf31
Merge pull request #2075 from stgraber/master
lxc_get_version() should show the "-devel" suffix
2018-01-06 10:25:18 +01:00
Stéphane Graber
5f98011c3e
Include -devel suffix in version string
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2018-01-05 16:25:28 -05:00
Stéphane Graber
78c164840c
Fix broken indentation
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2018-01-05 15:19:30 -05:00
Serge Hallyn
a3f5fbb39a
Merge pull request #2067 from brauner/2018-01-03/allow_fully_unprivileged_containers
conf: write "deny" to /proc/[pid]/setgroups
2018-01-04 10:26:01 -06:00
Serge Hallyn
4f5e5b78c8
Merge pull request #2068 from brauner/2018-01-03/cleanup_command_after_revert
commands: fully revert set_running_config_item()
2018-01-04 10:21:17 -06:00
Christian Brauner
bd8ef4e4da
cgfsng: only establish mapping once
When we deleted cgroups for unprivileged containers we used to allocate a new
mapping and clone a new user namespace each time we delete a cgroup. This of
course meant - on a cgroup v1 system - doing this >= 10 times when all
controllers were used. Let's not to do this and only allocate and establish a
mapping once.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-04 15:28:12 +01:00
Christian Brauner
dcf0ffdf41
conf: rework userns_exec_1()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-04 15:01:06 +01:00
Christian Brauner
c7e345ae1f
conf: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-04 15:00:39 +01:00
Christian Brauner
a19b974f42
conf: write "deny" to /proc/[pid]/setgroups
When fully unprivileged users run a container that only maps their own {g,u}id
and they do not have access to setuid new{g,u}idmap binaries we will write the
idmapping directly. This however requires us to write "deny" to
/proc/[pid]/setgroups otherwise any write to /proc/[pid]/gid_map will be
denied.

On a sidenote, this patch enables fully unprivileged containers. If you now set
lxc.net.[i].type = empty no privilege whatsoever is required to run a container.

Enhances #2033.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Felix Abecassis <fabecassis@nvidia.com>
Cc: Jonathan Calmels <jcalmels@nvidia.com>
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-04 11:57:09 +01:00
Christian Brauner
a8ca11c215
Merge pull request #2069 from stgraber/master
gentoo: Add support for .xz tarballs
2018-01-04 10:29:43 +01:00
Christian Brauner
773f442e3f
Merge pull request #2070 from hallyn/2018-01-03/staticlibcap
configure.ac: fix the check for static libcap
2018-01-04 10:29:18 +01:00
Serge Hallyn
c06ed219c4 configure.ac: fix the check for static libcap
The existing check doesn't work, because when you statically
link a program against libc, any functions not called are not
included.  So cap_init() which we check for is not there in
the built binary.

So instead just check whether a "gcc -lcap -static" works.
If libcap.a is not available it will fail, if it is it will
succeed.

Signed-off-by: Serge Hallyn <shallyn@cisco.com>
2018-01-03 21:09:10 -06:00
Stéphane Graber
71ac47aba1
gentoo: Add support for .xz tarballs
Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
2018-01-03 18:06:33 -05:00
Christian Brauner
a3edf26779
commands: fully revert set_running_config_item()
The noop implementation is pointless.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-03 18:28:58 +01:00
Stéphane Graber
acd546adad
Merge pull request #2065 from brauner/2017-01-01/revert_set_running_config_item
lxccontainer: revert set_running_config_item()
2018-01-03 12:12:39 -05:00
Serge Hallyn
fd7374db34
Merge pull request #2066 from brauner/2017-01-02/support_no_root_mappings
Support configurations without root mapping
2018-01-02 21:42:06 -06:00
Christian Brauner
f49007111e
conf: detect if devpts can be mounted with gid=5
Closes #2033.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-03 00:12:53 +01:00
Christian Brauner
4160c3a088
cgfsng: use init {g,u}id
If no id mapping for the container's root id is defined try to us the id
mappings specified via lxc.init.{g,u}id.

Closes #2033.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-03 00:12:50 +01:00
Christian Brauner
46ad64ab26
conf{ile}: detect ns{g,u}id mapping for root
Closes #2033.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-03 00:12:45 +01:00
Christian Brauner
db7cfe23ab
conf: adapt userns_exec_1()
Closes #2033.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-03 00:12:38 +01:00
Christian Brauner
c433319551
conf: adapt idmap helpers
- mapped_hostid_entry()
- idmap_add()

Closes #2033.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-03 00:12:24 +01:00
Christian Brauner
d393e64525
lxccontainer: revert set_running_config_item()
- As discussed we will have a proper API extension that will allow updating
  various parts of a running container. The prior approach wasn't a good idea.

- Revert this is not a problem since we haven't released any version with the
  set_running_config_item() API extension.

- I'm not simply reverting so that master users can still call into new
  liblxc's without crashing the container. This is achieved by keeping the
  commands callback struct member number identical.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2018-01-01 21:58:09 +01:00
Serge Hallyn
2b33c8bf12
Merge pull request #2062 from brauner/2017-12-25/capture_output_of_short_lived_init_process
mainloop: capture output of short-lived init procs
2017-12-30 17:27:48 -06:00
Christian Brauner
12c2798ed1
mainloop: use epoll_create1(EPOLL_CLOEXEC)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-30 23:33:55 +01:00
Christian Brauner
a63fade55b
console: do not allow non-pty devices on open()
We don't allow non-pty devices anyway so don't let open() create unneeded
files.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-30 23:33:54 +01:00
Christian Brauner
1cc8bd4b61
start: properly cleanup mainloop
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-30 23:33:49 +01:00
Christian Brauner
22840b791d
Merge pull request #2063 from marcosps/lxcconfig_help
lxc_config: Add -h and --help flags handler
2017-12-30 21:05:41 +01:00
Marcos Paulo de Souza
f63ac53e31 lxc_config: Add -h and --help flags handler
As the other tools already handle, show usage message when -h or --help
are used.

Signed-off-by: Marcos Paulo de Souza <marcos.souza.org@gmail.com>
2017-12-30 16:35:52 -02:00
Christian Brauner
3c319edbb0
mainloop: capture output of short-lived init procs
The handler for the signal fd will detect when the init process of a container
has exited and cause the mainloop to close. However, this can happen before the
console handlers - or any other events for that matter - are handled. So in the
case of init exiting we still need to allow for all buffered input to the
console to be handled before exiting. This allows us to capture output from
short-lived init processes.

This is conceptually equivalent to my implementation of ExecReaderToChannel()
https://github.com/lxc/lxd/blob/master/shared/util_linux.go#L527

Closes #1694.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-26 11:47:15 +01:00
Christian Brauner
a529bc25cd
mainloop: add mainloop macros
This makes it clearer why handlers return what value.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-26 11:31:39 +01:00
Serge Hallyn
c326c1967f
Merge pull request #2058 from brauner/2017-12-22/bugfixes
start: fix death signal
2017-12-22 16:10:14 -06:00
Christian Brauner
18225d1985
start: handle setting death signal smarter
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-22 22:52:42 +01:00
Christian Brauner
912314fc9b
start: fix death signal
On set{g,u}id() the kernel does:

 	/* dumpability changes */
	if (!uid_eq(old->euid, new->euid) ||
	    !gid_eq(old->egid, new->egid) ||
	    !uid_eq(old->fsuid, new->fsuid) ||
	    !gid_eq(old->fsgid, new->fsgid) ||
	    !cred_cap_issubset(old, new)) {
		if (task->mm)
			set_dumpable(task->mm, suid_dumpable);
		task->pdeath_signal = 0;
		smp_wmb();
	}

which means we need to re-enable the deat signal after the set{g,u}id().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-22 22:17:44 +01:00
Serge Hallyn
715584350e
Merge pull request #2057 from brauner/2017-12-22/bugfixes
start: simplify cgroup namespace preservation
2017-12-22 13:50:59 -06:00
Christian Brauner
8bf3abfbd0
start: simplify cgroup namespace preservation
Since we are now dumpable we can open /proc/<child-pid>/ns/cgroup so let's
avoid the overhead of sending around fds.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-22 17:23:46 +01:00
Christian Brauner
4b826b1fdc
start: make us dumpable
When set set{u,g}id() the kernel will make us undumpable. This is unnecessary
since we can guarantee that whatever is running inside the child process at
this point this is fully trusted by the parent. Making us dumpable let's users
use debuggers on the child process before the exec as well and also allows us
to open /proc/<child-pid> files in lieu of the child.
Note, that we only need to perform the prctl(PR_SET_DUMPABLE, ...) if our
effective uid on the host is not 0. If our effective uid on the host is 0 then
we will keep all capabilities in the child user namespace across set{g,u}id().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-22 17:23:45 +01:00
Serge Hallyn
150901398d
Merge pull request #2042 from brauner/2017-12-15/bugfixes
start: tweaks + bugfixes
2017-12-21 16:30:11 -06:00
Serge Hallyn
da5f5e3fbb
Merge pull request #2052 from brauner/2017-12-19/unprivileged_btrfs_regression
btrfs: fix unprivileged snapshot creation
2017-12-21 16:08:18 -06:00
Christian Brauner
c3184275ec
start: log closing cmd socket and STOPPED state
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-21 23:01:04 +01:00
Christian Brauner
ac2ba69621
start: use lxc_raw_clone_cb() where possible
This way we can rely on the kernel's copy-on-write support similar to fork().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-21 23:01:04 +01:00
Christian Brauner
0c2a98bdc8
namespace: add lxc_raw_clone_cb()
This is a copy-on-write (no stack passed) variant of lxc_clone().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-21 23:01:04 +01:00
Christian Brauner
718dbb8c2a
namespace: comment lxc_{raw_}clone()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-21 23:01:04 +01:00
Christian Brauner
0059379ff4
tree-wide: s/getpid()/lxc_raw_getpid()/g
This is to avoid bad surprises caused by older glibc's pid cache (up to 2.25)
when using clone().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-21 23:01:03 +01:00
Christian Brauner
bb196a1aa0
namespace: add lxc_raw_getpid()
Because of older glibc's pid cache (up to 2.25) whenever clone() is called the
child must must retrieve it's own pid via lxc_raw_getpid().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-21 23:00:22 +01:00
Christian Brauner
b01b36e9ad
tests: expand lxc_raw_clone() tests
- test CLONE_VFORK
- test CLONE_FILES

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-21 23:00:20 +01:00
Serge Hallyn
b5b200c627
Merge pull request #2047 from brauner/2017-12-18/attach_lsm_confinement
attach: simplify significantly
2017-12-21 15:56:51 -06:00
Christian Brauner
57de839fd5
attach: handle /proc with hidepid={1,2} property
Receive fd for LSM security module before we set{g,u}id(). The reason is that
on set{g,u}id() the kernel will a) make us undumpable and b) we will change our
effective uid. This means our effective uid will be different from the
effective uid of the process that created us which means that this processs no
longer has capabilities in our namespace including CAP_SYS_PTRACE. This means
we will not be able to read and /proc/<pid> files for the process anymore when
/proc is mounted with hidepid={1,2}. So let's get the lsm label fd before the
set{g,u}id().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-21 08:00:35 +01:00
Christian Brauner
a998454a2a
attach: use lxc_raw_clone()
This let's us simplify the whole file a lot and makes things way clearer. It
also let's us avoid the infamous pid cache.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-21 00:42:26 +01:00
Christian Brauner
94ac256fbb
attach: simplify significantly
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-12-20 22:17:56 +01:00
Christian Brauner
6c049d3a26
Merge pull request #2055 from marcosps/cgfsng_debug
cgfsng: Add new macro to print errors
2017-12-20 14:19:57 +01:00