fix(podman): mount managed /etc/hosts for all custom services#1105
fix(podman): mount managed /etc/hosts for all custom services#1105erhanurgun wants to merge 1 commit into
Conversation
Custom services without ShareHosts received no /etc/hosts mount, so podman synthesised the file from base_hosts_file, which defaults to the host's own /etc/hosts. Any "127.0.0.1 lerd-<svc>" line there (a stale entry from an older lerd, or one written for a client shim / host-proxy app) then shadows the container-DNS name: sidecar services such as phpmyadmin, pgadmin and mongo-express resolve lerd-mysql to their own loopback and fail with "mysqli::real_connect(): (HY000/2002): Connection refused". Mount the managed container hosts file in the else branch so every custom service overrides host inheritance. ShareHosts services keep the browser-hosts variant for .test resolution. PHP-FPM containers already bind-mount this file; this brings sidecar services in line.
|
thanks for the patch, can I ask what the mount is actually for? I can't work out what these sidecars read out of that file, it carries localhost, host.containers.internal and the .test domains, and phpMyAdmin, pgAdmin and Mongo Express want none of those, since lerd-phpmyadmin resolves lerd-mysql through aardvark either way. So it reads like it's there to shadow the inherited file rather than supply anything, and I want to be sure that's the intent in case I'm missing a case. The inheritance is real, I checked and my sidecars are carrying my host /etc/hosts wholesale. What I can't place is the 127.0.0.1 lerd-mysql line, I grepped the repo including install.sh and nothing on our side writes it, and the client shim runs in a throwaway container on the lerd network so it resolves through container DNS without touching the host file. Any chance you remember what put it there? If lerd wrote it that's the bug to fix, and if not we're really deciding whether to isolate sidecars on principle, which is fair but a different change. If it is just isolation we want, podman's --hosts-file none does that while keeping its own generated entries including the container's own name, though it was renamed across versions so it'd need a capability check like the StopTimeout one. One heads up either way, WriteFPMQuadlet calls ensureFPMHostsFile first because podman creates a directory at a missing Volume source, and EnsureCustomServiceQuadlet doesn't materialise the hosts file, so this has every custom service depending on a path nothing guarantees exists. |
Problem
Custom services created without
ShareHosts(phpmyadmin, pgadmin, mongo-express) receive no/etc/hostsmount. Podman then synthesises the file frombase_hosts_file, which defaults to the host's own/etc/hosts. Any127.0.0.1 lerd-<svc>line there — a stale entry from an older lerd, or one written for a client shim / host-proxy app — shadows the container-DNS name.The sidecar then resolves e.g.
lerd-mysqlto its own loopback and fails:phpMyAdmin, pgAdmin and Mongo Express all break this way. PHP-FPM containers are unaffected because they already bind-mount the managed hosts file, so the two paths were inconsistent.
Fix
Mount the managed container hosts file in the
elsebranch ofGenerateCustomQuadlet, so every custom service overrides host/etc/hostsinheritance.ShareHostsservices keep the browser-hosts variant for.testresolution.Test
TestGenerateCustomQuadlet_NoShareHoststo assert the managed hosts mount is present (and the browser variant is not).TestGenerateCustomQuadlet_ShareHostsunchanged and passing.127.0.0.1 lerd-mysqlline present on the host, a phpMyAdmin container regenerated with the mount resolveslerd-mysqlvia container DNS and connects (MySQL 8.4.10), where before it returned Connection refused.