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

REST APIv2 - rootless - hostname not added to /etc/hosts #7934

Closed
psakar opened this issue Oct 6, 2020 · 6 comments · Fixed by #7952
Closed

REST APIv2 - rootless - hostname not added to /etc/hosts #7934

psakar opened this issue Oct 6, 2020 · 6 comments · Fixed by #7952
Assignees
Labels
In Progress This issue is actively being worked by the assignee, please do not work on this at this time. 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

@psakar
Copy link
Contributor

psakar commented Oct 6, 2020

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

/kind bug

Description

Container created via REST APIv2 is unable to resolve its hostname because the assigned hostname is missing in container /etc/hosts

Steps to reproduce the issue:

# start podman REST API
podman --log-level=debug system service -t 0 tcp:localhost:8880 2>&1>/tmp/podman-rest.log &

curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8880/containers/create?name=test' --data '{"name":"test","Image":"localhost/test:latest", "Cmd":["/bin/sh", "-c", "tail -2 /etc/hosts"]}'
curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8880/containers/test/start'
curl --output - -H "Content-Type: application/json" "http://127.0.0.1:8880/containers/test/logs?stdout=true&stderr=true"

Describe the results you received:
Last two lines from file /etc/hosts from my laptop

Describe the results you expected:

# used by slirp4netns
10.0.2.100	3ff0b3519d00 test

(Value 3ff0b3519d00 would be different ...)

Additional information you deem important (e.g. issue happens only occasionally):
May be because netmode is not set ? Applying following patch fixes the issue (most probably wrong, just to test)

diff --git a/pkg/api/handlers/compat/containers_create.go b/pkg/api/handlers/compat/containers_create.go
index 0579da8de..6b92935b9 100644
--- a/pkg/api/handlers/compat/containers_create.go
+++ b/pkg/api/handlers/compat/containers_create.go
@@ -144,7 +144,7 @@ func makeCreateConfig(ctx context.Context, containerConfig *config.Config, input
 		IPAddress:    "",
 		LinkLocalIP:  nil, // docker-only
 		MacAddress:   input.MacAddress,
-		// NetMode:      nil,
+		NetMode:      namespaces.NetworkMode("slirp4netns"),
 		Network:      input.HostConfig.NetworkMode.NetworkName(),
 		NetworkAlias: nil, // docker-only now
 		PortBindings: input.HostConfig.PortBindings,

Output of podman version:

Version:      2.1.1
API Version:  2.0.0
Go Version:   go1.13.15
Built:        Wed Sep 30 21:51:15 2020
OS/Arch:      linux/amd64

Output of podman info --debug:

host:
  arch: amd64
  buildahVersion: 1.16.1
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.0.21-2.fc31.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.0.21, commit: d9f047cb413248e30a1ec560547d9b203396c31b'
  cpus: 8
  distribution:
    distribution: fedora
    version: "31"
  eventLogger: journald
  hostname: localhost
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 21528
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
    uidmap:
    - container_id: 0
      host_id: 21528
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
  kernel: 5.8.11-100.fc31.x86_64
  linkmode: dynamic
  memFree: 1259569152
  memTotal: 16381120512
  ociRuntime:
    name: crun
    package: crun-0.15-5.fc31.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 0.15
      commit: 56ca95e61639510c7dbd39ff512f80f626404969
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +YAJL
  os: linux
  remoteSocket:
    path: /run/user/21528/podman/podman.sock
  rootless: true
  slirp4netns:
    executable: /bin/slirp4netns
    package: slirp4netns-1.1.4-1.fc31.x86_64
    version: |-
      slirp4netns version 1.1.4
      commit: b66ffa8e262507e37fca689822d23430f3357fe8
      libslirp: 4.1.0
      SLIRP_CONFIG_VERSION_MAX: 1
  swapFree: 8252289024
  swapTotal: 8252289024
  uptime: 7h 55m 36.8s (Approximately 0.29 days)
registries:
  search:
  - registry.fedoraproject.org
  - registry.access.redhat.com
  - registry.centos.org
  - docker.io
store:
  configFile: /home/psakar/.config/containers/storage.conf
  containerStore:
    number: 3
    paused: 0
    running: 0
    stopped: 3
  graphDriverName: vfs
  graphOptions: {}
  graphRoot: /home/psakar/.local/share/containers/storage
  graphStatus: {}
  imageStore:
    number: 67
  runRoot: /run/user/21528/run
  volumePath: /home/psakar/.local/share/containers/storage/volumes
version:
  APIVersion: 2.0.0
  Built: 1601495475
  BuiltTime: Wed Sep 30 21:51:15 2020
  GitCommit: ""
  GoVersion: go1.13.15
  OsArch: linux/amd64
  Version: 2.1.1

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

podman-2.1.1-3.fc31.x86_64

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

Yes (not tested with master)

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

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Oct 6, 2020
@psakar
Copy link
Contributor Author

psakar commented Oct 6, 2020

related to testcontainers/testcontainers-java#2088 and #7235

@baude baude self-assigned this Oct 6, 2020
@baude baude added the In Progress This issue is actively being worked by the assignee, please do not work on this at this time. label Oct 6, 2020
@baude
Copy link
Member

baude commented Oct 6, 2020

@psakar could you confirm if you are running the service as rootfull or rootless?

@baude
Copy link
Member

baude commented Oct 6, 2020

@psakar im asking because i just ran your reproducer with upstream main branch and it ran correctly as rootful.

@baude baude removed the In Progress This issue is actively being worked by the assignee, please do not work on this at this time. label Oct 6, 2020
@psakar
Copy link
Contributor Author

psakar commented Oct 6, 2020

@baude rootless (as noted in title)

@baude
Copy link
Member

baude commented Oct 6, 2020

@psakar ty! i cannot believe i missed that. The # instead of $ was probably confusing me. I'll take another peek.

@baude
Copy link
Member

baude commented Oct 7, 2020

Ok, I can reproduce this.

@baude baude added the In Progress This issue is actively being worked by the assignee, please do not work on this at this time. label Oct 7, 2020
baude added a commit to baude/podman that referenced this issue Oct 7, 2020
when using the compatibility mode as rootless, containers that were created were not setting their host names correctly due to the netmode not being set.

Fixes: containers#7934

Signed-off-by: baude <[email protected]>
@baude baude added In Progress This issue is actively being worked by the assignee, please do not work on this at this time. and removed In Progress This issue is actively being worked by the assignee, please do not work on this at this time. labels Oct 7, 2020
mheon pushed a commit to mheon/libpod that referenced this issue Oct 14, 2020
when using the compatibility mode as rootless, containers that were created were not setting their host names correctly due to the netmode not being set.

Fixes: containers#7934

Signed-off-by: baude <[email protected]>
@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
In Progress This issue is actively being worked by the assignee, please do not work on this at this time. 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.

3 participants