-
Notifications
You must be signed in to change notification settings - Fork 760
Managed implementation of DNS resolver #6104
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
Conversation
32d94c5 to
40f8f9b
Compare
BrennanConroy
left a comment
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.
Only reviewed a subset of files. It's a large PR and has a lot of RFC reading attached to it. Will review more later.
src/Microsoft.Extensions.ServiceDiscovery.Dns/DnsServiceEndpointProvider.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Extensions.ServiceDiscovery.Dns/DnsServiceEndpointProviderBase.Log.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Extensions.ServiceDiscovery.Dns/DnsSrvServiceEndpointProvider.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Extensions.ServiceDiscovery.Dns/DnsSrvServiceEndpointProvider.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Extensions.ServiceDiscovery.Dns/Resolver/DnsDataReader.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Extensions.ServiceDiscovery.Dns/Resolver/DnsPrimitives.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Extensions.ServiceDiscovery.Dns/Resolver/DnsPrimitives.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Extensions.ServiceDiscovery.Dns/Resolver/DnsPrimitives.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Extensions.ServiceDiscovery.Dns/Resolver/DnsPrimitives.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Extensions.ServiceDiscovery.Dns/Resolver/DnsPrimitives.cs
Outdated
Show resolved
Hide resolved
|
|
||
| } | ||
|
|
||
| internal static bool TryReadQName(ReadOnlySpan<byte> messageBuffer, int offset, [NotNullWhen(true)] out string? name, out int bytesRead) |
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.
messageBuffer doesn't have any endianness normalization when it's passed in. Is that problematic?
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.
The only multibyte information is the offset in pointers and we read higher and lower byte separately and combine them correctly. Otherwise we only ever read individual bytes or (ascii) strings, so endianness should not matter.
src/Microsoft.Extensions.ServiceDiscovery.Dns/Resolver/NetworkInfo.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Extensions.ServiceDiscovery.Dns/Resolver/ResolvConf.cs
Outdated
Show resolved
Hide resolved
src/Microsoft.Extensions.ServiceDiscovery.Dns/Resolver/ResolvConf.cs
Outdated
Show resolved
Hide resolved
|
|
||
| if (responseLength > buffer.Length) | ||
| { | ||
| var largerBuffer = ArrayPool<byte>.Shared.Rent(responseLength); |
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.
This is kind of dangerous, user controlled pre-allocation. Since we're limited to 65k here you could argue it's not too risky, but we should probably explicitly call it out in a comment and make sure we're okay with the risk.
Technically the array pool (ConfigurableArrayPool) could return a 65 * 2 * 2 (or more) buffer since the implementation is free to search multiple bucket sizes to find a pooled byte[].
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 am curious, if we were to decide it's too risky, what would you suggest as a mitigation? We need the entire message in memory for parsing purposes (domain name compression via pointers with offsets), so I don't see us reading the contents of the message from a stream.
tests/Microsoft.Extensions.ServiceDiscovery.Dns.Tests/Resolver/ResolvConfTests.cs
Show resolved
Hide resolved
|
@rzikm could you set expectations on this one ? |
in parallel to this, I am also finishing Threat Model Review and will need to setup fuzzing. If there are no major distractions I hope to finish the work this month. |
|
@rzikm appreciate your work on this but we don;t have any plans to go this direction in the short term. I'll close the PR but feel free to continue evolving this. |
|
Reopening as I forgot we do want this change as a replacement for the DNS client in the service discovery package! |
|
Thank you @davidfowl. I had just started to write a comment with issues that I've encountered with current DNS client hoping in a hand on heart for this pull! |
|
CI is green, I expect to merge this within a week once I confirm there are no outstanding action items from Threat Model perspective. |
|
Last open items on threat Model Review discussions have been closed, good to merge this after I merge latest main |
|
@rzikm need you on standby in case something breaks 😄. This code has not changed in a LONG time and we just made this massive change in a minor update with no fallback. I think we should put back the old implementation and have it be possible to opt in. |
|
@davidfowl not that I expect stuff to break, but I expect to be on standby in case something does break. as for opt-in vs opt-out, we can easily toggle between Managed and System.Net.Dns for A/AAAA records. For SRV records, we would have to put back the DnsClient dependency. Let me know which variation of this (and the opt-in/out mechanism) you prefer and I can put up a follow-up PR. |
|
Add the DnsClient implementation back and we will keep it behind a feature flag for 1 or 2 minor versions then delete it later. |
|
I can try it and leave a feedback maybe tomorrow. We already used the previous version with a lot of issues for missing resolution in kubernetes with gRPC headless services. |
speaking of kubernetes, I noticed #9913 during local testing, I am very curious if it is really a me-problem or if something can be done to increase the pit of success for aspir8 users. |
|
We don't use aspir8 to generate manifest and the url used for service discovery is composed with named port and service name during setup so I can't test it. |
Hi @davidfowl, @Dona278 and @rzikm If there are technical reasons and issues I would really like to know for selfish reasons, to improve my library ofc! If there are other motivations, that's fine, I don't really care much if you use my library or not. I actually remember having some discussion with one of your team mates from Prague last year, that was more regarding your plans to add a configurable DNS resolver to the .NET framework I think. Anyways, if there is something I can do to help, let me know. Regarding
Digging a bit on google about issues with CoreDNS (the DNS system used by kubernetes) I found a bunch of reasons why you might get those kind of errors. Maybe we just need some retry logic here in the app specific code to account for service changes? After all, this is a distributed system which might have some latency. Maybe the resolver uses the wrong DNS server because of some bad system configuration? That being said, I do not have much experience with kubernetes because I'm not using it at work, so what do I know ;) Thanks |
Description
This PR brings in a C# implementation of a DNS resolver that is able to signal the TTL information together with the query results.
Main features
Checklist
<remarks />and<code />elements on your triple slash comments?Microsoft Reviewers: Open in CodeFlow