fix: Don't try to use system resolv.conf when other servers are configured #2460
No reviewers
Labels
No labels
Abandoned
Blocked
Bug
Changelog
Added
Changelog
Missing
Changelog
None
Cherry-picking
Compliance
Database
Dependencies
Dependencies/Renovate
Difficulty
Easy
Difficulty
Hard
Difficulty
Medium
Documentation
Enhancement
Good first issue
Help wanted
Inherited
Matrix/Administration
Matrix/Appservices
Matrix/Auth
Matrix/Client
Matrix/Core
Matrix/E2EE
Matrix/Federation
Matrix/Hydra
Matrix/MSC
Matrix/Media
Matrix/T&S
Merge
Merge/Manual
Merge/Squash
Meta
Meta/CI
Meta/Packaging
Priority
Blocking
Priority
High
Priority
Low
Security
Status
Confirmed
Status
Duplicate
Status
Invalid
Status
Needs Investigation
Support
bob the builder
No milestone
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
continuwuation/continuwuity!2460
Loading…
Reference in a new issue
No description provided.
Delete branch "silversys/continuwuity:silversys/fix-dns-resolution-errors"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Previously, only HTTP clients targeting matrix servers (and using the
resolution spec) would use the DNS servers configured in the c10y config.
This happened because reqwest requires any DNS resolvers passed in to
implement reqwest::dns::Resolve, which only the matrix resolver did,
and no other HTTP client had a proper DNS resolver (which used the
configured DNS servers) passed into it.
To fix this we make a custom resolution struct based on reqwest's
reqwest::dns::HickoryDnsResolver, which implements Request with no
other modifications to the DNS response. HickoryDnsResolver itself isn't
exported, which is why we re-created it instead of using it directly.
no im not an LLM i just wrote this to remember my own changes later on
Fixes: #2441
Pull request checklist:
mainbranch, and the branch is named something other thanmain.myself, if applicable. This includes ensuring code compiles.
4d69ceeceb809585cc96809585cc96588cdc14d0fix: Don't try to use system resolv.conf when other servers are configuredto WIP: fix: Don't try to use system resolv.conf when other servers are configuredWIP until tested
@ -314,3 +339,3 @@.map_err(|e| err!(error!("Failed to configure DNS resolver from system: {e}")))?;let mut conf = hickory_resolver::config::ResolverConfig::default();let mut conf = ResolverConfig::from_name_servers(vec![]);Note to reviewers here: I replaced

::default()with::from_name_servers(...)as theDefaultimplementation is going to be removed:we need also to add it in oidc/mod.rs:165 as we don't pass any dns stuff
@ -983,7 +983,7 @@ impl crate::Context<'_> {let resolver: &MatrixResolver = if no_cache {Passing matrix_http_client fixes .well-known fetching only. Without .dns_resolver(...), MatrixResolverBuilder creates a system resolver for SRV lookups. Pass the configured resolver here too.
@ -130,3 +151,2 @@appservice: base(config)?.dns_resolver(matrix_dns_resolver)appservice: base(config, matrix_dns_resolver)?this should be reqwest_dns_resolver as per the MSC
21be870bd33445d54a193445d54a195e82a4eab25e82a4eab2c4e4376bdfWIP: fix: Don't try to use system resolv.conf when other servers are configuredto fix: Don't try to use system resolv.conf when other servers are configuredc4e4376bdf1ffb3da4d1I don't use alternative DNS servers, but the standard path still works for me. no new explosions.
WOMM!!
No requests were sent to the
/etc/resolv.confnameservers. I don't have appservices yet but this is great1ffb3da4d1f626232448@ -0,0 +1 @@Ensure HTTP clients actually follow the `dns_servers` config option. Contributed by @silversys.bugfix.md@ -0,0 +38,4 @@Box::pin(async move {let lookup = resolver.lookup_ip(name.as_str()).await?;let addrs: Addrs = Box::new(SocketAddrs {iter: lookup.iter().collect::<Vec<_>>().into_iter(),This
collectis creating an unnecessary allocation, it's already an iterator?Possibly, I just copied reqwest's original HickoryDnsResolver without modifying it. I believe we so something similar in resolvematrix, but I'd have to confirm thah
i believe this is done because lookup is of type LookupIp, whereas the resolver wants Addrs (Box of SocketAddrs (struct of IntoIter)), and this conversion is done to get LookupIp into IntoIter. There might be a more efficient way to solve it, but i havent looked too far into it
here's how resolvematrix does the same:
Ok(Box::new(addrs.into_iter()) as Box<dyn Iterator<Item = SocketAddr> + Send>)yeah no i tried a few alternatives (including one based on resolvematrix' solution), but i couldnt find something that works. i might just be stupid (and/or bad at rust), but i think the existing solution (copied from HickoryDnsResolver) is the cleanest
Fair enough.
@ -21,3 +26,3 @@pub dns_resolver: Arc<TokioResolver>,pub dns: reqwest::Client,/// Tokio system resolver wrappedIsn't this wrapping the resolver which can prefer the configured resolvers?
wdym?
Basically the comment is wrong, it's also wrapping the resolvers configured in the config. Small nit anyway
@ -24,0 +31,4 @@/// Matrix server resolver according to server resolution specpub matrix_resolver: Arc<MatrixResolver>,/// HTTP client following matrix server resolution spec for requestsHTTP client used for fetching files during server resolution
@ -231,3 +253,1 @@.pool_max_idle_per_host(config.request_idle_per_host.into()).user_agent(conduwuit::user_agent()).redirect(redirect::Policy::limited(6)).hickory_dns(true)this gets overridden by the resolver, right?
no, iirc if you set
.dns_resolver(...)without.hickory_dns(...)then.dns_resolver(...)gets ignored. can double check if it's necessaryno yeah youre right, dns_resolver ignores hickory_dns. ill remove hickory_dns(true), we might be able to remove the hickory-dns feature entirely too then (since we pass in a custom resolver every time anyways)
i was correct, removing the hickory-dns feature from reqwest works perfectly and breaks nothing
f62623244833bf87ec6633bf87ec6645cd5f91b8