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

Populate /etc/hosts file when run in a user namespace #7937

Merged
merged 1 commit into from
Oct 7, 2020

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Oct 6, 2020

We do not populate the hostname field with the IP Address
when running within a user namespace.

Fixes #7490

Signed-off-by: Daniel J Walsh dwalsh@redhat.com

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 6, 2020
b, err := ioutil.ReadFile(hostsBindMount)
if err != nil {
return err
}
Copy link
Member

Choose a reason for hiding this comment

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

if /etc/hosts doesn't exist, do we want to fail or just continue on?

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 this fails, this means that the system is going to fail later when it attempts to mount the file. So yes we want to fail

Copy link
Member

Choose a reason for hiding this comment

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

Should error - something has gone seriously wrong in container creation if BindMounts refers to a path that does not exist.

@@ -976,6 +976,19 @@ func (c *Container) completeNetworkSetup() error {
}
}
}
// check if we have a bindmount for /etc/hosts
hostsBindMount := state.BindMounts["/etc/hosts"]
Copy link
Member

Choose a reason for hiding this comment

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

Could do _, hastBindMount := state.BindMounts... to get a bool directly instead

Copy link
Member

Choose a reason for hiding this comment

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

Ah, you need the path, too... Hm. Could still get the bool to avoid the string compare below?

libpod/container_internal.go Outdated Show resolved Hide resolved
@@ -976,6 +976,18 @@ func (c *Container) completeNetworkSetup() error {
}
}
}
// check if we have a bindmount for /etc/hos1ts
Copy link
Member

Choose a reason for hiding this comment

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

typo in the comment: /etc/hos1ts

if err != nil {
return err
}
if err := ioutil.WriteFile(hostsBindMount, append(b, []byte(c.cniHosts())...), 0644); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

does it write to the source file if the user specifies the bind mount?

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 added a check to make sure the path is an internal to the container path.
If there is a volume mount by the user, or by a shared container network namespace, we will not add the name mapping.

Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

a fix for the test, otherwise LGTM

@@ -477,6 +477,17 @@ var _ = Describe("Podman run networking", func() {
Expect(session.ExitCode()).To(Equal(0))
})

FIt("podman run --uidmap /etc/hosts contains --hostname", func() {
Copy link
Member

Choose a reason for hiding this comment

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

FIt -> It

Copy link
Member Author

Choose a reason for hiding this comment

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

oops. Too early in the morning I guess.

We do not populate the hostname field with the IP Address
when running within a user namespace.

Fixes containers#7490

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Copy link
Member

@giuseppe giuseppe left a comment

Choose a reason for hiding this comment

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

LGTM

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: giuseppe, rhatdan

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

@TomSweeneyRedHat
Copy link
Member

LGTM
but the ubuntu-20 root host test is having issues with some of the networking tests, but I couldn't see what, I've rerun the test in hope that it's a flake.

@mheon
Copy link
Member

mheon commented Oct 7, 2020

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 7, 2020
@openshift-merge-robot openshift-merge-robot merged commit 173e3c2 into containers:master Oct 7, 2020
@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 24, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 24, 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.

hosts file not populated when using user namespace
6 participants