Commit Graph

5727 Commits

Author SHA1 Message Date
Christian Brauner
dbc9832d21
commands: add lxc_cmd_state_server()
A LXC container's lifecycle is regulated by the states STARTING, RUNNING,
STOPPING, STOPPED, ABORTING. These states are tracked in the LXC handler and
can be checked via approriate functions in the command socket callback system.
(The freezer stages are not part of a container's lifecycle since they are not
recorded in the LXC handler. This might change in the future but given that the
freezer controller will be removed from future cgroup implementations it is
unlikely.) So far, LXC was using an external helper to track the states of a
container (lxc-monitord). This solution was error prone. For example, the
external state server would hang in various scenarios that seemed to be caused
by either very subtle internal races or irritation of the external state server
by signals.

LXC will switch from an external state monitor (lxc-monitord) which serves as a
state server for state clients to a native implementation using the indiviual
container's command socket. This solution was discussed and outlined by Stéphane
Graber and Christian Brauner during a LX{C,D} sprint.

The LXC handler will gain an additional field to track state clients. In order
for a state client to receive state notifications from the command server he
will need to register himself via the lxc_cmd_state_server() function in the
state client list. The state client list will be served by lxc_set_state()
during the container's lifecycle. lxc_set_state() will also take care of
removing any clients from the state list in the LXC handler once the requested
state has been reached and sent to the client.
In order to prevent races between adding and serving new state clients the state
client list and the state field in the LXC handler will be protected by a lock.

This commit effectively deprecates lxc-monitord. Instead of serving states to
state clients via the lxc-monitord fifo and socket we will now send the state
of the container via the container's command socket.
lxc-monitord is still useable and will - for the sake of the lxc-monitor
command - be kept around so that non-API state clients can still monitor the
container during it's lifecycle.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-13 06:13:20 +02:00
Stéphane Graber
46d9789cca Merge pull request #1621 from leitao/master
lxc-alpine: Add support for ppc64le
2017-06-12 23:24:34 -04:00
Christian Brauner
3f903c04fe
commands: add TRACE()ers
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-13 00:58:25 +02:00
Christian Brauner
85ff0e3ee2
lxccontainer: only spawn monitord on demand
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-13 00:58:25 +02:00
Christian Brauner
aa460476ad
start: add lxc_init_handler()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-13 00:58:21 +02:00
Christian Brauner
7835f056f9 Merge pull request #1615 from 0x0916/expose-lxc_log_init
API: expose function lxc_log_init
2017-06-13 00:51:41 +02:00
Breno Leitao
2933a5ce1c lxc-alpine: Add support for ppc64le
Starting at version 3.6, Alpine Linux has support for ppc64le
architecture. Adding the new keys also.

Signed-off-by: Breno Leitao <breno.leitao@gmail.com>
2017-06-12 13:54:07 -05:00
Stéphane Graber
ddfb7c7706 Merge pull request #1588 from brauner/2017-05-26/update_opensuse_template
lxc-opensuse: add Tumbleweed as supported release
2017-06-06 16:47:29 -06:00
Christian Brauner
ab373bdfbb Merge pull request #1578 from 0x0916/export-seccomp-filter-to-log
seccomp: export the seccomp filter after load it into kernel successful
2017-06-05 23:09:26 -06:00
0x0916
73b910a341 API: expose function lxc_log_init
Signed-off-by: 0x0916 <w@laoqinren.net>
2017-06-06 11:55:31 +08:00
0x0916
5107af320a seccomp: export the seccomp filter after load it into kernel successful
when the log level is TRACE, this patch export the seccomp
filter to log file.

the ouput of `seccomp_export_pfc()` is human readable and this feature
is useful for user to make sure their `seccomp configuration file` is
right.

Output for he default ubuntu container's seccomp filter is the
following:

```
      lxc-start ubuntu 20170520024159.412 INFO     lxc_apparmor - lsm/apparmor.c:apparmor_process_label_set:238 - changed apparmor profile to lxc-container-default-cgns
if ($arch == 3221225534)
  # filter for syscall "finit_module" (313) [priority: 65535]
  if ($syscall == 313)
    action ERRNO(1);
  # filter for syscall "open_by_handle_at" (304) [priority: 65535]
  if ($syscall == 304)
    action ERRNO(1);
  # filter for syscall "kexec_load" (246) [priority: 65535]
  if ($syscall == 246)
    action ERRNO(1);
  # filter for syscall "delete_module" (176) [priority: 65535]
  if ($syscall == 176)
    action ERRNO(1);
  # filter for syscall "init_module" (175) [priority: 65535]
  if ($syscall == 175)
    action ERRNO(1);
  # filter for syscall "umount2" (166) [priority: 65533]
  if ($syscall == 166)
    if ($a1.hi32 & 0x00000000 == 0)
      if ($a1.lo32 & 0x00000001 == 1)
        action ERRNO(13);
  # default action
  action ALLOW;
if ($arch == 1073741827)
  # filter for syscall "finit_module" (350) [priority: 65535]
  if ($syscall == 350)
    action ERRNO(1);
  # filter for syscall "open_by_handle_at" (342) [priority: 65535]
  if ($syscall == 342)
    action ERRNO(1);
  # filter for syscall "kexec_load" (283) [priority: 65535]
  if ($syscall == 283)
    action ERRNO(1);
  # filter for syscall "delete_module" (129) [priority: 65535]
  if ($syscall == 129)
    action ERRNO(1);
  # filter for syscall "init_module" (128) [priority: 65535]
  if ($syscall == 128)
    action ERRNO(1);
  # filter for syscall "umount2" (52) [priority: 65534]
  if ($syscall == 52)
    if ($a1 & 0x00000001 == 1)
      action ERRNO(13);
  # default action
  action ALLOW;
if ($arch == 3221225534)
  # filter for syscall "kexec_load" (1073742352) [priority: 65535]
  if ($syscall == 1073742352)
    action ERRNO(1);
  # filter for syscall "finit_module" (1073742137) [priority: 65535]
  if ($syscall == 1073742137)
    action ERRNO(1);
  # filter for syscall "open_by_handle_at" (1073742128) [priority: 65535]
  if ($syscall == 1073742128)
    action ERRNO(1);
  # filter for syscall "delete_module" (1073742000) [priority: 65535]
  if ($syscall == 1073742000)
    action ERRNO(1);
  # filter for syscall "init_module" (1073741999) [priority: 65535]
  if ($syscall == 1073741999)
    action ERRNO(1);
  # filter for syscall "umount2" (1073741990) [priority: 65534]
  if ($syscall == 1073741990)
    if ($a1 & 0x00000001 == 1)
      action ERRNO(13);
  # default action
  action ALLOW;
action KILL;
      lxc-start ubuntu 20170520024159.412 NOTICE   lxc_start - start.c:start:1470 - Exec'ing "/sbin/init".
```

Signed-off-by: 0x0916 <w@laoqinren.net>
2017-06-06 09:45:31 +08:00
Stéphane Graber
9795e880ae Merge pull request #1613 from brauner/2017-06-03/af_unix
abstract lxc_abstract_unix_{send,recv}_fd, bugfixes, and improvements
2017-06-05 19:52:46 -04:00
Christian Brauner
5b8819a714
lxc-opensuse: add Tumbleweed as supported release
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-06 01:40:08 +02:00
Stéphane Graber
3b01115569 Merge pull request #1611 from brauner/2017-06-02/enforce_config_item_method_implementation
tests: enforce all methods for config items being implemented
2017-06-05 19:30:00 -04:00
Christian Brauner
a394f952cd
conf: fix bionic builds
bionic seems to lack a definition of __S_ISTYPE().

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-05 23:44:22 +02:00
Christian Brauner
6e50e70437
conf: improve lxc_map_ids()
Closes https://github.com/lxc/lxd/issues/3384.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-05 23:44:11 +02:00
Christian Brauner
54117de569
conf: improve tty shifting function
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-05 19:17:11 +02:00
Christian Brauner
a5b18cb1b1
bdev: record output from mkfs.*
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-05 19:17:11 +02:00
Christian Brauner
493de765bb
bdev: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-05 19:17:11 +02:00
Christian Brauner
b9986e437b
doc: tweak lxc.container.conf a little
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-05 19:17:10 +02:00
Christian Brauner
7e009d5207
bdev: "detect" loop file
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-04 18:02:50 +02:00
Christian Brauner
9aa76a172c
conf: remove dead mount code
The removed codepath was non-functional for a long time now. All mounting is
handled through bdev.{c,h} and if that fails the other codepath would
necessarily fail as well. So let's remove them. This makes it way clearer what
is going on and simplifies things massively.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-04 13:25:23 +02:00
Christian Brauner
ae467c546b
af_unix: abstract lxc_abstract_unix_{send,recv}_fd
- Enable lxc_abstract_unix_{send,recv}_fd() to send and receive multiple fds at
  once.
- lxc_abstract_unix_{send,recv}_fd() -> lxc_abstract_unix_{send,recv}_fds()
- Send tty fds from child to parent all at once.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-04 08:08:41 +02:00
Stéphane Graber
beda39ebbd Merge pull request #1612 from brauner/2017-06-03/bugfixes
idmapping bugfixes
2017-06-03 19:13:11 -04:00
Christian Brauner
c9b7c33ed0
tree-wide: log function called in userns_exec_1()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-03 23:35:07 +02:00
Christian Brauner
1d90e06436
conf: avoid double-frees in userns_exec_1()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-03 22:05:27 +02:00
Christian Brauner
b0ee598357
conf: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-03 22:05:27 +02:00
Christian Brauner
f07fa8df6e
start: log sending and receiving of tty fds
This is a potentially security sensitive operation and I really want to keep an
eye on *when exactly* this is send. So add more logging on the TRACE() level.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-03 22:05:04 +02:00
Stéphane Graber
ff3381e14a Merge pull request #1609 from brauner/2017-06-01/unit_test_idmap_parser
unit test idmap parser + userns_exec_1() rework
2017-06-02 20:43:38 -04:00
Christian Brauner
6002524466 Merge pull request #1608 from ss1h2a3tw/checkconfig
add probe status checking
2017-06-02 17:21:16 -06:00
Christian Brauner
28a2d9e76d
conf: rework userns_exec_1()
This also fixes a bug where we caused a double mapping, when the {u,g}id for
the user was mapped to container root {g,u}id.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-03 00:41:59 +02:00
Christian Brauner
339efad99e
conf: non-functional changes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-03 00:41:57 +02:00
Christian Brauner
77803ee7a6
tests: add unit tests for idmap parser
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-03 00:41:56 +02:00
Christian Brauner
0b843d358a
confile_utils: add new file
This adds confile_utils.{c,h} which will contain a helpers to parse lxc
configuration files.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-03 00:41:54 +02:00
Shane Chen
59d7470770 add probe status checking
Signed-off-by: Shane Chen <ss1ha3tw@gmail.com>
2017-06-02 13:31:55 +08:00
Christian Brauner
c04f651ede
tests: enforce all methods for config items
This adds a test that checks LXC's configuration jump table whether all methods
for a given configuration item are implemented. If it is not, we'll error out.
This should provide additional safety since a) the API can now be sure that
dereferencing the pointer for a given method in the config struct is safe and
b) when users implement new configuration keys and forget to implement a
required method we'll see it right away.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-02 02:48:20 +02:00
Christian Brauner
a3c8e60080
confile: add dummy getter for lxc.include
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-02 02:42:19 +02:00
Serge Hallyn
a9849a0685 Merge pull request #1592 from brauner/2017-05-28/idmap_handling
idmap improvements
2017-06-01 17:29:55 -05:00
Serge Hallyn
ca3592eb15 Merge pull request #1599 from brauner/2017-05-30/use_minimal_idmap_set
conf: use minimal {g,u}id map
2017-06-01 17:12:58 -05:00
Christian Brauner
f8aa4bf308
conf: use minimal {g,u}id map
Afaict, userns_exec_1() is only used to operate based on privileges for the
user's own {g,u}id on the host and for the container root's unmapped {g,u}id.
This means we require only to establish a mapping from:
- the container root {g,u}id as seen from the host -> user's host {g,u}id
- the container root -> some sub{g,u}id

The former we add, if the user did not specifiy a mapping. The latter we
retrieve from the ontainer's configured {g,u}id mappings.

Closes #1598.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-01 23:54:47 +02:00
Serge Hallyn
493c623619 Merge pull request #1596 from brauner/2017-05-29/fix_parsing
confile: fix parsing
2017-06-01 16:17:11 -05:00
Christian Brauner
1573a51475 Merge pull request #1607 from ss1h2a3tw/master
adding warning for mtu ignoring
2017-06-01 20:25:09 +10:00
Shane Chen
72ccbbe1aa adding warning for mtu ignoring
Signed-off-by: Shane Chen <ss1ha3tw@gmail.com>
2017-06-01 14:22:39 +08:00
Christian Brauner
ae4ad10d18
tests: comp retval to exp val whenever we can
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-01 04:10:00 +02:00
Christian Brauner
a182feaebd
confile: performance tweaks
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-01 04:09:43 +02:00
Christian Brauner
03931c9e18 Merge pull request #1605 from decomposite/systemd_unit_stop
Use lxc-stop to stop systemd service
2017-06-01 08:40:40 +10:00
JD Friedrikson
c08d29b6d1
Use lxc-stop to stop systemd service
Ever since 8eb62c2, systemd has not been able to cleanly stop lxc
containers (via lxc@) because it's still using SIGPWR for systemd-based
containers.

We should now use the nice logic in 330ae3d to stop the containers
instead.

Signed-off-by: JD Friedrikson <yours@decompo.site>
2017-05-31 18:04:37 -04:00
Stéphane Graber
bf3e9c154e Merge pull request #1601 from brauner/2017-05-30/veth_fixes
network: don't delete net devs we didn't create
2017-05-31 13:17:36 -04:00
Christian Brauner
6afd673f2e
lxccontainer: switch api to new clearer callbacks
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-05-31 18:59:29 +02:00
Christian Brauner
973082f566
confile: add clearer for lxc.include
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-05-31 18:45:51 +02:00