Commit Graph

6355 Commits

Author SHA1 Message Date
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
Christian Brauner
e3db0162ff
utils: parse_byte_size_string()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 18:38:13 +02:00
Christian Brauner
b037bc675b
utils: add lxc_safe_long_long()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 18:38:13 +02:00
Christian Brauner
f3d05ee66d
ringbuf: implement simple and efficient ringbuffer
liblxc will use a ringbuffer implementation that employs mmap()ed memory.
Specifically, the ringbuffer will create an anonymous memory mapping twice the
requested size for the ringbuffer. Afterwards, an in-memory file the requested
size for the ringbuffer will be created. This in-memory file will then be
memory mapped twice into the previously established anonymous memory mapping
thereby effectively splitting the anoymous memory mapping in two halves of
equal size.  This will allow the ringbuffer to get rid of any complex boundary
and wrap-around calculation logic. Since the underlying physical memory is the
same in both halves of the memory mapping only a single memcpy() call for both
reads and writes from and to the ringbuffer is needed.

Design Notes:
- Since we're using MAP_FIXED memory mappings to map the same in-memory file
  twice into the anonymous memory mapping the kernel requires us to always
  operate on properly aligned pages. To guarantee proper page aligment the size
  of the ringbuffer must always be a muliple of the kernel's page size. This
  also implies that the minimum size of the ringbuffer must be at least equal to
  one page size. This additional requirement is reasonably unproblematic.
  First, any ringbuffer smaller than the size of a single page is very likely
  useless since the standard page size on linux is 4096 bytes.
- Because liblxc is not able to predict the output a user is going to produce
  (e.g. users could cat binary files onto the console) and because the
  ringbuffer is located in a hotpath and needs to be as performant as possible
  liblxc will not parse the buffer.

Use Case:
The ringbuffer is needed by liblxc in order to safely log the output of write
intensive callers that produce unpredictable output or unpredictable amounts of
output. The console output created by a booting system and the user is one of
those cases. Allowing a container to log the console's output to a file it
would be possible for a malicious user to fill up the host filesystem by
producing random ouput on the container's console if quota support is either
not enabled or not available for the underlying filesystem. Using a ringbuffer
is a reliable and secure way to ensure a fixed-size log.

Closes #1857.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 18:38:13 +02:00
Christian Brauner
e46361235c
utils: add lxc_getpagesize()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 18:38:13 +02:00
Christian Brauner
127c6e703b
utils: add lxc_make_tmpfile()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 18:38:12 +02:00
Christian Brauner
b499121f1f
utils: add lxc_cloexec()
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 16:30:08 +02:00
Christian Brauner
f749d524f1
utils: move memfd_create() definition
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-21 16:30:03 +02:00
Christian Brauner
c01db84ea9 Merge pull request #1866 from geaaru/fix-sabayon-unpriv-master
Fix start of Sabayon unprivileged containers
2017-10-20 11:31:42 +02:00
Geaaru
a254b67cf2 Fix start of Sabayon unprivileged containers
Problem happens for image with systemd >=233.
Minor fix for mirrors list.

Signed-off-by: Geaaru <geaaru@gmail.com>
2017-10-20 11:01:26 +02:00
Christian Brauner
ecc94d764f Merge pull request #1860 from kilobyte/master
fix build failures on x32
2017-10-19 00:25:16 +02:00
Christian Brauner
8c104d583c Merge pull request #1862 from fridtjof/patch-1
Change locale "en-US.UTF-8" to "en_US.UTF-8"
2017-10-17 17:04:46 +02:00
Fridtjof Mund
c86234b601 Change locale "en-US.UTF-8" to "en_US.UTF-8"
This template would always add "en-US.UTF-8" to the end of the container's locale.gen, which in turn confused locale-gen.

Signed-off-by: Fridtjof Mund <fridtjofmund@gmail.com>
2017-10-17 15:20:20 +02:00
Serge Hallyn
e485b36cef Merge pull request #1861 from brauner/2017-10-16/fix_log_stack_smash
log: bugfixes
2017-10-16 08:40:16 -05:00
Adam Borowski
714608316e Use the proper type for rlim_t, fixing build failure on x32.
Assuming a particular width of a type (or equivalence with "long") doesn't
work everywhere.  On new architectures, LFS/etc is enabled by default,
making rlim_t same as rlim64_t even if long is only 32-bit.

Not sure how you handle too big values -- you may want to re-check the
strtoull part.

Signed-off-by: Adam Borowski <kilobyte@angband.pl>
2017-10-16 15:12:07 +02:00
Adam Borowski
291f64ac27 Fix a format string build failure on x32.
Both of struct timespec fields are 64-bit on any new architecture, even
32-bit ones.

Signed-off-by: Adam Borowski <kilobyte@angband.pl>
2017-10-16 15:12:07 +02:00
Christian Brauner
a427e2686b
conf: error out on too many mappings
The kernel only allows 4k writes to most files in /proc including {g,u}id_map
so let's not try to write partial mappings. (This will obviously become a lot
more relevant when my patch to extend the idmap limit in the kernel is merged.)

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-16 13:13:14 +02:00
Christian Brauner
b0a507d7b4
log: prevent stack smashing
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-16 12:22:20 +02:00
Stéphane Graber
59262374da Merge pull request #1856 from brauner/2017-10-12/preserve_abi_compatibility
lxccontainer: preserve ABI compatibility
2017-10-12 11:23:56 -04:00
Christian Brauner
dcf33b9471
lxccontainer: preserve ABI compatibility
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-12 17:12:38 +02:00
Stéphane Graber
d289046a3e Merge pull request #1855 from brauner/2017-10-12/append_devel_to_version
arguments: print "-devel" when LXC_DEVEL is true
2017-10-12 09:14:09 -04:00
Christian Brauner
632297b3b6
arguments: print "-devel" when LXC_DEVEL is true
liblxc should inform users that they are using a devel version. This will have
liblxc print

    MAJOR.MINOR.PATCH-devel

if LXC_DEVEL is true and

    MAJOR.MINOR.PATCH

otherwise.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-12 10:06:46 +02:00
Serge Hallyn
70e1f27e0b Merge pull request #1851 from brauner/2017-10-10/setsid_for_mini_init
init: rework dumb init
2017-10-11 15:21:54 -05:00
Serge Hallyn
eb4ca13d26 Merge pull request #1852 from brauner/2017-10-11/container_live_patching
POC: container live patching
2017-10-11 15:20:25 -05:00
Christian Brauner
af54d8e68b
tests: test container live patching
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-11 21:43:48 +02:00
Christian Brauner
0d9cd9c37a
lxccontainer: implement container live patching
This adds set_running_config_item() which is the analogue of
get_running_config_item(). In essence it allows a caller to livepatch the
container's in-memory configuration. This POC is severly limited. Here are the
most obvious ones:
- Only the container's in-memory config can be updated but no further actions
  (e.g. on-disk actions) are made.
- Only keys in the "lxc.net." namespace can be changed. This POC also allows
  updating an existing network. For example it allows to change the network
  type of an existing network. This is obviously nonsense and in a non-POC
  implementation this should be blocked.

Use Case:
Callers can hotplug a new network for the container. For example, LXD can
create a pair of veth devices in the host and in the container and add it to
the container's in-memory config. This means, the container can later be
queried for the name of the device later on etc. Note that liblxc will
currently not delete hotplugged network devices on container shutdown since it
won't have the ifindex of the container.

Relates to https://github.com/lxc/lxd/issues/3920 .

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-11 14:02:46 +02:00
Christian Brauner
a6f151a7ce
init: rework dumb init
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-10 18:01:35 +02:00
Serge Hallyn
70cc675554 Merge pull request #1849 from brauner/2017-10-10/update_config
confile: make update warning opt-in
2017-10-10 09:28:53 -05:00
Christian Brauner
f6d9b7d50e
init: become session leader
Before exec()ing we need to become session leader otherwise some shells will
not be able to correctly initialize job control.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-10 15:53:11 +02:00
Christian Brauner
70952c01b8
confile: make update warning opt-in
With the release LXC 2.1 we started warning users who use LXC through the API
and users who use LXC through the tools equally about updating their config.
This quickly got confusing and annoying to API users who e.g. generate configs
on the fly (e.g. LXD). So instead of unconditionally warning users we make this
opt-in. If LXC detects that the env variable LXC_UPDATE_CONFIG_FORMAT is set
then it will warn the user if any legacy configuration keys are present. If it
is not set however, it will not warn the user. This is ok, since the log will
still log WARN()s for all legacy configuration keys.
The tools will all set LXC_UPDATE_CONFIG_FORMAT since it is very much required
that users update to the new configuration format pre-LXC 3.0.

Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
2017-10-10 14:35:40 +02:00