Skip to content
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

Don't resolve record directly #142

Open
ghost opened this issue May 3, 2024 · 3 comments
Open

Don't resolve record directly #142

ghost opened this issue May 3, 2024 · 3 comments

Comments

@ghost
Copy link

ghost commented May 3, 2024

Hello there,

I wanted to know is there any way with this library to prevent direct lookup results for de.example.com, europe.example.com, ... and only allow resolves for example.com ?

Thanks in advance.

@ghost
Copy link
Author

ghost commented May 3, 2024

@abh

I can add this code to the serve.go and it will resolve the issue, do you think this is the right way? Should I open pull request?

if len(labelMatches) == 1 {
  var countryCode, continentCode string
  
  if len(targets) == 3 {
	  countryCode, continentCode = targets[1], targets[2]
  } else if len(targets) == 2 {
	  if countries.CountryContinent[targets[1]] != "" {
		  countryCode = targets[1]
	  } else {
		  continentCode = targets[1]
	  }
  }
  
  cc := strings.SplitN(labelMatches[0].Label.Label, ".", 2)
  
  if len(cc) == 2 && (countries.CountryContinent[cc[1]] != "" || len(countries.ContinentCountries[cc[1]]) > 0) {
	  newTargets := targets
  
	  if cc[1] != countryCode && cc[1] != continentCode {
		  newTargets = append(newTargets, cc[1])
	  }
  
	  parentLabelMatches := z.FindLabels(cc[0], newTargets, []uint16{dns.TypeMF, dns.TypeCNAME, qtype})
  
	  if len(parentLabelMatches) > 1 {
		  // empty labelMatches
		  labelMatches = []zones.LabelMatch{}
	  }
  }
}

Also this must be added to imports on top:

"github.com/abh/geodns/v3/countries"

@abh
Copy link
Owner

abh commented May 4, 2024

Something like that could work with an option to enable the feature.

Though I think it'd make more sense to "hide" the targeting rules in some way in a separate part of the data structure (and then if the data comes that way then they can't be queried directly).

Many years ago @miekg suggested having the zone format be a regular "RFC 1035 zone" with extra metadata for the targeting information; that might be worth revisiting again.

@ghost
Copy link
Author

ghost commented May 4, 2024

@abh I have managed to code it somehow, but I don't know where to put for configuration or if its the right decision, take a look:

6047cb9

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

No branches or pull requests

1 participant