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

hosts file not populated when using user namespace #7490

Closed
st1971 opened this issue Aug 28, 2020 · 4 comments · Fixed by #7937
Closed

hosts file not populated when using user namespace #7490

st1971 opened this issue Aug 28, 2020 · 4 comments · Fixed by #7937
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. stale-issue

Comments

@st1971
Copy link
Contributor

st1971 commented Aug 28, 2020

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description
when running a rooted container with either --uidmap or --subuidname /etc/hosts does not have an entry for the container.

Steps to reproduce the issue:

  1. sudo podman run --rm -it --uidmap=0:100000:5000 --hostname=mycontainer fedora:32 /bin/bash -c "cat /etc/hosts"

Describe the results you received:
Output of the content of /etc/hosts without an entry for mycontainer

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

Describe the results you expected:
Output of the content of /etc/hosts with an entry for mycontainer, as you get without the --uidmap or --subuidname flag

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.88.0.164	my-container

Additional information you deem important (e.g. issue happens only occasionally):

Output of podman version:

Version:      2.0.5
API Version:  1
Go Version:   go1.14.6
Built:        Thu Jan  1 01:00:00 1970
OS/Arch:      linux/amd64

Output of podman info --debug:

host:
  arch: amd64
  buildahVersion: 1.15.1
  cgroupVersion: v2
  conmon:
    package: conmon-2.0.19-1.fc32.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.19, commit: 5dce9767526ed27f177a8fa3f281889ad509fea7'
  cpus: 8
  distribution:
    distribution: fedora
    version: "32"
  eventLogger: file
  hostname: xxxxxx.lan
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 5.7.17-200.fc32.x86_64
  linkmode: dynamic
  memFree: 27110072320
  memTotal: 33613930496
  ociRuntime:
    name: crun
    package: crun-0.14.1-3.fc32.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 0.14.1
      commit: 598ea5e192ca12d4f6378217d3ab1415efeddefa
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +YAJL
  os: linux
  remoteSocket:
    path: /run/podman/podman.sock
  rootless: false
  slirp4netns:
    executable: ""
    package: ""
    version: ""
  swapFree: 16873680896
  swapTotal: 16873680896
  uptime: 6h 12m 59.46s (Approximately 0.25 days)
registries:
  search:
  - registry.fedoraproject.org
  - registry.access.redhat.com
  - registry.centos.org
  - docker.io
  xxxxxx.lan:5000:
    Blocked: false
    Insecure: true
    Location: xxxxxx.lan:5000
    MirrorByDigestOnly: false
    Mirrors: []
    Prefix: steve-linux.lan:5000
store:
  configFile: /etc/containers/storage.conf
  containerStore:
    number: 1
    paused: 0
    running: 1
    stopped: 0
  graphDriverName: overlay
  graphOptions:
    overlay.mountopt: nodev,metacopy=on
  graphRoot: /mnt/podman/lib/containers/storage
  graphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "true"
  imageStore:
    number: 65
  runRoot: /mnt/podman/run/containers/storage
  volumePath: /mnt/podman/lib/containers/storage/volumes
version:
  APIVersion: 1
  Built: 0
  BuiltTime: Thu Jan  1 01:00:00 1970
  GitCommit: ""
  GoVersion: go1.14.6
  OsArch: linux/amd64
  Version: 2.0.5

Package info (e.g. output of rpm -q podman or apt list podman):

podman-2.0.5-1.fc32.x86_64

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide?

Yes
Have tested with 2.0.4 & 2.0.5

Additional environment details (AWS, VirtualBox, physical, etc.):
Physical server

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Aug 28, 2020
@TomSweeneyRedHat
Copy link
Member

@st1971 thanks for the issue report. A couple of questions.

If you run this same image as root, does it have an /etc/hosts file? Also, can you share how you created the container image initially? Depending on the build options, this might be expected.

@st1971
Copy link
Contributor Author

st1971 commented Aug 28, 2020

@TomSweeneyRedHat Thank you for taking a look, much appreciated.

This is happening only as root and i am using a vanilla fedora:32 image pulled from registry.fedoraproject.org. Both of the below are run as root..

With --uidmap

podman run --rm -it --uidmap=0:100000:5000 registry.fedoraproject.org/fedora:32 /bin/bash -c "cat /etc/hosts"
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

Without --uidmap

podman run --rm -it registry.fedoraproject.org/fedora:32 /bin/bash -c "cat /etc/hosts"
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
10.88.0.168	dca9379e61d8

Also get the same with a stock alpine image from docker.io.

@mheon
Copy link
Member

mheon commented Sep 4, 2020

Suspicion: This is due to postConfigureNetNS.

Generally speaking, Podman configures the network namespace completely, then creates any files it needs to bind-mount in (/etc/hosts amount them), then goes ahead with container creation. However, with containers in a user namespace, we are forced to use a different flow - the network namespace is configured much later in the process, after /etc/hosts is created, so we don't know what the container's IP is - so the code treats it like a container that doesn't have one, and does not add an entry to /etc/hosts.

We can probably edit /etc/hosts once the IP is known in the user namespace case to resolve this.

@github-actions
Copy link

github-actions bot commented Oct 5, 2020

A friendly reminder that this issue had no activity for 30 days.

rhatdan added a commit to rhatdan/podman that referenced this issue Oct 6, 2020
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>
rhatdan added a commit to rhatdan/podman that referenced this issue Oct 6, 2020
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>
rhatdan added a commit to rhatdan/podman that referenced this issue Oct 6, 2020
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>
rhatdan added a commit to rhatdan/podman that referenced this issue Oct 7, 2020
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>
rhatdan added a commit to rhatdan/podman that referenced this issue Oct 7, 2020
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>
edsantiago pushed a commit to edsantiago/libpod that referenced this issue Nov 4, 2020
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>
@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
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. stale-issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants