mirror of
https://github.com/clearlinux/docker.git
synced 2026-09-06 21:51:33 +00:00
Add warning for --dns flag set to localhost addresses.
We should warn users who use the `--dns` command line option to point DNS to a localhost address, either IPv4 or IPv6. Unless they have specifically set up the container as a DNS server or are using --net=host (which is why this should be allowed, but warned on because those are pretty unique cases) a localhost address as a resolver will not reach what they might expect (e.g. expecting it will hit localhost on the Docker daemon/host). Added a test for the message, and fixed up tests to separate stdout and stderr that were using `--dns=127.0.0.1` to test the options. Docker-DCO-1.1-Signed-off-by: Phil Estes <estesp@linux.vnet.ibm.com> (github: estesp)
This commit is contained in:
@@ -1463,11 +1463,16 @@ func TestRunDnsOptions(t *testing.T) {
|
||||
|
||||
cmd := exec.Command(dockerBinary, "run", "--dns=127.0.0.1", "--dns-search=mydomain", "busybox", "cat", "/etc/resolv.conf")
|
||||
|
||||
out, _, err := runCommandWithOutput(cmd)
|
||||
out, stderr, _, err := runCommandWithStdoutStderr(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err, out)
|
||||
}
|
||||
|
||||
// The client will get a warning on stderr when setting DNS to a localhost address; verify this:
|
||||
if !strings.Contains(stderr, "Localhost DNS setting") {
|
||||
t.Fatalf("Expected warning on stderr about localhost resolver, but got %q", stderr)
|
||||
}
|
||||
|
||||
actual := strings.Replace(strings.Trim(out, "\r\n"), "\n", " ", -1)
|
||||
if actual != "nameserver 127.0.0.1 search mydomain" {
|
||||
t.Fatalf("expected 'nameserver 127.0.0.1 search mydomain', but says: %q", actual)
|
||||
@@ -1475,7 +1480,7 @@ func TestRunDnsOptions(t *testing.T) {
|
||||
|
||||
cmd = exec.Command(dockerBinary, "run", "--dns=127.0.0.1", "--dns-search=.", "busybox", "cat", "/etc/resolv.conf")
|
||||
|
||||
out, _, err = runCommandWithOutput(cmd)
|
||||
out, _, _, err = runCommandWithStdoutStderr(cmd)
|
||||
if err != nil {
|
||||
t.Fatal(err, out)
|
||||
}
|
||||
@@ -1502,7 +1507,7 @@ func TestRunDnsOptionsBasedOnHostResolvConf(t *testing.T) {
|
||||
|
||||
var out string
|
||||
cmd := exec.Command(dockerBinary, "run", "--dns=127.0.0.1", "busybox", "cat", "/etc/resolv.conf")
|
||||
if out, _, err = runCommandWithOutput(cmd); err != nil {
|
||||
if out, _, _, err = runCommandWithStdoutStderr(cmd); err != nil {
|
||||
t.Fatal(err, out)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user