Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avahi-daemon fails to start inside unpriviledged lxd container #2948

Closed
iteco opened this issue Feb 24, 2017 · 3 comments
Closed

avahi-daemon fails to start inside unpriviledged lxd container #2948

iteco opened this issue Feb 24, 2017 · 3 comments

Comments

@iteco
Copy link

iteco commented Feb 24, 2017

I used plain ubuntu 16.04 server to make lxd containers (lxc launch ubuntu:16.04 ) where I installed lxde. First container was working fine, but in second I got problems with avahi, "apt install lxde" ended to following errors. It can be also reproduced this way.

Errors were encountered while processing:
 avahi-daemon
 avahi-utils
 libnss-mdns:amd64
E: Sub-process /usr/bin/dpkg returned an error code (1)

Digging deeper revealed that
chroot.c: fork() failed: Resource temporarily unavailable
avahi-daemon: failed to start chroot() helper daemon.

As described also in
https://lists.linuxcontainers.org/pipermail/lxc-users/2016-January/010791.html
https://bugzilla.redhat.com/show_bug.cgi?id=1203731

I looked around and found similar issue
lxc/lxc#25
but it was closed four years ago as there was not enough information.. however, it looks to be still referenced and updated frequently. Will it be solved and closed (again) one day(?)

I also found
https://bugs.launchpad.net/maas/+bug/1661869 (comment#1)
but from there I understand the it should work on unprivileged containers (what I am using), so I am taking this up here.

Should it work ?
If not, why processes of one guest will limit process of other guest ?
(I have thought that unprivileged containers isolated from each others)

--
I looked also a work-a-round for this issue, and finding out bit more about rlimit-nproc value

avahi/avahi#97
says that nproc limit is for security and perhaps not so useful there either

https://blog.dbi-services.com/linux-how-to-monitor-the-nproc-limit-1/
recommends to set nproc value to 16K for oracle server

https://loune.net/2011/02/avahi-setrlimit-nproc-and-lxc/
and this says to remove the limit fully

I ended up setting nproc value (/etc/avahi/avahi-daemon.conf) in lxd guests from 3 to 30 and managed to get my avahi working.

I wrote my work-a-round here in case it would help somebody else, and also in the hope that somebody that would understand more about the issue could comment that is this a solid workaround.

--
Used environment on host
lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.2 LTS
Release: 16.04
Codename: xenial

lxc info
driver: lxc
driverversion: 2.0.7
kernel: Linux
kernelarchitecture: x86_64
kernelversion: 4.4.0-62-generic
server: lxd
serverversion: 2.0.9

@ardevd
Copy link

ardevd commented Feb 24, 2017

So all you did was set the nproc value to 30? I did just that but still cant start the avahi-daemon.

@stgraber
Copy link
Contributor

stgraber commented Feb 24, 2017

rlimits as used by systemd are tied to kernel uid/gid and aren't namespace aware, so they do cross container boundary and affect other containers, whether those containers are privileged or not.

One way around the problem is to tell avahi not to set the rlimit.

Another way around the problem is to have a different uid/gid allocation per container which with LXD is done by first increasing the id range in /etc/subuid and /etc/subgid, then restart the LXD daemon and lastly setting the security.idmap.isolated property to true.

Each container will then get their own 65536 non-overlapping uid and gid, effectively making rlimits tied to a given container.

@stgraber
Copy link
Contributor

The reason why people think that avahi will work in an unprivileged container is because unprivileged containers use a different id range from the host.

So out of the box, you can have avahi running on the host and in ONE unprivileged container. But if running more than one unprivileged container, you'll run into the problem unless you're using security.idmap.isolated.

drybjed referenced this issue in drybjed/debops Jan 28, 2019
Unprivileged LXC containers can share subUIDs/subGIDs on the LXC host.

The default configuration of the 'avahi-daemon' package on Debian
enables resource limits for Avahi that result in maximum 3 processes
allowed for the Avahi UNIX account. Because the specific UID/GID used
for Avahi user account can vary from container to container, and the
resource limits not being namespaced between LXC containers with the
same subUID/subGID range, multiple Avahi instances started at the same
time may fail.

This patch creates a systemd unit override which tells the avahi-daemon
process to not apply the resource limits which should avoid the issue in
test environments. This only applies to the virtual machines managed by
Vagrant.

Ref: https://github.com/lxc/lxd/issues/2948
Ref: https://loune.net/2011/02/avahi-setrlimit-nproc-and-lxc/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants