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

rootless netns: resolve all path components for resolv.conf #12524

Merged
merged 1 commit into from
Dec 7, 2021

Conversation

Luap99
Copy link
Member

@Luap99 Luap99 commented Dec 6, 2021

What this PR does / why we need it:

We need to follow all symlinks in the /etc/resolv.conf path. Currently
we would only check the last file but it is possible that any directory
before that is also a link.

Unfortunately this code is very hard to maintain and not well tested. I
will try to come up with a unit test when I have more time. I think we
could utilize some for of chroot for this. For now we are stucked with
the default setup in the fedora/ubunutu test VMs.

How to verify it

Which issue(s) this PR fixes:

Fixes #12461

Special notes for your reviewer:

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Dec 6, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: Luap99

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Dec 6, 2021
We need to follow all symlinks in the /etc/resolv.conf path. Currently
we would only check the last file but it is possible that any directory
before that is also a link.

Unfortunately this code is very hard to maintain and not well tested. I
will try to come up with a unit test when I have more time. I think we
could utilize some for of chroot for this. For now we are stucked with
the default setup in the fedora/ubunutu test VMs.

[NO NEW TESTS NEEDED]

Fixes containers#12461

Signed-off-by: Paul Holzinger <[email protected]>
// We also need to resolve all path components not just the last file.
// see https://github.com/containers/podman/issues/12461

if resolvePath[i] != '/' {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we strip any potential trailing / and then do a filepath.Dir()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be the wrong order. You have to resolve from left to right.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe split the string on / to get an array of path components, and then iterate through them, adding each to the path and checking for a symlink?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not see how this would be better than what I am doing now. This would just complicate things because I now have to constantly use strings.Split() and strings.Join().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair - I just see the existing code as not exactly clear in what it's trying to do.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I have more time after podman 4.0 I will spend some time to add a test for this and maybe rework this to make it more readable.

In theory we could drop this when we are full netavark without iptables backend. In this case we would not need to bind mount /run and /var/lib/cni because netavark does not need write access to those directories.

@rhatdan
Copy link
Member

rhatdan commented Dec 7, 2021

LGTM

Copy link
Member

@edsantiago edsantiago left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like the sort of code that would be nice to refactor into a helper function with lots and lots of unit tests... but I can see that this would be a lot of work. Nice work, although it's a little too hairy for me to LGTM.

libpod/networking_linux.go Show resolved Hide resolved
libpod/networking_linux.go Show resolved Hide resolved
@rhatdan
Copy link
Member

rhatdan commented Dec 7, 2021

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Dec 7, 2021
@openshift-merge-robot openshift-merge-robot merged commit 471defb into containers:main Dec 7, 2021
@Luap99 Luap99 deleted the resolve-symlink branch December 7, 2021 21:08
@edsantiago
Copy link
Member

Oh well. I was trying to figure out what would happen if /etc/resolv.conf -> ../run/something (symlink to ../run/ instead of absolute /run). Anyhow, too late, maybe something to add to the unit test suite when you get to it.

@Luap99
Copy link
Member Author

Luap99 commented Dec 7, 2021

@edsantiago That works already this is the default setup on fedora with systemd-resolved

@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error with symlinked /etc/resolv.conf
5 participants