-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Conversation
libpod/container_internal.go
Outdated
b, err := ioutil.ReadFile(hostsBindMount) | ||
if err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
libpod/container_internal.go
Outdated
@@ -976,6 +976,19 @@ func (c *Container) completeNetworkSetup() error { | |||
} | |||
} | |||
} | |||
// check if we have a bindmount for /etc/hosts | |||
hostsBindMount := state.BindMounts["/etc/hosts"] |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
@@ -976,6 +976,18 @@ func (c *Container) completeNetworkSetup() error { | |||
} | |||
} | |||
} | |||
// check if we have a bindmount for /etc/hos1ts |
There was a problem hiding this comment.
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
libpod/container_internal.go
Outdated
if err != nil { | ||
return err | ||
} | ||
if err := ioutil.WriteFile(hostsBindMount, append(b, []byte(c.cniHosts())...), 0644); err != nil { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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
test/e2e/run_networking_test.go
Outdated
@@ -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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FIt -> It
There was a problem hiding this comment.
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
[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 |
LGTM |
/lgtm |
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 [email protected]