Commit Graph

5245 Commits

Author SHA1 Message Date
Christian Brauner
cccd2219a4
network: give getters a void pointer arg
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:55:32 +02:00
Christian Brauner
519df1c1ac
network: clear whole networks
When users specify

lxc.network.<n>

we remove the whole network from the networks list.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:55:32 +02:00
Christian Brauner
ff6da29581
network: implement network clearing
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:55:30 +02:00
Christian Brauner
40db5d2f96
network: abstract network handling
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:54:09 +02:00
Christian Brauner
2647140368
network: add arg to config clear method
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:54:03 +02:00
Christian Brauner
1ed6ba91b5
network: add lxc_log_configured_netdevs()
This logs the configured networks on the trace level to support debugging.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:53:59 +02:00
Christian Brauner
bbc079cf87
network: use new network configuration parser
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:53:54 +02:00
Christian Brauner
56637458ca
network: perform network validation at creation time
Some of the checks were previously performed when parsing the network config.
But since we allow for a little more flexibility now it doesn't work anymore.
Instead, let's validate the network at creation time.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:53:50 +02:00
Christian Brauner
ce2f5ae83f
network: implement lxc_get_netdev_by_idx()
lxc_get_netdev_by_idx() takes care of checking whether a given netdev struct
for a given index is already allocated. If so it returns a pointer to it to the
caller.
If it doesn't find it it will allocate a new netdev struct and insert it into
the network list at the right position. For example, let's say you have the
following networks defined in your config file:

lxc.network.0.type=veth
lxc.network.0.link=lxcbr0
lxc.network.0.name=eth0
lxc.network.0.flags=up

lxc.network.3.type=veth
lxc.network.3.link=lxcbr0
lxc.network.3.name=eth1
lxc.network.3.flags=up
lxc.network.3.hwaddr = 00:16:3e:5d:7d:65

lxc.network.1.type=veth
lxc.network.1.link=lxcbr0
lxc.network.1.name=eth0
lxc.network.1.flags=up

lxc_get_netdev_by_idx() will take care that the internal network list appears
in the order:

0
1
3

The ordering of the keys themselves can also be random, meaning you could do:

lxc.network.3.type=veth
lxc.network.0.link=lxcbr0
lxc.network.0.name=eth0
lxc.network.3.hwaddr = 00:16:3e:5d:7d:65
lxc.network.0.flags=up
lxc.network.3.flags=up
lxc.network.0.type=veth
lxc.network.3.link=lxcbr0
lxc.network.3.name=eth1

and lxc_get_netdev_by_idx() would still figure out the correct ordering since
it keeps track of the index.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:53:45 +02:00
Christian Brauner
5c35a8f1d9
network: add network counter
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:53:34 +02:00
Christian Brauner
c7e27aaf3b
network: add data arg to set callback
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:53:28 +02:00
Christian Brauner
663e99165e
network: mv config_value_empty() to confile_utils
and rename it to lxc_config_value_empty()

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-18 11:53:20 +02:00
Serge Hallyn
192f5e7b25 Merge pull request #1627 from brauner/2017-06-15/fix_new_logging_api
tree-wide: priority -> level
2017-06-15 23:50:36 -05:00
Christian Brauner
4b73005c60
tree-wide: priority -> level
When we merged the new logging function for the api we exposed the log level
argument in the struct as "priority" which we actually requested to be changed
to "level" which somehow didn't happen and we missed it. Given the fact there
has been no new liblxc release let's fix it right now before it hits users.
Also, take the chance to change the terminology in the log from "priority" to
"level" globally. This is to prevent confusion with syslog's "priority"
argument which we also support.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-15 12:13:04 +02:00
Serge Hallyn
74f0414131 Merge pull request #1618 from brauner/2017-06-06/kill_lxc_monitord
start: kill lxc-monitord
2017-06-13 00:34:47 -05:00
Christian Brauner
d0ab6d91c9
tests: don't fail when no processes for user exist
Since we kicked lxc-monitord there will very likely be no user processes around
anymore after all container's have been stopped. Which is a very very very good
thing. So let's not error out when pkill doesn't find any processes.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-13 06:13:20 +02:00
Christian Brauner
bbdbf8f078
conf: fix wrong path on overlayfs
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-13 06:13:20 +02:00
Christian Brauner
c47eafecc6
lxccontainer: cleanup + bugfixes
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-13 06:13:20 +02:00
Christian Brauner
f2e07cb6a4
{start,lxccontainer}: add lxc_free_handler()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-06-13 06:13:20 +02:00
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