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

/etc/resolv.conf is broken when it's an absolute symbolic link on the host #187

Closed
refi64 opened this issue Jun 6, 2019 · 19 comments · Fixed by #460
Closed

/etc/resolv.conf is broken when it's an absolute symbolic link on the host #187

refi64 opened this issue Jun 6, 2019 · 19 comments · Fixed by #460
Assignees
Labels
1. Bug Something isn't working
Milestone

Comments

@refi64
Copy link

refi64 commented Jun 6, 2019

systemd-resolved has you symlink /etc/resolv.conf to some other location (under /run/systemd/resolve). When the host volume /etc is mounted, this location of course does not exist, so all hostname access within the container fails.

@debarshiray
Copy link
Member

debarshiray commented Jun 7, 2019

Yeah, that wouldn't work. We could bind mount /run too or switch to using the flatpak-spawn maintained copies.

What does ls -l /etc/resolv.conf show on the host? Could you please paste the output here?

@refi64
Copy link
Author

refi64 commented Jun 7, 2019

lrwxrwxrwx. 1 root root 32 Jun  6 13:23 /etc/resolv.conf -> /run/systemd/resolve/resolv.conf

like the resolved documentation mentions.

@debarshiray
Copy link
Member

So, Ubuntu uses systemd-resolved since 16.04.

@debarshiray
Copy link
Member

I think the best way forward is to switch the /etc/resolv.conf symbolic link to the copy maintained by flatpak-session-helper at /run/host/monitor/resolv.conf.

However, I'd like to wait a bit longer for flatpak/flatpak#2916 to be more widely installed, to avoid having some unintended fallout. Ultimately, Toolbox's primary use-case is Silverblue, and it doesn't use systemd-resolved, so it's better to lean in favour of it.

@debarshiray
Copy link
Member

I'd like to wait a bit longer for flatpak/flatpak#2916
to be more widely installed, to avoid having some unintended fallout.
Ultimately, Toolbox's primary use-case is Silverblue, and it doesn't use
systemd-resolved, so it's better to lean in favour of it.

flatpak/flatpak#2916 was introduced in Flatpak 1.4.0, which is too new for Fedora 29. So we need to wait until Fedora 29 is end-of-life:d before we make this change.

@debarshiray debarshiray changed the title resolv.conf is broken with systemd-resolved resolv.conf is broken when it's a symbolic link on the host Sep 24, 2019
@TingPing
Copy link

TingPing commented Nov 20, 2019

So we need to wait until Fedora 29 is end-of-life:d before we make this change.

Since this date is approaching is there any work on this? Its a bit of a problem to simply not work with many configurations...

EDIT: Seems like you can modify toolbox to use /run/host/monitor/resolv.conf instead of /run/host/etc/resolv.conf.

@fansari
Copy link

fansari commented Nov 20, 2019

Seems to work with /run/host/monitor/resolv.conf. I set the link stopped the box and started again. The link remained intact.

@sigmavirus24
Copy link

I can confirm @fansari's results with @TingPing's work around. I'm running Fedora 31 Workstation, toolbox-0.0.17-1.fc31.src.rpm, podman-1.6.2-2.fc31.src.rpm, and registry.fedoraproject.org/f31/fedora-toolbox 31 a198bc8c3cda 4 weeks ago 448 MB and having this issue. Let me know if I can provide any other details to help get this resolved (no pun intended).

@HarryMichal HarryMichal added the 1. Bug Something isn't working label Dec 5, 2019
@fansari
Copy link

fansari commented Feb 21, 2020

When will this issue been fixed? I have now again created directory /run/host/monitor (which does not exist on Fedora 31) removed the NetworkManager link and place the resolv.conf there.

toolbox should work with NetworkManager without this issue.

@abitrolly
Copy link

abitrolly commented Mar 17, 2020

Can't add custom DNS servers to /etc/resolv.conf from toolbox. I had to copy it, unlink and copy back.

@imcsk8
Copy link

imcsk8 commented Apr 1, 2020

The problem is that in Fedora 31 /etc/resolv.conf is a symlink to /run/host/etc/resolv.conf which in turn is a symlink to /var/run/NetworkManager/resolv.conf, this file does not exist in the container since it does not use NetworkManager.

The registry.fedoraproject.org/f31/fedora-toolbox:31 image has to be fixed to avoid this problem.

I found this Workaround:

⬢[ichavero@toolbox ~]$ sudo -i
sudo: setrlimit(RLIMIT_CORE): Operation not permitted
⬢[root@toolbox ~]# ping google.com
ping: google.com: Name or service not known
⬢[root@toolbox ~]# mkdir /var/run/NetworkManager
⬢[root@toolbox ~]# echo "nameserver 192.168.1.254" > /var/run/NetworkManager/resolv.conf
⬢[root@toolbox ~]# ping -c2 google.com
PING google.com (216.58.217.14) 56(84) bytes of data.
64 bytes from qro02s15-in-f14.1e100.net (216.58.217.14): icmp_seq=1 ttl=57 time=6.74 ms
64 bytes from qro02s15-in-f14.1e100.net (216.58.217.14): icmp_seq=2 ttl=57 time=5.63 ms

--- google.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 5.632/6.187/6.742/0.555 ms
⬢[root@toolbox ~]# 

@martinpitt
Copy link
Contributor

I sent a fix for that in PR #380 a while ago.

@liambeguin
Copy link

I tested #380 and it works great for me with systemd-resolved.

Thanks

@fansari
Copy link

fansari commented Apr 11, 2020

I have created a toolbox for Fedora 32 Silverblue and again ran into the same issue.
Only quick workaround was again to remove the link /etc/resolv.conf and set it to /run/host/monitor.resolv.conf.

@DanMan
Copy link

DanMan commented Apr 27, 2020

I'm running into this issue right now with Fedora 31 WS that has been upgraded since 24 I think. So it'd be nice, if someone could merge Martin's PR 380. The best software is worthless, if it only creates more problems.

HarryMichal added a commit to HarryMichal/toolbox that referenced this issue May 27, 2020
There has been a long standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. There are many ways how to go about it. Hardcode other paths,
where the file could be, completely rely on tools like
flatpak-session-helper that will track such files in a single directory,
or update the symlinking function to follow symlinks and update the
target path.

The first solution is the easiest short-term but not very good
long-term. Second solution is possibly the best long-term but there is a
problem with using flatpak-session-helper. It cannot be used as root.
That leaves the third option, follow symlinks and updating the target
path.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink and if it is, it's
target will be set as the new target. This is repeated if the new target
is also a symlink. Then the function tries first to find the file before
it creates the link.

Based on: containers#380

[0] containers#187
HarryMichal added a commit to HarryMichal/toolbox that referenced this issue May 27, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. There are many ways how to go about it. Hardcode other paths,
where the file could be, completely rely on tools like
flatpak-session-helper that will track such files in a single directory,
or update the symlinking function to follow symlinks and update the
target path.

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and updating the
target path.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink and if it is, it's
target will be set as the new target. This is repeated if the new target
is also a symlink. Then the function tries first to find the file before
it creates the link.

Based on: containers#380

[0] containers#187
@Jmennius
Copy link
Collaborator

Just making sure we stay on top of it :)
Fedora is aiming to enable systemd-resolved by default in Fedora 33 (link).

@HarryMichal HarryMichal added this to the Stable 1.0 milestone Jul 7, 2020
@martinpitt
Copy link
Contributor

This is tracked in https://bugzilla.redhat.com/show_bug.cgi?id=1785244 as well.

@HarryMichal HarryMichal self-assigned this Jul 22, 2020
HarryMichal added a commit to HarryMichal/toolbox that referenced this issue Jul 23, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. There are many ways how to go about it. Hardcode other paths,
where the file could be, completely rely on tools like
flatpak-session-helper that will track such files in a single directory,
or update the symlinking function to follow symlinks and update the
target path.

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and updating the
target path.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink and if it is, it's
target will be set as the new target. This is repeated if the new target
is also a symlink. Then the function tries first to find the file before
it creates the link.

Based on: containers#380

[0] containers#187
HarryMichal added a commit to HarryMichal/toolbox that referenced this issue Jul 28, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. There are many ways how to go about it. Hardcode other paths,
where the file could be, completely rely on tools like
flatpak-session-helper that will track such files in a single directory,
or update the symlinking function to follow symlinks and update the
target path.

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and updating the
target path.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink and if it is, it's
target will be set as the new target. This is repeated if the new target
is also a symlink. The function looks for the links in the chain under
/run/host where the host's filesystem is available.

Based on: containers#380

[0] containers#187
@HarryMichal HarryMichal added this to Needs triage in Priority Board Jul 28, 2020
HarryMichal added a commit to HarryMichal/toolbox that referenced this issue Aug 11, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. There are many ways how to go about it. Hardcode other paths,
where the file could be, completely rely on tools like
flatpak-session-helper that will track such files in a single directory,
or update the symlinking function to follow symlinks and update the
target path.

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and updating the
target path.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink and if it is, it's
target will be set as the new target. This is repeated if the new target
is also a symlink. The function looks for the links in the chain under
/run/host where the host's filesystem is available.

Based on: containers#380

[0] containers#187
HarryMichal added a commit to HarryMichal/toolbox that referenced this issue Aug 13, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. There are many ways how to go about it. Hardcode other paths,
where the file could be, completely rely on tools like
flatpak-session-helper that will track such files in a single directory,
or update the symlinking function to follow symlinks and update the
target path.

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and updating the
target path.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink and if it is, it's
target will be set as the new target. This is repeated if the new target
is also a symlink. The function looks for the links in the chain under
/run/host where the host's filesystem is available. Relative symlinks
are handled by this.

Based on: containers#380

[0] containers#187
HarryMichal added a commit to HarryMichal/toolbox that referenced this issue Aug 13, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. There are many ways how to go about it. Hardcode other paths,
where the file could be, completely rely on tools like
flatpak-session-helper that will track such files in a single directory,
or update the symlinking function to follow symlinks and update the
target path.

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and updating the
target path.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink and if it is, it's
target will be set as the new target. This is repeated if the new target
is also a symlink. The function looks for the links in the chain under
/run/host where the host's filesystem is available. Relative symlinks
are handled by this (thanks Tudor Roman!).

Based on: containers#380

[0] containers#187
@debarshiray
Copy link
Member

debarshiray commented Aug 18, 2020

The problem is that in Fedora 31 /etc/resolv.conf is a symlink to
/run/host/etc/resolv.conf which in turn is a symlink to
/var/run/NetworkManager/resolv.conf, this file does not exist in
the container since it does not use NetworkManager.

Umm... not quite.

I suppose, what you meant is that on Fedora 31 hosts, /etc/resolv.conf is a symbolic link to /run/NetworkManager/resolv.conf (because /var/run is a symbolic link to /run).

/etc/resolv.conf isn't meant to be a symbolic link on any Fedora hosts prior to Fedora 33. From Fedora 33 onwards, it's going to be managed by systemd-resolved and will indeed be a symbolic link. You can verify that by installing a Fedora < 33 system from scratch in a virtual machine or something.

However, due to an old (or passing?) NetworkManager bug, Fedora systems that have undergone a series of upgrades from one release to another for a good few years can end up with /etc/resolv.conf being a symbolic link as you mention.

@debarshiray
Copy link
Member

debarshiray commented Aug 18, 2020

An update about the impending systemd-resolved change in Fedora 33.

By default, Fedora will ship /etc/resolv.conf as a relative symbolic link to ../run/systemd/resolve/stub-resolv.conf, and so does Ubuntu. This already works since Toolbox 0.0.14 because of commit d63b0a9

This situation is an illustration of the benefits of a relative symbolic link. It ensures that the link continues to resolve properly even when the prefix or the root is changed.

So, if you need a quick solution that works with Toolbox as it's shipping today, I'd suggest switching to a relative symbolic link on your systems.

What doesn't work, and we need to fix, are absolute symbolic links. ie., a /etc/resolv.conf that links to /run/systemd/resolve/stub-resolv.conf.

@debarshiray debarshiray changed the title resolv.conf is broken when it's a symbolic link on the host /etc/resolv.conf is broken when it's an absolute symbolic link on the host Aug 18, 2020
HarryMichal added a commit to HarryMichal/toolbox that referenced this issue Aug 19, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. Hardcode other paths, where the file could be, completely rely
on tools like flatpak-session-helper that will track such files in a
single directory, or update the symlinking function to follow symlinks
and update the target path.

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and updating the
target path.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink and if it is, it's
target will be set as the new target. This is repeated if the new target
is also a symlink. The function looks for the links in the chain under
/run/host where the host's filesystem is available. Relative symlinks
are handled by this (thanks Tudor Roman!).

Based on: containers#380

[0] containers#187
HarryMichal added a commit to HarryMichal/toolbox that referenced this issue Aug 19, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. Hardcode other paths, where the file could be, completely rely
on tools like flatpak-session-helper that will track such files in a
single directory, or update the symlinking function to follow symlinks
and update the target path.

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and update the
target path if the target is an invalid symlink.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink. If it's not then
the symlinking is done right away. If it's a symlink then it is resolved.
When the target is valid, symlinking proceeds normally. If it it's not
then symlinking still proceeds but in two different ways depending on
target being an absolute or a relative symlink:

  - absolute - target is prepended with /run/host (the target may not be
    invalid)
  - relative - target is not changed (the target will be invalid)

This commit tries to rely on well-made relative symlinks. Those behave
correctly even when they are placed in a different prefix (in Toolbox's
case under /run/host).

Thanks Tudor Roman for raising concern about relative links.

Based on: containers#380

[0] containers#187
HarryMichal added a commit to HarryMichal/toolbox that referenced this issue Aug 19, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. Hardcode other paths, where the file could be, completely rely
on tools like flatpak-session-helper that will track such files in a
single directory, or update the symlinking function to follow symlinks
and update the target path.

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and update the
target path if the target is an invalid symlink.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink. If it's not then
the symlinking is done right away. If it's a symlink then it is resolved.
When the target is valid, symlinking proceeds normally. If it it's not
then symlinking still proceeds but in two different ways depending on
target being an absolute or a relative symlink:

  - absolute - target is prepended with /run/host (the target may not be
    invalid)
  - relative - target is not changed (the target will be invalid)

This commit tries to rely on well-made relative symlinks. Those behave
correctly even when they are placed in a different prefix (in Toolbox's
case under /run/host).

Thanks Tudor Roman for raising concern about relative links.

Based on: containers#380

[0] containers#187
HarryMichal added a commit to HarryMichal/toolbox that referenced this issue Aug 19, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. Hardcode other paths, where the file could be, completely rely
on tools like flatpak-session-helper that will track such files in a
single directory, or update the symlinking function to follow symlinks
and update the target path.

[0] containers#187

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and update the
target path if the target is an invalid symlink.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink. If it's not then
the symlinking is done right away. If it's a symlink then it is resolved.
When the target is valid, symlinking proceeds normally. If it it's not
then symlinking still proceeds but in two different ways depending on
target being an absolute or a relative symlink:

  - absolute - target is prepended with /run/host (the target may not be
    invalid)
  - relative - target is not changed (the target will be invalid)

This commit tries to rely on well-made relative symlinks. Those behave
correctly even when they are placed in a different prefix (in Toolbox's
case under /run/host).

Thanks Tudor Roman for raising concern about relative links.

Based on: containers#380

containers#460
debarshiray pushed a commit to HarryMichal/toolbox that referenced this issue Aug 27, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. Hardcode other paths, where the file could be, completely rely
on tools like flatpak-session-helper that will track such files in a
single directory, or update the symlinking function to follow symlinks
and update the target path.

[0] containers#187

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and update the
target path if the target is an invalid symlink.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink. If it's not then
the symlinking is done right away. If it's a symlink then it is resolved.
When the target is valid, symlinking proceeds normally. If it it's not
then symlinking still proceeds but in two different ways depending on
target being an absolute or a relative symlink:

  - absolute - target is prepended with /run/host (the target may not be
    invalid)
  - relative - target is not changed (the target will be invalid)

This commit tries to rely on well-made relative symlinks. Those behave
correctly even when they are placed in a different prefix (in Toolbox's
case under /run/host).

Thanks Tudor Roman for raising concern about relative links.

Based on: containers#380

containers#460
debarshiray pushed a commit to HarryMichal/toolbox that referenced this issue Aug 28, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. Hardcode other paths, where the file could be, completely rely
on tools like flatpak-session-helper that will track such files in a
single directory, or update the symlinking function to follow symlinks
and update the target path.

[0] containers#187

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and update the
target path if the target is an invalid symlink.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink. If it's not then
the symlinking is done right away. If it's a symlink then it is resolved.
When the target is valid, symlinking proceeds normally. If it it's not
then symlinking still proceeds but in two different ways depending on
target being an absolute or a relative symlink:

  - absolute - target is prepended with /run/host (the target may not be
    invalid)
  - relative - target is not changed (the target will be invalid)

This commit tries to rely on well-made relative symlinks. Those behave
correctly even when they are placed in a different prefix (in Toolbox's
case under /run/host).

Thanks Tudor Roman for raising concern about relative links.

Based on: containers#380

containers#460
debarshiray pushed a commit to HarryMichal/toolbox that referenced this issue Aug 28, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. Hardcode other paths, where the file could be, completely rely
on tools like flatpak-session-helper that will track such files in a
single directory, or update the symlinking function to follow symlinks
and update the target path.

[0] containers#187

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and update the
target path if the target is an invalid symlink.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink. If it's not then
the symlinking is done right away. If it's a symlink then it is resolved.
When the target is valid, symlinking proceeds normally. If it it's not
then symlinking still proceeds but in two different ways depending on
target being an absolute or a relative symlink:

  - absolute - target is prepended with /run/host (the target may not be
    invalid)
  - relative - target is not changed (the target will be invalid)

This commit tries to rely on well-made relative symlinks. Those behave
correctly even when they are placed in a different prefix (in Toolbox's
case under /run/host).

Thanks Tudor Roman for raising concern about relative links.

Based on: containers#380

containers#460
debarshiray pushed a commit to HarryMichal/toolbox that referenced this issue Aug 28, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. Hardcode other paths, where the file could be, completely rely
on tools like flatpak-session-helper that will track such files in a
single directory, or update the symlinking function to follow symlinks
and update the target path.

[0] containers#187

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and update the
target path if the target is an invalid symlink.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink. If it's not then
the symlinking is done right away. If it's a symlink then it is resolved.
When the target is valid, symlinking proceeds normally. If it it's not
then symlinking still proceeds but in two different ways depending on
target being an absolute or a relative symlink:

  - absolute - target is prepended with /run/host (the target may not be
    invalid)
  - relative - target is not changed (the target will be invalid)

This commit tries to rely on well-made relative symlinks. Those behave
correctly even when they are placed in a different prefix (in Toolbox's
case under /run/host).

Thanks Tudor Roman for raising concern about relative links.

Based on: containers#380

containers#460
debarshiray pushed a commit to HarryMichal/toolbox that referenced this issue Aug 28, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. Hardcode other paths, where the file could be, completely rely
on tools like flatpak-session-helper that will track such files in a
single directory, or update the symlinking function to follow symlinks
and update the target path.

[0] containers#187

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and update the
target path if the target is an invalid symlink.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink. If it's not then
the symlinking is done right away. If it's a symlink then it is resolved.
When the target is valid, symlinking proceeds normally. If it it's not
then symlinking still proceeds but in two different ways depending on
target being an absolute or a relative symlink:

  - absolute - target is prepended with /run/host (the target may not be
    invalid)
  - relative - target is not changed (the target will be invalid)

This commit tries to rely on well-made relative symlinks. Those behave
correctly even when they are placed in a different prefix (in Toolbox's
case under /run/host).

Thanks Tudor Roman for raising concern about relative links.

Based on: containers#380

containers#460
debarshiray pushed a commit to HarryMichal/toolbox that referenced this issue Aug 28, 2020
There has been a long-standing issue[0] when symlinking /etc/resolv.conf
to /run/host/etc/resolv.conf (host's resolv.conf). Many solutions were
proposed. Hardcode other paths, where the file could be, completely rely
on tools like flatpak-session-helper that will track such files in a
single directory, or update the symlinking function to follow symlinks
and update the target path.

[0] containers#187

The first solution is the easiest short-term but not very good
long-term. The second solution is possibly the best long-term but there
is a problem with using flatpak-session-helper. It cannot be used as
root. That leaves the third option, follow symlinks and update the
target path if the target is an invalid symlink.

This commit takes the third approach to solve the issue. Now the target
of the symlinking is first tested if it is a symlink. If it's not then
the symlinking is done right away. If it's a symlink then it is resolved.
When the target is valid, symlinking proceeds normally. If it it's not
then symlinking still proceeds but in two different ways depending on
target being an absolute or a relative symlink:

  - absolute - target is prepended with /run/host (the target may not be
    invalid)
  - relative - target is not changed (the target will be invalid)

This commit tries to rely on well-made relative symlinks. Those behave
correctly even when they are placed in a different prefix (in Toolbox's
case under /run/host).

Thanks Tudor Roman for raising concern about relative links.

Based on: containers#380

containers#460
debarshiray pushed a commit to HarryMichal/toolbox that referenced this issue Aug 28, 2020
Currently toolbox containers can get misconfigured if some
configuration files on the host are absolute symbolic links to some
other location.

For example, when systemd-resolved is used to manage /etc/resolv.conf
on the host, and if the file is an absolute link to
/run/systemd/resolve/stub-resolv.conf, then /etc/resolv.conf ends up
being invalid inside the container. This happens because the
container's /etc/resolv.conf points to /run/host/etc/resolv.conf, which
in turn points to /run/systemd/resolve/stub-resolv.conf, but that's
absent from the container.

This is, of course, not a problem with relative symbolic links. If the
host had a relative link to ../run/systemd/resolve/stub-resolv.conf,
then it would continue to work inside the container.

One solution would have been to use flatpak-session-helper to maintain
a copy of the host's /etc/resolv.conf in
$XDG_RUNTIME_DIR/.flatpak-helper/monitor. However, that doesn't work
when toolbox(1) is run as root.

The other option is to prepend the destination of the absolute symbolic
link with /run/host to make it resolve inside the container. It might
not work with funky links, but it's enough for the common case where a
an administrator changed the host's /etc/resolv.conf into a sane, but
absolute, symbolic link.

Properly configured hosts should anyway use relative symbolic links,
because they don't need to be adjusted in such scenarios. That's also
what Fedora and Ubuntu do, by default.

Thanks to Tudor Roman for raising a concern about relative symbolic
links.

Based on Martin Pitt's work on the POSIX shell implementation:
containers#380

containers#187
Priority Board automation moved this from Needs triage to Closed Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1. Bug Something isn't working
Projects
No open projects
Priority Board
  
Closed
Development

Successfully merging a pull request may close this issue.