Skip to content

Commit

Permalink
append podman dns search domain
Browse files Browse the repository at this point in the history
Append the podman dns seach domain to the host search domains when we
use the dnsname/aardvark server. Previously it would only use podman
seach domains and discard the host domains.

Fixes containers#13103

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 authored and mheon committed Feb 10, 2022
1 parent b1bf91a commit bcd5f5e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
22 changes: 11 additions & 11 deletions libpod/container_internal_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2099,38 +2099,38 @@ func (c *Container) generateResolvConf() (string, error) {
}
dnsServers := append(dns, c.config.DNSServer...)
// If the user provided dns, it trumps all; then dns masq; then resolv.conf
var search []string
switch {
case len(dnsServers) > 0:

// We store DNS servers as net.IP, so need to convert to string
for _, server := range dnsServers {
nameservers = append(nameservers, server.String())
}
case len(networkNameServers) > 0:
nameservers = append(nameservers, networkNameServers...)
default:
// Make a new resolv.conf
nameservers = resolvconf.GetNameservers(resolv.Content)
// slirp4netns has a built in DNS server.
// first add the nameservers from the networks status
nameservers = append(nameservers, networkNameServers...)
// when we add network dns server we also have to add the search domains
search = networkSearchDomains
// slirp4netns has a built in DNS forwarder.
if c.config.NetMode.IsSlirp4netns() {
slirp4netnsDNS, err := GetSlirp4netnsDNS(c.slirp4netnsSubnet)
if err != nil {
logrus.Warn("Failed to determine Slirp4netns DNS: ", err.Error())
} else {
nameservers = append([]string{slirp4netnsDNS.String()}, nameservers...)
nameservers = append(nameservers, slirp4netnsDNS.String())
}
}
nameservers = append(nameservers, resolvconf.GetNameservers(resolv.Content)...)
}

var search []string
if len(c.config.DNSSearch) > 0 || len(c.runtime.config.Containers.DNSSearches) > 0 || len(networkSearchDomains) > 0 {
if len(c.config.DNSSearch) > 0 || len(c.runtime.config.Containers.DNSSearches) > 0 {
if !util.StringInSlice(".", c.config.DNSSearch) {
search = c.runtime.config.Containers.DNSSearches
search = append(search, c.runtime.config.Containers.DNSSearches...)
search = append(search, c.config.DNSSearch...)
search = append(search, networkSearchDomains...)
}
} else {
search = resolvconf.GetSearchDomains(resolv.Content)
search = append(search, resolvconf.GetSearchDomains(resolv.Content)...)
}

var options []string
Expand Down
24 changes: 21 additions & 3 deletions test/system/500-networking.bats
Original file line number Diff line number Diff line change
Expand Up @@ -605,9 +605,27 @@ load helpers
"8.8.8.8",
]
EOF
CONTAINERS_CONF=$containersconf run_podman run --rm $IMAGE grep "example.com" /etc/resolv.conf
CONTAINERS_CONF=$containersconf run_podman run --rm $IMAGE grep $searchIP /etc/resolv.conf
is "$output" "nameserver $searchIP" "Should only be one $searchIP not multiple"

local nl="
"

CONTAINERS_CONF=$containersconf run_podman run --rm $IMAGE cat /etc/resolv.conf
is "$output" "search example.com$nl.*" "correct seach domain"
is "$output" ".*nameserver 1.1.1.1${nl}nameserver $searchIP${nl}nameserver 1.0.0.1${nl}nameserver 8.8.8.8" "nameserver order is correct"

# create network with dns
local netname=testnet-$(random_string 10)
local subnet=$(random_rfc1918_subnet)
run_podman network create --subnet "$subnet.0/24" $netname
# custom server overwrites the network dns server
CONTAINERS_CONF=$containersconf run_podman run --network $netname --rm $IMAGE cat /etc/resolv.conf
is "$output" "search example.com$nl.*" "correct seach domain"
is "$output" ".*nameserver 1.1.1.1${nl}nameserver $searchIP${nl}nameserver 1.0.0.1${nl}nameserver 8.8.8.8" "nameserver order is correct"

# we should use the integrated dns server
run_podman run --network $netname --rm $IMAGE cat /etc/resolv.conf
is "$output" "search dns.podman.*" "correct seach domain"
is "$output" ".*nameserver $subnet.1.*" "integrated dns nameserver is set"
}

# vim: filetype=sh

0 comments on commit bcd5f5e

Please sign in to comment.