Skip to content

Use the existence of an NS record to determine whether a domain is an apex domain #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 12, 2016

Conversation

haileys
Copy link
Contributor

@haileys haileys commented Aug 7, 2015

This will behave correctly even if a domain is not a listed public suffix. This could happen if a domain is a delegated zone, which can't have a CNAME record at the apex.

cc @benbalter @jdennes @spraints

Charlie Somerville added 3 commits August 7, 2015 10:11
Net::DNS was returning NS records it shouldn't have
stubbing the domain method fails to invalidate any of the memoized
results
@haileys haileys force-pushed the check-dns-for-apex-domains branch from 431ae3c to 2c9e2a5 Compare August 7, 2015 01:03
@haileys
Copy link
Contributor Author

haileys commented Aug 7, 2015

In 2c9e2a5 I changed one of the specs to create a new GitHubPages::HealthCheck object every time rather than stubbing the domain method of the existing one. Stubbing domain didn't actually flush any of the memoized data, so we were testing the wrong thing in some cases.

Should I go and update the rest of the stubs to just create a new object instead?

return @apex_domain if defined?(@apex_domain)

answers = Resolv::DNS.open { |dns|
dns.getresources(absolute_domain, Resolv::DNS::Resource::IN::NS)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I'm understanding correctly, since we already make a call to grab the DNS record, could this be simplified to use the dns method to save a call?

dns.any? { |answer| answer.class == Net::DNS::RR::NS }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately the DNS lookup we're already doing doesn't fetch NS records, it just asks for an A record. I don't think there's a way to look up multiple record types (except an ANY request - but that's on its way out)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh. Makes sense. Last thought would be that we might be able to continue to use Net:Dns (if there's any advantage over Resolve (?) with something like:

Net::DNS::Resolver.start("google.com", Net::DNS::NS)

You're the true Rubyist here, so trust your judgement on the dependency. Feel free to merge when you're ready. Thanks for tackling this. Gonna make many users 😸 .

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with Resolv because it was acting up on one of the test cases and returning records it shouldn't have:

>> Net::DNS::Resolver.start("blog.parkermoore.de", Net::DNS::NS).answer
=> [blog.parkermoore.de.    261     IN      CNAME   parkr.github.io., parkr.github.io.        3561    IN      CNAME   github.map.fastly.net.]
>> Resolv::DNS.open { |dns| dns.getresources("blog.parkermoore.de", Resolv::DNS::Resource::IN::NS) }
=> []

But we can probably just filter non-NS records out in Rubyland

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I think Net::DNS just wraps resolve, and it's a core lib, so it's not like we're adding an external dependency. If resolve works more cleanly, lets use that. 👍.

@benbalter
Copy link
Contributor

Should I go and update the rest of the stubs to just create a new object instead?

If you don't mind, that'd be awesome. Good catch.

@benbalter
Copy link
Contributor

Also, a dumb question, I know it doesn't make sense, but could I add an NS record to a subdomain?

@spraints
Copy link
Member

spraints commented Aug 7, 2015

Also, a dumb question, I know it doesn't make sense, but could I add an NS record to a subdomain?

Yes, you can. But if you do, then you wouldn't want to have a CNAME for that subdomain either. For example, pickardayune.com is an apex domain, so it has NS records and should not be a CNAME record. www.pickardayune.com is OK to be a CNAME. If I set an NS record to sub.pickardayune.com, then I shouldn't make sub.pickardayune.com also have a CNAME record. www.sub.pickardayune.com would be fine as a CNAME.

@benbalter
Copy link
Contributor

Ahh. @spraints thanks for dropping the :books.

@benbalter
Copy link
Contributor

As soon as this merges, glad to cut and deploy a new gem with this and the Proxy checks from #21.

@parkr
Copy link
Contributor

parkr commented Jan 12, 2016

@benbalter Is this ok to merge? I'll fix merge conflicts and merge if it looks good to you.

@benbalter
Copy link
Contributor

Is this ok to merge? I'll fix merge conflicts and merge if it looks good to you.

👍

* master: (28 commits)
  travis: use Ruby 2.1.7
  Upgrade to Ruby 2.1.7-github per https://pages.github.com/versions/
  💎 bump
  Memoize served_by_pages? == false
  Memoize dns = nil
  typo in comment
  💎 bump
  actually check that a domains dns resolves
  💎 bump
  add invalid_dns.rb to gemspec
  add timeout to DNS check
  add script/check
  💎 bump
  require net-dns 0.8
  add check for #26
  💎 bump
  properly detect if domain is served by pages for non-200 response codes
  💎 bump
  remove some diff noise
  use addressable::uri to support domains with underscores
  ...
parkr added a commit that referenced this pull request Jan 12, 2016
Use the existence of an NS record to determine whether a domain is an apex domain
@parkr parkr merged commit d7f72e4 into master Jan 12, 2016
@parkr parkr deleted the check-dns-for-apex-domains branch January 12, 2016 23:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants