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

Allow for local dns resolution with a custom dialer #121

Merged
merged 4 commits into from
Jul 11, 2023

Conversation

stephaniehingtgen
Copy link

@stephaniehingtgen stephaniehingtgen commented Jun 26, 2023

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.

@codecov-commenter
Copy link

codecov-commenter commented Jun 26, 2023

Codecov Report

Merging #121 (d376e9e) into main (dd3e503) will decrease coverage by 0.26%.
The diff coverage is 100.00%.

@@            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     
Impacted Files Coverage Δ
mssql.go 86.27% <ø> (ø)
protocol.go 94.05% <100.00%> (+0.44%) ⬆️

... and 2 files with indirect coverage changes

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 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

&& c.Dialer != nil {

might there be value in defining an interface to determine if the custom dialer handles DNS lookups? Do we know that all of them do?

Copy link
Author

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):
Screenshot 2023-06-27 at 1 25 46 PM

But if there is a use case for it, I'd be happy to implement this.

Copy link
Collaborator

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)

Copy link
Author

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

Copy link
Author

Choose a reason for hiding this comment

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

Added :)

protocol.go Outdated Show resolved Hide resolved
@shueybubbles
Copy link
Collaborator

thank you for submitting a PR!

@stephaniehingtgen
Copy link
Author

@microsoft-github-policy-service agree company="Grafana"

Copy link
Collaborator

@shueybubbles shueybubbles left a 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!

Copy link

@apoorvdeshmukh apoorvdeshmukh left a 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?

@stephaniehingtgen
Copy link
Author

@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?

@stephaniehingtgen
Copy link
Author

Hey! Just wanted to check if there is anything I need to do here to get this merged. Thanks!

@shueybubbles
Copy link
Collaborator

@apoorvdeshmukh it's waiting for you to approve then we can merge

Copy link

@apoorvdeshmukh apoorvdeshmukh left a 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!

@shueybubbles shueybubbles merged commit 45ecf99 into microsoft:main Jul 11, 2023
kodiakhq bot referenced this pull request in cloudquery/cloudquery Aug 22, 2023
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 [@&#8203;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 [@&#8203;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 [@&#8203;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 [@&#8203;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 [@&#8203;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 [@&#8203;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 [@&#8203;shueybubbles](https://github.com/shueybubbles) in [https://github.com/microsoft/go-mssqldb/pull/138](https://github.com/microsoft/go-mssqldb/pull/138)

#### New Contributors

-   [@&#8203;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)
-   [@&#8203;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)
-   [@&#8203;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)
-   [@&#8203;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 ([#&#8203;110](https://github.com/microsoft/go-mssqldb/issues/110))
-   Updated go package dependencies ([#&#8203;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==-->
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