Commit Graph

6084 Commits

Author SHA1 Message Date
Christian Brauner
e2695f0e02
cgroups/cgfsng: remove is_lxcfs()
We don't need to parse fuse.lxcfs entries.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-07 00:54:28 +01:00
Christian Brauner
c2712f64d5
cgroupfs/cgfsng: tweak logging
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-07 00:54:28 +01:00
Christian Brauner
be5c06ece4
log: check for i/o error with vsnprintf()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-07 00:54:27 +01:00
Christian Brauner
a760603e3b
cgroups/cgfsng: support MS_READONLY with cgroup ns
If we lack CAP_SYS_ADMIN this is really useful.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-07 00:54:27 +01:00
Christian Brauner
058c1cb631
cgroups/cgfsng: cgfsns_chown() -> cgfsng_chown()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-07 00:54:27 +01:00
Christian Brauner
ae5e6c0856
cgroups/cgfsng: make sure pointer is NULL
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-07 00:54:27 +01:00
Christian Brauner
411ac6d854
cgroups/cgfsng: keep mountpoint intact
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-07 00:54:27 +01:00
Christian Brauner
877f3a0452
attach: handle namespace inheritance
We need to have lxc_attach() distinguish between a caller specifying specific
namespaces to attach to and a caller not requesting specific namespaces. The
latter is taken by lxc_attach() to mean that all namespaces will be attached.
This also needs to include all inherited namespaces.

Closes #1890.
Closes #1897.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-07 00:54:04 +01:00
Christian Brauner
13bc611359
tools: fix help output of lxc-create
Closes #1899.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-07 00:53:34 +01:00
Christian Brauner
eef2ab4475
storage: switch to ext4 as default filesystem
Closes #1899.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-07 00:53:31 +01:00
Stéphane Graber
da3dcce69a
Merge pull request #1906 from brauner/2017-11-06/cgns_check_before_preserve
start: only preserve CLONE_NEWCGROUP when supported
2017-11-06 17:45:07 -05:00
Christian Brauner
baed7c1b58
start: only preserve CLONE_NEWCGROUP when supported
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-06 23:24:01 +01:00
Christian Brauner
eb42a0de98
Merge pull request #1901 from jacmet/fix-no-new-privs-check
lxc/start.c: Fix legacy PR_{G,S}ET_NO_NEW_PRIVS handling
2017-11-06 12:15:40 +01:00
Peter Korsgaard
995accccbb lxc/start.c: Fix legacy PR_{G,S}ET_NO_NEW_PRIVS handling
The configure checks for these use AC_CHECK_DECLS, which define the symbol
to 0 if not available - So adjust the code to match.  From the autoconf
manual:

https://www.gnu.org/software/autoconf/manual/autoconf-2.65/html_node/Generic-Declarations.html)

For each of the symbols (comma-separated list), define HAVE_DECL_symbol (in
all capitals) to ‘1’ if symbol is declared, otherwise to ‘0’.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
2017-11-06 09:35:48 +01:00
Serge Hallyn
2ed797da7e
Merge pull request #1884 from brauner/2017-10-28/move_tools_to_api_only
confile: add lxc.namespace.<namespace-key> + add user namespace sharing + rework start logic
2017-11-04 22:27:45 -05:00
Christian Brauner
686dd5d114
conf: reap child in all cases
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-03 08:37:10 +01:00
Christian Brauner
6b9f82a9f5
network: reap child in all cases
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-03 08:37:09 +01:00
Christian Brauner
fa3a5b2205
start: rework ns sharing + add userns sharing
- Implement inheriting user namespaces.
  - When inheriting user namespaces make sure to not try and map ids again. The
    kernel will not allow you to do this.
- Change clone() logic:
  1. If we inherit no namespaces simply call lxc_clone().
  2. If we inherit any namespaces call lxc_fork_attach_clone(). Here's why:
     - Causes one syscall (fork()) instead of two syscalls (setns() to
       inherited namespace and setns() back to parent namespace) to be
       performed.
     - Allows us to get rid of a bunch of variables and helper functions/code.
     - Sharing a user namespaces requires us to setns() to the inherited user
       namespace but the kernel does not allow reattaching to a parent user
       namespace. So the old logic made user namespace inheritance impossible.
       By using the lxc_fork_attach_clone() model we can simply setns() to the
       inherited user namespace in the fork()ed child and be done with it.
       The only thing we need to do is to specify CLONE_PARENT when calling
       clone() in lxc_fork_attach_clone() so that we can wait on the child.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-03 08:37:09 +01:00
Christian Brauner
2469f9b65e
monitor: do not log useless warnings
lxc-monitord is deprecated so this is expected to fail.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-03 08:37:09 +01:00
Christian Brauner
a9e1109e07
start: close data socket in parent
Brings the number of open fds in the monitor process for a standard container
without ttys down to 17.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-03 08:37:09 +01:00
Christian Brauner
28d9e29e18
confile: add lxc.namespace.<namespace-key>
This commit also gets rid of ~10 unnecessarily file descriptors that were kept
open. Before we kept open:

- A set of file descriptors that refer to the monitor's namespaces. These were
  only used to reattach to the monitor's namespace in lxc_spawn() and were
  never used anywhere else. So close them and don't keep them around.
- A list of inherited file descriptors.
- A list of file descriptors referring to the containers's namespaces to pass
  to lxc.hook.stop. This list duplicated inherited file descriptors.

Let's simply use a single list in the handler that has all file descriptors we
need and get rid of all other ones. As an illustration. Starting a container

1. Without this patch and looking at the fds that the monitor keeps open (26):

chb@conventiont|~
> ls -al /proc/27219/fd
total 0
dr-x------ 2 root root  0 Oct 29 14:30 .
dr-xr-xr-x 9 root root  0 Oct 29 14:30 ..
lrwx------ 1 root root 64 Oct 29 14:30 0 -> /dev/null
lrwx------ 1 root root 64 Oct 29 14:30 1 -> /dev/null
lrwx------ 1 root root 64 Oct 29 14:30 10 -> anon_inode:[signalfd]
lrwx------ 1 root root 64 Oct 29 14:30 11 -> /dev/ptmx
lrwx------ 1 root root 64 Oct 29 14:30 12 -> /dev/pts/10
lr-x------ 1 root root 64 Oct 29 14:30 13 -> net:[4026532553]
lrwx------ 1 root root 64 Oct 29 14:30 15 -> socket:[7909181]
lrwx------ 1 root root 64 Oct 29 14:30 16 -> socket:[7909182]
lr-x------ 1 root root 64 Oct 29 14:30 17 -> uts:[4026531838]
lr-x------ 1 root root 64 Oct 29 14:30 18 -> ipc:[4026531839]
lr-x------ 1 root root 64 Oct 29 14:30 19 -> net:[4026532009]
lrwx------ 1 root root 64 Oct 29 14:30 2 -> /dev/null
lr-x------ 1 root root 64 Oct 29 14:30 20 -> mnt:[4026532611]
lr-x------ 1 root root 64 Oct 29 14:30 21 -> pid:[4026532612]
lr-x------ 1 root root 64 Oct 29 14:30 22 -> uts:[4026532548]
lr-x------ 1 root root 64 Oct 29 14:30 23 -> ipc:[4026532549]
lr-x------ 1 root root 64 Oct 29 14:30 24 -> net:[4026532553]
l-wx------ 1 root root 64 Oct 29 14:30 3 -> /var/log/lxc/a1.log
lr-x------ 1 root root 64 Oct 29 14:30 4 -> uts:[4026532548]
lr-x------ 1 root root 64 Oct 29 14:30 5 -> ipc:[4026532549]
lr-x------ 1 root root 64 Oct 29 14:30 6 -> net:[4026532553]
lrwx------ 1 root root 64 Oct 29 14:30 7 -> anon_inode:[eventpoll]
lrwx------ 1 root root 64 Oct 29 14:30 9 -> socket:[7911594]

2. With this patch and looking at the fds that the monitor keeps open (19):

chb@conventiont|~
> ls -al /proc/28465/fd
total 0
dr-x------ 2 root root  0 Oct 29 14:31 .
dr-xr-xr-x 9 root root  0 Oct 29 14:31 ..
lrwx------ 1 root root 64 Oct 29 14:31 0 -> /dev/null
lrwx------ 1 root root 64 Oct 29 14:31 1 -> /dev/null
lr-x------ 1 root root 64 Oct 29 14:31 10 -> net:[4026532820]
lrwx------ 1 root root 64 Oct 29 14:31 12 -> socket:[7912349]
lrwx------ 1 root root 64 Oct 29 14:31 13 -> socket:[7912350]
lr-x------ 1 root root 64 Oct 29 14:31 14 -> mnt:[4026532611]
lr-x------ 1 root root 64 Oct 29 14:31 15 -> pid:[4026532813]
lr-x------ 1 root root 64 Oct 29 14:31 16 -> uts:[4026532612]
lr-x------ 1 root root 64 Oct 29 14:31 17 -> ipc:[4026532613]
lr-x------ 1 root root 64 Oct 29 14:31 18 -> net:[4026532820]
lrwx------ 1 root root 64 Oct 29 14:31 2 -> /dev/null
l-wx------ 1 root root 64 Oct 29 14:31 3 -> /var/log/lxc/a1.log
lrwx------ 1 root root 64 Oct 29 14:31 4 -> anon_inode:[signalfd]
lrwx------ 1 root root 64 Oct 29 14:31 5 -> /dev/ptmx
lrwx------ 1 root root 64 Oct 29 14:31 6 -> /dev/pts/10
lrwx------ 1 root root 64 Oct 29 14:31 7 -> anon_inode:[eventpoll]
lrwx------ 1 root root 64 Oct 29 14:31 9 -> socket:[7913041]

Relates to #1881.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-03 08:37:09 +01:00
Christian Brauner
f0ecc19d8f
handler: make name argument const
There's no obvious need to strdup() the name of the container in the handler.
We can simply make this a pointer to the memory allocated in
lxc_container_new().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-03 08:37:08 +01:00
Christian Brauner
6e5fc7a5c7
start: close non-needed file descriptors
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-03 08:37:08 +01:00
Christian Brauner
4e4832eeb3
lxc-start: remove unnecessary checks
The console struct is internal and liblxc takes care of creating paths.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-11-03 08:37:08 +01:00
Christian Brauner
190f9aeedc
Merge pull request #1896 from ffontaine/master
Fix compilation on toolchain without prlimit
2017-11-02 23:40:58 +03:00
Fabrice Fontaine
f48b5fd8ab Fix compilation on toolchain without prlimit
Some toolchains which are not bionic like uclibc does not support
prlimit or prlimit64. In this case, return an error.
Moreover, if prlimit64 is available, use lxc implementation of prlimit.

Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com>
2017-11-02 18:36:00 +01:00
Serge Hallyn
2ba9ef6c89
Merge pull request #1883 from brauner/2017-10-29/fix_namespace_inheritance_on_attach
attach: correctly handle namespace inheritance
2017-10-30 13:14:40 -05:00
Stéphane Graber
82df9e1e3a
Merge pull request #1875 from brauner/2017-10-27/tools_allow_undefined_containers
tools: allow lxc-attach to undefined containers
2017-10-30 18:22:47 +01:00
Serge Hallyn
af949cc193
Merge pull request #1888 from brauner/2017-10-30/enable_cgfsng_cgroup_mounting
cgroups: enable container without CAP_SYS_ADMIN
2017-10-30 10:30:13 -05:00
Christian Brauner
b635e92d21
cgroups: enable container without CAP_SYS_ADMIN
In case cgroup namespaces are supported but we do not have CAP_SYS_ADMIN we
need to mount cgroups for the container. This patch enables both privileged and
unprivileged containers without CAP_SYS_ADMIN.

Closes #1737.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-30 14:32:40 +01:00
Christian Brauner
cdfe90a49f
cgfsng: fix cgroup2 detection
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-30 14:32:30 +01:00
Christian Brauner
299d119818
attach: correctly handle namespace inheritance
When attaching to a container's namespaces we did not handle the case where we
inherited namespaces correctly. In essence, liblxc on start records the
namespaces the container was created with in the handler. But it only records
the clone flags that were passed to clone() and doesn't record the namespaces
we e.g. inherited from other containers. This means that attach only ever
attached to the clone flags. But this is only correct if all other namespaces
not recorded in the handler refer to the namespaces of the caller. However,
this need not be the case if the container has inherited namespaces from
another container. To handle this case we need to check whether caller and
container are in the same namespace. If they are, we know that things are all
good. If they aren't then we need to attach to these namespaces as well.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-29 12:27:52 +01:00
Christian Brauner
cf13d10781
Merge pull request #1880 from terceiro/lxc-debian
lxc-debian improvements
2017-10-28 15:05:05 +02:00
Antonio Terceiro
dba285d5df lxc-debian: don't hardcode valid releases
This avoids the dance of updating the list of valid releases every time
Debian makes a new release.

It also fixes the following bug: even though lxc-debian will default to
creating containers of the latest stable by querying the archive, it
won't allow you to explicitly request `stable` because the current list
of valid releases don't include it.

Last, but not least, avoid hitting the mirror in the case the desired
release is one of the ones we know will always be there, i.e. stable,
testing, sid, and unstable.

Signed-off-by: Antonio Terceiro <terceiro@debian.org>
2017-10-28 10:32:12 -02:00
Antonio Terceiro
c99055ea6d lxc-debian: don't write C.* locales to /etc/locale.gen
Doing that confuses locale generation. lxc-ubuntu does the same check

Signed-off-by: Antonio Terceiro <terceiro@debian.org>
2017-10-28 10:11:54 -02:00
Christian Brauner
b25c853b2e
Merge pull request #1879 from jordemort/lxc-execute-config-define-load
Call lxc_config_define_load from lxc_execute again
2017-10-28 01:18:45 +02:00
Stéphane Graber
b4819bd8d7
Merge pull request #1874 from adrian5/patch-1
Fix typo in lxc-net script
2017-10-27 15:28:24 -04:00
Jordan Webb
baebdaf95a
Add missing lxc_container_put
Signed-off-by: Jordan Webb <jordemort@github.com>
2017-10-27 13:31:10 -05:00
adrian5
09a4c38063 Fix typo in lxc-net script
Signed-off-by: adrian5 <adrian5@users.noreply.github.com>
2017-10-27 20:29:50 +02:00
Jordan Webb
47d556f517
Call lxc_config_define_load from lxc_execute again
Signed-off-by: Jordan Webb <jordemort@github.com>
2017-10-27 13:13:10 -05:00
Christian Brauner
5e5129d751
tools: allow lxc-attach to undefined containers
For example the following sequence is expected to work:

lxc-start -n containerName -f /path/to/conf \
-s 'lxc.id_map = u 0 100000 65536' \
-s 'lxc.id_map = g 0 100000 65536' \
-s 'lxc.rootfs = /path/to/rootfs' \
-s 'lxc.init_cmd = /path/to/initcmd'

lxc-attach -n containerName

Closes #984.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-27 13:41:28 +02:00
Christian Brauner
546d446951 Merge pull request #1873 from terceiro/debian-rolling
lxc-debian: allow creating `testing` and `unstable`
2017-10-27 06:02:16 +02:00
Antonio Terceiro
61fa13293d lxc-debian: allow creating testing and unstable
Being able to create `testing` containers, regardless of what's the name
of the next stable, is useful in several contexts, included but not
limited to testing purposes. i.e. one won't need to explicitly switch to
`bullseye` once `buster` is released to be able to continue tracking
`testing`. While we are at it, let's also enable `unstable`, which is
exactly the same as `sid`, but there is no reason for not being able to.

Signed-off-by: Antonio Terceiro <terceiro@debian.org>
2017-10-26 20:48:43 -02:00
Serge Hallyn
f3d91bf09a Merge pull request #1864 from brauner/2017-10-18/ringbuffer
ringbuffer: implement efficient and performant ringbuffer
2017-10-21 13:03:46 -04:00
Christian Brauner
a2028b8f5f
namespace: use lxc_getpagesize()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 18:38:14 +02:00
Christian Brauner
732375f5f5
console: add ringbuffer
Closes #1857.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 18:38:14 +02:00
Christian Brauner
7f135597a2
conf: lxc_setup() -> lxc_setup_child()
Closes #1857.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 18:38:14 +02:00
Christian Brauner
a04220de0b
confile: add lxc.console.logsize
Closes #1857.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 18:38:14 +02:00
Christian Brauner
2ea479c9a6
confile_utils: add lxc_get_conf_uint64()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 18:38:14 +02:00
Christian Brauner
6222c3f48b
utils: add lxc_find_next_power2()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 18:38:13 +02:00