-
Notifications
You must be signed in to change notification settings - Fork 67
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
Allow for local dns resolution with a custom dialer #121
Conversation
Codecov Report
@@ Coverage Diff @@
## main #121 +/- ##
==========================================
- Coverage 74.11% 73.86% -0.26%
==========================================
Files 29 29
Lines 5613 5620 +7
==========================================
- Hits 4160 4151 -9
- Misses 1206 1216 +10
- Partials 247 253 +6
|
protocol.go
Outdated
@@ -51,6 +51,14 @@ func (t tcpDialer) DialSqlConnection(ctx context.Context, c *Connector, p *msdsn | |||
var ips []net.IP | |||
ip := net.ParseIP(p.Host) | |||
if ip == nil { | |||
// if the dialer has been updated, the dialer may be proxying to a different network, and so the | |||
// dialer should be used to connect so the DNS is resolved within the right network | |||
if c != nil && c.Dialer != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My initial thought is that if the custom dialer sends the final request to a different network, that they would want to use the DNS lookup where the actual requests will later be sent to.
For example, if the driver is being run in a k8s namespace that has a MSSQL instance with the local DNS of mssql
, but we want to proxy the request to a separate MSSQL instance in another cluster with the local DNS of mssql2
, we'd want the DNS resolution to happen on the other k8s cluster, otherwise we may get false positives that the DNS is correct if we are using mssql
, when it won't work (Or vice versa if the DNS is switched):
But if there is a use case for it, I'd be happy to implement this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we're in disagreement about the end result. I'm asking if there are multiple types of custom dialers - some that proxy to other networks and some that rely on the current DNS lookup and if we'd need to distinguish between the two. EG, your dialer is clearly of the former. Anyone using the existing model, though, is getting the DNS lookup "for free" and we risk breaking them.
Maybe a better name for Dialer
would have been IPDialer
since the driver has always called it with an IP address up to now.
Your dialer could be HostDialer
which takes a host name.
eg
h, ok := c.Dialer.(HostDialer)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good! I'll work on implementing the second HostDialer
interface
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added :)
thank you for submitting a PR! |
@microsoft-github-policy-service agree company="Grafana" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the README and the CHANGELOG. Once I get a second approver we will merge.
thx!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stephaniehingtgen Can you look into the test failure?
@shueybubbles updated the README & Changelog! Thanks for the review! @apoorvdeshmukh I updated the unit test, but I'm unable to kick off running the tests. Would you be able to kick it off for me? |
Hey! Just wanted to check if there is anything I need to do here to get this merged. Thanks! |
@apoorvdeshmukh it's waiting for you to approve then we can merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks for the fix!
This PR contains the following updates: | Package | Type | Update | Change | |---|---|---|---| | [github.com/microsoft/go-mssqldb](https://github.com/microsoft/go-mssqldb) | require | major | `v0.19.0` -> `v1.5.0` | --- ### ⚠ Dependency Lookup Warnings ⚠ Warnings were logged while processing this repo. Please check the Dependency Dashboard for more information. --- ### Release Notes <details> <summary>microsoft/go-mssqldb (github.com/microsoft/go-mssqldb)</summary> ### [`v1.5.0`](https://github.com/microsoft/go-mssqldb/releases/tag/v1.5.0) [Compare Source](https://github.com/microsoft/go-mssqldb/compare/v1.4.0...v1.5.0) #### What's Changed - go mod vendor npipe to this repo by [@​shueybubbles](https://github.com/shueybubbles) in [https://github.com/microsoft/go-mssqldb/pull/118](https://github.com/microsoft/go-mssqldb/pull/118) - Enable dependabot for pkg updates by [@​apoorvdeshmukh](https://github.com/apoorvdeshmukh) in [https://github.com/microsoft/go-mssqldb/pull/119](https://github.com/microsoft/go-mssqldb/pull/119) - fix: mips and mipsel builds by [@​powersj](https://github.com/powersj) in [https://github.com/microsoft/go-mssqldb/pull/124](https://github.com/microsoft/go-mssqldb/pull/124) - Allow for local dns resolution with a custom dialer by [@​stephaniehingtgen](https://github.com/stephaniehingtgen) in [https://github.com/microsoft/go-mssqldb/pull/121](https://github.com/microsoft/go-mssqldb/pull/121) - Fixes MarshalText and adds UnmarshalJSON interface for UniqueIdentifier by [@​Musab-Nazir](https://github.com/Musab-Nazir) in [https://github.com/microsoft/go-mssqldb/pull/126](https://github.com/microsoft/go-mssqldb/pull/126) - Update README.md by [@​dlevy-msft](https://github.com/dlevy-msft) in [https://github.com/microsoft/go-mssqldb/pull/132](https://github.com/microsoft/go-mssqldb/pull/132) - Fix: Handle extended chars in SQL instance names by [@​shueybubbles](https://github.com/shueybubbles) in [https://github.com/microsoft/go-mssqldb/pull/138](https://github.com/microsoft/go-mssqldb/pull/138) #### New Contributors - [@​powersj](https://github.com/powersj) made their first contribution in [https://github.com/microsoft/go-mssqldb/pull/124](https://github.com/microsoft/go-mssqldb/pull/124) - [@​stephaniehingtgen](https://github.com/stephaniehingtgen) made their first contribution in [https://github.com/microsoft/go-mssqldb/pull/121](https://github.com/microsoft/go-mssqldb/pull/121) - [@​Musab-Nazir](https://github.com/Musab-Nazir) made their first contribution in [https://github.com/microsoft/go-mssqldb/pull/126](https://github.com/microsoft/go-mssqldb/pull/126) - [@​dlevy-msft](https://github.com/dlevy-msft) made their first contribution in [https://github.com/microsoft/go-mssqldb/pull/132](https://github.com/microsoft/go-mssqldb/pull/132) **Full Changelog**: microsoft/go-mssqldb@v1.1.0...v1.5.0 ### [`v1.4.0`](https://github.com/microsoft/go-mssqldb/compare/v1.3.0...v1.4.0) [Compare Source](https://github.com/microsoft/go-mssqldb/compare/v1.3.0...v1.4.0) ### [`v1.3.0`](https://github.com/microsoft/go-mssqldb/compare/v1.2.0...v1.3.0) [Compare Source](https://github.com/microsoft/go-mssqldb/compare/v1.2.0...v1.3.0) ### [`v1.2.0`](https://github.com/microsoft/go-mssqldb/compare/v1.1.0...v1.2.0) [Compare Source](https://github.com/microsoft/go-mssqldb/compare/v1.1.0...v1.2.0) ### [`v1.1.0`](https://github.com/microsoft/go-mssqldb/releases/tag/v1.1.0) [Compare Source](https://github.com/microsoft/go-mssqldb/compare/v1.0.0...v1.1.0) ### Version 1.1.0 - Release date: May 30, 2023 #### What's new in 1.1.0 - Supports finding the DAC port using the browser service ([#​110](https://github.com/microsoft/go-mssqldb/issues/110)) - Updated go package dependencies ([#​112](https://github.com/microsoft/go-mssqldb/issues/112)) ### [`v1.0.0`](https://github.com/microsoft/go-mssqldb/compare/v0.21.0...v1.0.0) [Compare Source](https://github.com/microsoft/go-mssqldb/compare/v0.21.0...v1.0.0) ### [`v0.21.0`](https://github.com/microsoft/go-mssqldb/compare/v0.20.0...v0.21.0) [Compare Source](https://github.com/microsoft/go-mssqldb/compare/v0.20.0...v0.21.0) ### [`v0.20.0`](https://github.com/microsoft/go-mssqldb/compare/v0.19.0...v0.20.0) [Compare Source](https://github.com/microsoft/go-mssqldb/compare/v0.19.0...v0.20.0) </details> --- ### Configuration 📅 **Schedule**: Branch creation - "before 4am on the first day of the month" (UTC), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41NC4yIiwidXBkYXRlZEluVmVyIjoiMzYuNTQuMiIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->
If the custom dialer updates the transport to proxy the mssql connection, and only the proxy can reach the network that mssql is running in, then any local DNS resolution will fail.
To address this, this PR ensures the custom dialer is used, if defined, to resolve the DNS.
We've been using this logic on Grafana's forked repo for the past few months.