Skip to content

Wrong DNS when launched from existing network namespace #3564

@vmedea

Description

@vmedea

Linux distribution and version

PureOS 9 (based on Debian stretch).

Flatpak version

Flatpak 1.2.4

Description of the problem

When starting flatpak run from a Linux network namespace (ip netns exec <ns>…), the application sandbox will contain a /etc/resolv.conf that symlinks to the global DNS configuration instead of /etc/netns/<ns>/resolv.conf.

This causes DNS lookups to fail for the application!

Steps to reproduce

For example, start a VPN-tunneled network namespace with (openvpn-netns)[https://github.com/pekman/openvpn-netns] or similar, anything that sets up a completely different network configuration than the host will work—then start flatpak firefox in it:

#  ip netns add vpn
#  ip netns exec vpn ip addr add 127.0.0.1/8 dev lo
#  ip netns exec vpn ip link set lo up
# export NETNS=vpn
# openvpn-netns  --config <config> --daemon --log /tmp/vpn.log
# ip netns exec vpn sudo -i -u <user> flatpak run org.mozilla.firefox

The resulting firefox will run inside the namespace however the DNS will be wrong so it doesn't show any pages.

It's possible to work around this by entering the flatpak PID's filesystem namespace and correct the /etc/resolv.conf with nsenter:

#!/bin/bash
namespace=$1
conf="/etc/netns/${namespace}/resolv.conf"
newns=$(grep nameserver $conf)
echo "[${namespace}] ${newns}"
for pid in $(ip netns pids "${namespace}"); do
    nsenter -m -t "${pid}" bash -c \
        "if [ \"\$(readlink /etc/resolv.conf)\" == '/run/host/monitor/resolv.conf' ]; then
            echo '${pid}: rewriting resolv.conf';
            rm /etc/resolv.conf;
            echo '${newns}' > /etc/resolv.conf;
        fi"
done

But I think ideally it should just work. I know flatpak has a built-in option to run in a new network namespace without any networking, but this is not what I'm trying to do.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions