network: fixes to public address support#5851
Merged
algorandskiy merged 6 commits intoalgorand:masterfrom Dec 7, 2023
Merged
Conversation
algorandskiy
commented
Dec 2, 2023
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #5851 +/- ##
==========================================
- Coverage 55.95% 55.92% -0.03%
==========================================
Files 477 477
Lines 67346 67355 +9
==========================================
- Hits 37683 37671 -12
- Misses 27117 27131 +14
- Partials 2546 2553 +7 ☔ View full report in Codecov by Sentry. |
1. requestTracker changes: - Remove http.Request.RemoteAddr overwriting in request tracker - Remove http.Request from request tracker - Add a new remoteAddresss() method that returns a most suitable address 2. public addr changes: - no otherPublicAddr outside of requestTracker - new remoteAddresss() method provides most meaningful address for incoming requests Rationale: There is a chain http.Handler's in wsNetwork: request tracker and wsNetwork itself. Tracked request is created/updated in the first ServeHTTP and used to save a pointer to http.Request object. This request object is actually gets copied in mux.ServeHTTP that calls downstream wsNetwork's ServeHTTP making the request non-usable in the main wsNetwork's ServeHTTP so removed. otherPublicAddr is an address reported by a peer via our custom X-Algorand-Location header that the only correct value for wsPeer.rootURL (host:port accepting connections) but cannot be trusted. Unconditionally rewriting it with remoteAddr obtained from a tcp connection is too much and a new remoteAddresss() method attempts to provide the most meaningful trusted value. Fixes algorand#5713
8c3a37f to
6e2a2fe
Compare
gmalouf
reviewed
Dec 6, 2023
gmalouf
reviewed
Dec 6, 2023
gmalouf
reviewed
Dec 6, 2023
gmalouf
reviewed
Dec 6, 2023
gmalouf
reviewed
Dec 6, 2023
gmalouf
reviewed
Dec 6, 2023
algorandskiy
commented
Dec 6, 2023
algorandskiy
commented
Dec 6, 2023
Co-authored-by: Gary <982483+gmalouf@users.noreply.github.com>
gmalouf
reviewed
Dec 6, 2023
gmalouf
reviewed
Dec 6, 2023
jasonpaulos
previously approved these changes
Dec 7, 2023
Contributor
jasonpaulos
left a comment
There was a problem hiding this comment.
This seems better. Just putting in some minor corrections
Co-authored-by: Jason Paulos <jasonpaulos@users.noreply.github.com>
jasonpaulos
approved these changes
Dec 7, 2023
gmalouf
approved these changes
Dec 7, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
http.Request.RemoteAddroverwriting in request trackerhttp.Requestfrom request trackerremoteAddresss()method that returns a most suitable addressotherPublicAddroutside of requestTrackerremoteAddresss()method provides most meaningful address for incoming requestsRationale:
There is a chain http.Handler's in wsNetwork: request tracker and wsNetwork itself.
Tracked request is created/updated in the first
ServeHTTPand used to save a pointer tohttp.Requestobject.This request object is actually gets copied in
mux.ServeHTTPthat calls downstream wsNetwork'sServeHTTPmakingthe request non-usable in the main wsNetwork's ServeHTTP so removed.
otherPublicAddris an address reported by a peer via our customX-Algorand-Locationheader that the onlycorrect value for wsPeer.rootURL (host:port accepting connections) but cannot be trusted.
Unconditionally rewriting it with remoteAddr obtained from a tcp connection is too much and a new
remoteAddresss()method attempts to provide the most meaningful trusted value.Fixes #5713
Test Plan
TestPeeringtests since they relied on a buggyotherPublicAddroverwriting byremoteAddr.