Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

DNS lookups should not be case sensitive. #1462

Merged
merged 2 commits into from
Oct 1, 2015
Merged

Conversation

tomwilkie
Copy link
Contributor

Fixes #1461

@tomwilkie tomwilkie self-assigned this Sep 23, 2015
@tomwilkie tomwilkie force-pushed the 1461-dns-case-sensitive branch 2 times, most recently from dcb1a83 to ce30e26 Compare September 23, 2015 03:15
entries := n.entries.tombstone(n.ourName, func(e *Entry) bool {
if hostname != "*" && e.Hostname != hostname {
if hostname != "*" && strings.ToLower(e.Hostname) != lowerHostname {

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

@tomwilkie tomwilkie force-pushed the 1461-dns-case-sensitive branch 2 times, most recently from fd8b6cb to 50ba1db Compare September 23, 2015 04:34
@tomwilkie tomwilkie changed the title [WIP] DNS lookups should not be case sensitive. DNS lookups should not be case sensitive. Sep 23, 2015
@tomwilkie tomwilkie removed their assignment Sep 23, 2015
@tomwilkie
Copy link
Contributor Author

@inercia would you mind giving this a look please?

@rade
Copy link
Member

rade commented Sep 24, 2015

What about the domain? Should that be treated case insensitively too?

Also, what's the motivation for dealing with the case insensitivity in the various lookups/comparisons, instead of simply lower-casing the hostname on entry creation?

@tomwilkie
Copy link
Contributor Author

What about the domain? Should that be treated case insensitively too?

Domain is included in the hostname here (see https://github.com/weaveworks/weave/blob/master/weave#L844)

Also, what's the motivation for dealing with the case insensitivity in the various lookups/comparisons, instead of simply lower-casing the hostname on entry creation?

Backwards compatibility.

@inercia inercia self-assigned this Sep 24, 2015
@tomwilkie
Copy link
Contributor Author

Also, what's the motivation for dealing with the case insensitivity in the various lookups/comparisons, instead of simply lower-casing the hostname on entry creation?

Actually this will change the sort order, which means it isn't backwards compatible. Will change to lowercasing on entry creation.

@tomwilkie tomwilkie force-pushed the 1461-dns-case-sensitive branch 2 times, most recently from 9da34b1 to 99c7085 Compare September 25, 2015 07:14
@rade
Copy link
Member

rade commented Sep 25, 2015

Will change to lowercasing on entry creation.

So where does that leave us w.r.t. backward compatibility?

@tomwilkie
Copy link
Contributor Author

So where does that leave us w.r.t. backward compatibility?

If you are running a mixed 1.1/1.2 cluster

  • the 1.1 host will resolve lower case versions of the containers on the weave 1.2 hosts
  • if you are using non-lowercase hostnames/domain on a weave 1.1 hosts, the 1.2 host will not be able to resolve those names.

(1) is probably fine, but (2) looks like a show stopper. We could solve it by:

  • also looking for non-lowercased names in the lookup method (as well as lowercased names)
  • going back to original scheme (don't lowercase on the way in, just on search), but keeping the case on sort. This would also fix (1).

@rade
Copy link
Member

rade commented Sep 28, 2015

I reckon add/remove should be case-sensitive, but lookup shouldn't be, i.e. it should return all records that match case-insensitively. I suspect this is how normal DNS servers behave, e.g. you can give them a zone file with mixed case records and they will return case-insensitively matching ones on lookup. Worth checking though.

@tomwilkie tomwilkie force-pushed the 1461-dns-case-sensitive branch from 99c7085 to 85494b1 Compare September 28, 2015 08:18
@tomwilkie
Copy link
Contributor Author

I reckon add/remove should be case-sensitive

Agreed.

Attempt (3) - only do case insensitive matching on lookup. Re: backwards compatibility - sort order is preserved. From a 1.1 host, lookup will be case sensitive, and from a 1.2 host, it will not be.

@tomwilkie tomwilkie force-pushed the 1461-dns-case-sensitive branch from 85494b1 to 5788c34 Compare September 28, 2015 08:22
@tomwilkie
Copy link
Contributor Author

Actually this won't work either; sort on a string puts all the upper case before the lowercase:

http://play.golang.org/p/UXLptUu953

func main() {
    a := []string{"aaa", "Aaa", "bbb", "Bbb", "aAa", "aaA", "bBb", "bbB"}
    sort.Strings(a)
    fmt.Println(a)
}
[Aaa Bbb aAa aaA aaa bBb bbB bbb]

Back to drawing board.

@rade
Copy link
Member

rade commented Sep 28, 2015

Actually this won't work either; sort on a string puts all the upper case before the lowercase

The objective is correct. Your implementation is broken.

@tomwilkie
Copy link
Contributor Author

If we change the sort order the gossip messages will fail to merge with 1.1 hosts. So we can't change the sort order.

We could make lookup O(n), but that sucks.

@tomwilkie tomwilkie assigned tomwilkie and unassigned inercia Sep 28, 2015
@rade
Copy link
Member

rade commented Sep 28, 2015

If we change the sort order the gossip messages will fail to merge with 1.1 hosts.

How would this manifest itself?

@tomwilkie
Copy link
Contributor Author

Routers with different sort orders would drop the connection to each other (nameserver.go:218 would fail)

@rade
Copy link
Member

rade commented Sep 28, 2015

Why not sort the received data instead of checking that it is sorted?

@bboreham
Copy link
Contributor

If you're sorting case-sensitively, why would the order be different?

@rade
Copy link
Member

rade commented Sep 28, 2015

If you're sorting case-sensitively, why would the order be different?

It wouldn't be but then you cannot do an efficient case _in_sensitive lookup.

@tomwilkie
Copy link
Contributor Author

Why not sort the received data instead of checking that it is sorted?

We can do that in 1.2, but the doesn't help with 1.2 sending gossips to 1.1.

@rade
Copy link
Member

rade commented Sep 28, 2015

Oh dear. Looks like we are in a bit of pickle here.

@dpw
Copy link
Contributor

dpw commented Sep 28, 2015

Why can't you decouple the data structure that you gossip (which needs to be case-sensitively sorted for compatibility) from the data structure that you do lookups in?

@tomwilkie
Copy link
Contributor Author

@dpw we can, or course. But we haven't done that yet (as it is simpler, with less code, not to).

As part of the original design we discussed putting indexes on the entries data structure to accelerate non-hostname lookups (ie reverse lookups, or delete by container id). Perhaps, now that the order of the entires doesn't help for lookup, this is needed for lookups too?

@tomwilkie
Copy link
Contributor Author

And a even simpler solution would be to do a case sensitive sort for gossips we send, and a case-insensitive sort on gossips we receive.

@dpw
Copy link
Contributor

dpw commented Sep 28, 2015

@dpw we can, or course. But we haven't done that yet (as it is simpler, with less code, not to).

Ok. I interpreted Matthias' "bit of a pickle" comment as suggesting that there was some genuine difficulty, not merely the need to write some code that you'd prefer not to. As you were then.

@tomwilkie tomwilkie force-pushed the 1461-dns-case-sensitive branch from af5a36b to 2e95fba Compare September 30, 2015 10:06
@tomwilkie
Copy link
Contributor Author

@rade PTAL

Failures are in 602_proxy_docker_py_test and are unrelated.

@tomwilkie tomwilkie assigned rade and unassigned tomwilkie Sep 30, 2015
es.checkAndPanic()
defer es.checkAndPanic()
checkAndPanic(CaseInsensitive(*es))
defer func() { checkAndPanic(CaseInsensitive(*es)) }()

This comment was marked as abuse.

@rade rade assigned tomwilkie and unassigned rade Sep 30, 2015
- On-the-wire gossip messages are sorted case sensitive, but in memory they are sorted case-insensitive.
- Add test for case insensitive match on multiple names.
@tomwilkie
Copy link
Contributor Author

Have tested manually - ubuntu-14 is this branch, ubuntu-15 is 1.1:

vagrant@ubuntu-14:~/src/github.com/weaveworks/weave$ nslookup searchapp.weave.local 172.17.42.1
Server:     172.17.42.1
Address:    172.17.42.1#53

Name:   searchapp.weave.local
Address: 10.32.0.12
Name:   searchapp.weave.local
Address: 10.40.0.2
Name:   searchapp.weave.local
Address: 10.40.0.3
Name:   searchapp.weave.local
Address: 10.32.0.4
Name:   searchapp.weave.local
Address: 10.32.0.3

vagrant@ubuntu-14:~/src/github.com/weaveworks/weave$ weave status dns
app          10.40.0.7       63acc94a6eed 56:f7:a1:9a:90:ff
app          10.40.0.6       c4078e711876 56:f7:a1:9a:90:ff
app          10.32.0.7       09cf6c314865 ae:23:70:89:80:61
app          10.32.0.8       5a7ac5be5157 ae:23:70:89:80:61
client       10.40.0.10      9b34528aee2e 56:f7:a1:9a:90:ff
client       10.32.0.11      2073da265f48 ae:23:70:89:80:61
elasticsearch 10.32.0.2       661f8e294fef ae:23:70:89:80:61
frontend     10.40.0.8       23d34d5994e1 56:f7:a1:9a:90:ff
frontend     10.40.0.9       52763050e15c 56:f7:a1:9a:90:ff
frontend     10.32.0.10      d34742dd2a09 ae:23:70:89:80:61
frontend     10.32.0.9       ff88aad13e05 ae:23:70:89:80:61
qotd         10.40.0.5       4c0277bfbc51 56:f7:a1:9a:90:ff
qotd         10.32.0.6       0dee827d5b34 ae:23:70:89:80:61
redis        10.40.0.4       14c131aec9e3 56:f7:a1:9a:90:ff
redis        10.32.0.5       038b5dd8171a ae:23:70:89:80:61
searchapp    10.40.0.2       97992c807504 56:f7:a1:9a:90:ff
searchapp    10.40.0.3       fa539363ed99 56:f7:a1:9a:90:ff
searchapp    10.32.0.3       35ec6a8ea094 ae:23:70:89:80:61
Searchapp    10.32.0.12      4e90d538db02 ae:23:70:89:80:61
searchapp    10.32.0.4       940d037096b5 ae:23:70:89:80:61
vagrant@ubuntu-15:~/src/github.com/weaveworks/scope$ weave status dns
Searchapp    10.32.0.12      4e90d538db02 ae:23:70:89:80:61
app          10.40.0.7       63acc94a6eed 56:f7:a1:9a:90:ff
app          10.40.0.6       c4078e711876 56:f7:a1:9a:90:ff
app          10.32.0.7       09cf6c314865 ae:23:70:89:80:61
app          10.32.0.8       5a7ac5be5157 ae:23:70:89:80:61
client       10.40.0.10      9b34528aee2e 56:f7:a1:9a:90:ff
client       10.32.0.11      2073da265f48 ae:23:70:89:80:61
elasticsearch 10.32.0.2       661f8e294fef ae:23:70:89:80:61
frontend     10.40.0.8       23d34d5994e1 56:f7:a1:9a:90:ff
frontend     10.40.0.9       52763050e15c 56:f7:a1:9a:90:ff
frontend     10.32.0.10      d34742dd2a09 ae:23:70:89:80:61
frontend     10.32.0.9       ff88aad13e05 ae:23:70:89:80:61
qotd         10.40.0.5       4c0277bfbc51 56:f7:a1:9a:90:ff
qotd         10.32.0.6       0dee827d5b34 ae:23:70:89:80:61
redis        10.40.0.4       14c131aec9e3 56:f7:a1:9a:90:ff
redis        10.32.0.5       038b5dd8171a ae:23:70:89:80:61
searchapp    10.40.0.2       97992c807504 56:f7:a1:9a:90:ff
searchapp    10.40.0.3       fa539363ed99 56:f7:a1:9a:90:ff
searchapp    10.32.0.3       35ec6a8ea094 ae:23:70:89:80:61
searchapp    10.32.0.4       940d037096b5 ae:23:70:89:80:61

@tomwilkie tomwilkie force-pushed the 1461-dns-case-sensitive branch from 4ba1f23 to 357174e Compare October 1, 2015 12:43
@tomwilkie tomwilkie removed their assignment Oct 1, 2015
@tomwilkie
Copy link
Contributor Author

Failure in test is the docker py test_792_explicit_port_protocol failure, unrelated.


weave_on $HOST1 launch

start_container_with_dns $HOST1 --name=test

This comment was marked as abuse.

rade added a commit that referenced this pull request Oct 1, 2015
DNS lookups should not be case sensitive.

Fixes #1461.
@rade rade merged commit 49459cf into master Oct 1, 2015
@rade rade deleted the 1461-dns-case-sensitive branch October 1, 2015 15:52
@rade rade added this to the 1.2.0 milestone Oct 5, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants