mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix user specified ndots option
Setting ndots to 0 does not allow to resolve search domains The default will remain ndots:0 that will directly resolve services, but if the user specify a different ndots value just propagate it into the container Signed-off-by: Flavio Crisciani <flavio.crisciani@docker.com>
This commit is contained in:
parent
1eaa943f64
commit
5a658d4cc1
2 changed files with 24 additions and 7 deletions
|
@ -362,7 +362,7 @@ func (sb *sandbox) rebuildDNS() error {
|
|||
dnsOpt:
|
||||
for _, resOpt := range resOptions {
|
||||
if strings.Contains(resOpt, "ndots") {
|
||||
for i, option := range dnsOptionsList {
|
||||
for _, option := range dnsOptionsList {
|
||||
if strings.Contains(option, "ndots") {
|
||||
parts := strings.Split(option, ":")
|
||||
if len(parts) != 2 {
|
||||
|
@ -371,10 +371,8 @@ dnsOpt:
|
|||
if num, err := strconv.Atoi(parts[1]); err != nil {
|
||||
return fmt.Errorf("invalid number for ndots option %v", option)
|
||||
} else if num > 0 {
|
||||
// if the user sets ndots, we mark it as set but we remove the option to guarantee
|
||||
// that into the container land only ndots:0
|
||||
// if the user sets ndots, use the user setting
|
||||
sb.ndotsSet = true
|
||||
dnsOptionsList = append(dnsOptionsList[:i], dnsOptionsList[i+1:]...)
|
||||
break dnsOpt
|
||||
}
|
||||
}
|
||||
|
@ -382,7 +380,11 @@ dnsOpt:
|
|||
}
|
||||
}
|
||||
|
||||
dnsOptionsList = append(dnsOptionsList, resOptions...)
|
||||
if !sb.ndotsSet {
|
||||
// if the user did not set the ndots, set it to 0 to prioritize the service name resolution
|
||||
// Ref: https://linux.die.net/man/5/resolv.conf
|
||||
dnsOptionsList = append(dnsOptionsList, resOptions...)
|
||||
}
|
||||
|
||||
_, err = resolvconf.Build(sb.config.resolvConfPath, dnsList, dnsSearchList, dnsOptionsList)
|
||||
return err
|
||||
|
|
|
@ -55,15 +55,30 @@ func TestDNSOptions(t *testing.T) {
|
|||
defer sb.Delete()
|
||||
sb.(*sandbox).startResolver(false)
|
||||
|
||||
sb.(*sandbox).config.dnsOptionsList = []string{"ndots:5"}
|
||||
err = sb.(*sandbox).setupDNS()
|
||||
require.NoError(t, err)
|
||||
err = sb.(*sandbox).rebuildDNS()
|
||||
require.NoError(t, err)
|
||||
|
||||
currRC, err := resolvconf.GetSpecific(sb.(*sandbox).config.resolvConfPath)
|
||||
require.NoError(t, err)
|
||||
dnsOptionsList := resolvconf.GetOptions(currRC.Content)
|
||||
assert.Equal(t, 1, len(dnsOptionsList), "There should be only 1 option instead:", dnsOptionsList)
|
||||
assert.Equal(t, "ndots:0", dnsOptionsList[0], "The option must be ndots:0 instead:", dnsOptionsList[0])
|
||||
|
||||
sb.(*sandbox).config.dnsOptionsList = []string{"ndots:5"}
|
||||
err = sb.(*sandbox).setupDNS()
|
||||
require.NoError(t, err)
|
||||
currRC, err = resolvconf.GetSpecific(sb.(*sandbox).config.resolvConfPath)
|
||||
require.NoError(t, err)
|
||||
dnsOptionsList = resolvconf.GetOptions(currRC.Content)
|
||||
assert.Equal(t, 1, len(dnsOptionsList), "There should be only 1 option instead:", dnsOptionsList)
|
||||
assert.Equal(t, "ndots:5", dnsOptionsList[0], "The option must be ndots:5 instead:", dnsOptionsList[0])
|
||||
|
||||
err = sb.(*sandbox).rebuildDNS()
|
||||
require.NoError(t, err)
|
||||
currRC, err = resolvconf.GetSpecific(sb.(*sandbox).config.resolvConfPath)
|
||||
require.NoError(t, err)
|
||||
dnsOptionsList = resolvconf.GetOptions(currRC.Content)
|
||||
assert.Equal(t, 1, len(dnsOptionsList), "There should be only 1 option instead:", dnsOptionsList)
|
||||
assert.Equal(t, "ndots:5", dnsOptionsList[0], "The option must be ndots:5 instead:", dnsOptionsList[0])
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue