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

Podman 3.3 adds 127.0.0.1 /etc/hosts record for hostname, breaking gethostbyaddr for the hostname #11596

Closed
adelton opened this issue Sep 15, 2021 · 7 comments · Fixed by #11605
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.

Comments

@adelton
Copy link
Contributor

adelton commented Sep 15, 2021

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

/kind bug

Description

The change for #10319 via #11118 changed the /etc/hosts entry being added from 127.0.1.1 to 127.0.0.1. That in turn breaks gethostbyaddr in the container, at least in rootless pods.

Steps to reproduce the issue:

  1. podman pod create --name test-hostname --hostname machine.example.test --add-host machine.example.test:172.29.0.1
  2. podman run --rm --pod test-hostname registry.fedoraproject.org/fedora:34 cat /etc/hosts
  3. podman run --rm --pod test-hostname registry.fedoraproject.org/fedora:34 python3 -c 'import socket; print(socket.gethostbyaddr("machine.example.test"))'

Describe the results you received:

$ podman pod create --name test-hostname --hostname machine.example.test --add-host machine.example.test:172.29.0.1
be4669ba40ba018668c5aa057299f70328a3cdc9b9326b79a041ccdf4121b4ea
$ podman run --rm --pod test-hostname registry.fedoraproject.org/fedora:34 cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.29.0.1 machine.example.test
# used by slirp4netns
10.0.2.100	machine.example.test be4669ba40ba-infra
10.0.2.2 host.containers.internal
127.0.0.1 machine.example.test cranky_ritchie
$ podman run --rm --pod test-hostname registry.fedoraproject.org/fedora:34 python3 -c 'import socket; print(socket.gethostbyaddr("machine.example.test"))'
('localhost', ['localhost.localdomain', 'localhost4', 'localhost4.localdomain4'], ['127.0.0.1'])

Describe the results you expected:

$ podman pod create --name test-hostname --hostname machine.example.test --add-host machine.example.test:172.29.0.1
40b60852dfd48d40ff084d230572dd33c3fcf72ad8efc57a54aa42af98ef5a62
$ podman run --rm --pod test-hostname registry.fedoraproject.org/fedora:34 cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.29.0.1 machine.example.test
# used by slirp4netns
10.0.2.100	machine.example.test 40b60852dfd4-infra
10.0.2.2 host.containers.internal
127.0.1.1 machine.example.test brave_nightingale
$ podman run --rm --pod test-hostname registry.fedoraproject.org/fedora:34 python3 -c 'import socket; print(socket.gethostbyaddr("machine.example.test"))'
('machine.example.test', ['brave_nightingale'], ['127.0.1.1'])

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

This is a regression with podman-3.3.1-1.fc34.x86_64, against podman-3.2.3-1.fc34.x86_64.

Now the previous behaviour which returned 127.0.1.1 was not great either but at least the hostname returned was the actual container hostname, not localhost.

Output of podman version:

Version:      3.3.1
API Version:  3.3.1
Go Version:   go1.16.6
Built:        Mon Aug 30 22:46:36 2021
OS/Arch:      linux/amd64

Output of podman info --debug:

host:
  arch: amd64
  buildahVersion: 1.22.3
  cgroupControllers: []
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.0.29-2.fc34.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.29, commit: '
  cpus: 2
  distribution:
    distribution: fedora
    version: "34"
  eventLogger: journald
  hostname: kvm-01-guest16.lab.eng.brq.redhat.com
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
    uidmap:
    - container_id: 0
      host_id: 1000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
  kernel: 5.13.15-200.fc34.x86_64
  linkmode: dynamic
  memFree: 5698027520
  memTotal: 8326172672
  ociRuntime:
    name: crun
    package: crun-1.0-1.fc34.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 1.0
      commit: 139dc6971e2f1d931af520188763e984d6cdfbf8
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +YAJL
  os: linux
  remoteSocket:
    path: /run/user/1000/podman/podman.sock
  security:
    apparmorEnabled: false
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: true
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: true
  serviceIsRemote: false
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: slirp4netns-1.1.12-2.fc34.x86_64
    version: |-
      slirp4netns version 1.1.12
      commit: 7a104a101aa3278a2152351a082a6df71f57c9a3
      libslirp: 4.4.0
      SLIRP_CONFIG_VERSION_MAX: 3
      libseccomp: 2.5.0
  swapFree: 8325689344
  swapTotal: 8325689344
  uptime: 10h 17m 58.67s (Approximately 0.42 days)
registries:
  search:
  - registry.fedoraproject.org
  - registry.access.redhat.com
  - docker.io
  - quay.io
store:
  configFile: /home/test/.config/containers/storage.conf
  containerStore:
    number: 4
    paused: 0
    running: 4
    stopped: 0
  graphDriverName: overlay
  graphOptions: {}
  graphRoot: /home/test/.local/share/containers/storage
  graphStatus:
    Backing Filesystem: btrfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Using metacopy: "false"
  imageStore:
    number: 88
  runRoot: /run/user/1000/containers
  volumePath: /home/test/.local/share/containers/storage/volumes
version:
  APIVersion: 3.3.1
  Built: 1630356396
  BuiltTime: Mon Aug 30 22:46:36 2021
  GitCommit: ""
  GoVersion: go1.16.6
  OsArch: linux/amd64
  Version: 3.3.1

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

podman-3.3.1-1.fc34.x86_64

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/master/troubleshooting.md)

Yes (latest packaged in Fedora 34).

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

A Fedora 34 VM.

@rhatdan
Copy link
Member

rhatdan commented Sep 15, 2021

@Luap99 @mheon PTAL

@Luap99
Copy link
Member

Luap99 commented Sep 16, 2021

OK so I think the problem here is that our logic thinks joining the pod namespace is the same as the none networking mode.

I think we should never add 127.0.1.1 or 127.0.0.1 in case of joining the pod ns. @adelton Do you agree?

Edit: This is the result I get when 127... is not added.

$ bin/podman run --rm --pod test-hostname registry.fedoraproject.org/fedora:34 python3 -c 'import socket; print(socket.gethostbyaddr("machine.example.test"))'
('machine.example.test', ['d6fd0f0ae175-infra'], ['10.0.2.100'])

@adelton
Copy link
Contributor Author

adelton commented Sep 16, 2021

Yes, this looks like a good improvement.

Luap99 added a commit to Luap99/libpod that referenced this issue Sep 16, 2021
The check for net=none was wrong. It just assumed when we do not create
the netns but have one set that we use the none mode. This however also
applies to a container which joins the pod netns.
To correctly check for the none mode use `config.NetMode.IsNone()`.

Fixes containers#11596

Signed-off-by: Paul Holzinger <[email protected]>
mheon pushed a commit to mheon/libpod that referenced this issue Sep 22, 2021
The check for net=none was wrong. It just assumed when we do not create
the netns but have one set that we use the none mode. This however also
applies to a container which joins the pod netns.
To correctly check for the none mode use `config.NetMode.IsNone()`.

Fixes containers#11596

Signed-off-by: Paul Holzinger <[email protected]>
@adelton
Copy link
Contributor Author

adelton commented Oct 18, 2021

I see the fix should be in podman 3.4 but https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_21.04/ still has only 3.3.1. Is there any plan to build 3.4 there?

@mheon
Copy link
Member

mheon commented Oct 18, 2021

@lsm5 PTAL

adelton added a commit to adelton/freeipa-container that referenced this issue Dec 31, 2021
@Luap99
Copy link
Member

Luap99 commented Apr 20, 2022

@adelton FYI I tested this with my new /etc/hosts changes from #13918

The result I now get is ('machine.example.test', [], ['172.29.0.1']) which I assume works for you?
Basically the new logic makes sure to never overwrite entries that a user added with --add-host.

@adelton
Copy link
Contributor Author

adelton commented Apr 20, 2022

With podman-3.4.4-1.fc35.x86_64 I get

$ podman pod create --name test-hostname --hostname machine.example.test --add-host machine.example.test:172.29.0.1
01f31527cd44dc95468e48352c0799891e41f2ea13e92982b6468adaee94b1de
$ podman run --rm --pod test-hostname registry.fedoraproject.org/fedora:34 cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.29.0.1 machine.example.test
# used by slirp4netns
10.0.2.100	machine.example.test 01f31527cd44-infra
10.0.2.2 host.containers.internal
$ podman run --rm --pod test-hostname registry.fedoraproject.org/fedora:34 python3 -c 'import socket; print(socket.gethostbyaddr("machine.example.test"))'
('machine.example.test', ['01f31527cd44-infra'], ['10.0.2.100'])

I don't see a problem with the IP address being different as long as the hostname is the expected one.

@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 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants