DNS resolution problem in snaps on Ubuntu 18.04 Server with systemd-resolved

Hi :wave: I’m not sure if this was brought up somewhere before, it seems like something that would be affecting a lot of people but I couldn’t find much about it.

A couple of folks noticed an issue with DNS resolution from within the NextCloud snap on Ubuntu 18.04 Server and there was an issue open about it here. It was noticed that this can be worked around by installing resolvconf package.

I wanted to see if I can avoid it and I did a bit of digging and found that this is because on the system I was on /etc/resolv.conf was a symlink pointing to /lib/systemd/resolv.conf and that file couldn’t be read from a confined snap. I.e.:

# snap run --shell nextcloud.occ
# cat /etc/resolv.conf
/etc/resolv.conf: No such file or directory

On the other hand if I changed the symlink to point to the file /run/systemd/resolve/stub-resolv.conf dynamically generated by systemd-resolved things worked OK. This is a good-enough solution for me, as in my case I prefer the dynamically generated stub because it respects the search domain, but I thought it’d be better to report it in case others run into this.

I’m not sure where is the best place to do that. As mentioned in the comment both configurations are perfectly valid but it could be that the default confinement policy should allow reading from (/usr)?/lib/systemd/resolv.conf but currently doesn’t? Not sure. Does anyone have ideas?

/cc @kyrofa

@jdstrand this could use your eyes. @ijohnson you might be interested as well.

Do you know what set this symlink? As you found out, /run/systemd/resolve/stub-resolv.conf is where we expect the systemd-resolved symlink to go to and I confirmed this in 18.04 desktop, server, lxd container and uc18 devices. A symlink to /lib/systemd/resolv.conf is problematic because the /lib in the snap won’t have this file (but /var/lib/snapd/hostfs/lib/systemd would).