Repository navigation
SOLR-18537: Proxy requests to a node via X-Solr-targetNode - #5112
Conversation
Header or param. Useful to reach a specific node. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
|
FYI I've been using this for awhile at work. Are there security concerns here? I don't think so. This is live-nodes only. |
code: use Solr's URL param parsing
janhoy
left a comment
There was a problem hiding this comment.
I delegate review to Copilot who is probably better at servlet spec than me. I do like the general solution and I believe the security aspect is handled so so far a LGTM from me from 10.000 ft
janhoy
left a comment
There was a problem hiding this comment.
Some manual review comments as I'm out of copilot credit...
There was a problem hiding this comment.
🟡 Changes recommended
Caller identity preservation and request-routing correctness need correction before approval.
5 open issues
Proxy authentication uses node identity instead of caller identity · New Authentication filter masks proxy errors and response statuses · New Routing directive causes proxy loops on non-replica nodes · New Decoded request paths corrupt upstream URL encoding · New Dotless live-node names are incorrectly expanded · New
Review effort: Balanced
| HttpClient httpClient = | ||
| ((HttpJettySolrClient) cores.getDefaultHttpSolrClient()).getHttpClient(); | ||
| HttpSolrProxy.doHttpProxy(httpClient, req, resp, url); |
There was a problem hiding this comment.
I'm investigating this separately.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…uting loops Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…icationFilter Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… caller Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
It's really remarkable how much this PR has improved/evolved as a result of such peer-review/scrutiny. |
There was a problem hiding this comment.
technically, this aspect is a small bug fix to possible encoding issue in the path. That's very unlikely to happen in practice IMO.
| // also accept it as a query param on GET requests, for convenience when a header can't | ||
| // easily be set (e.g. a browser address bar) | ||
| String queryString = req.getQueryString(); | ||
| if ("GET".equals(req.getMethod()) | ||
| && queryString != null | ||
| && queryString.contains(TARGET_NODE_HEADER)) { // cheap; avoid double-parse | ||
| SolrParams params = SolrRequestParsers.parseQueryString(queryString); | ||
| if (targetNode != null && params.get(TARGET_NODE_HEADER) != null) { | ||
| res.sendError(400, TARGET_NODE_HEADER + " must EITHER be a header or url param"); | ||
| return; | ||
| } | ||
| targetNode = params.get(TARGET_NODE_HEADER); | ||
| if (targetNode != null) { | ||
| queryString = filterQueryString(params); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
there is non-trivial complexity to support the query string option, particularly for removal. It's a sunk costs as this point -- it works, tested, etc. The motivation is to make this easy for a user with their browser.
| // wrap the request to filter out the header & param. | ||
| // NOTE: we assume downstream processing only accesses such data via what we override !! |
There was a problem hiding this comment.
an alternative would be to enhance HttpSolrProxy to directly do this. The header part would trivially be one line in hop-by-hop headers with a comment justification. I don't love the coupling but it's in the same package.
|
AI Review: |
|
|
🤖 AI text below 🤖 (reviewed by Nick Shanin) @dsmiley, the example has no targeting query parameter. Suppose this request reaches node A, with the header naming live node B: GET /solr/admin/info/system?foo=X-Solr-targetNode HTTP/1.1
X-Solr-targetNode: node-B.example.com:8983_solrThe substring check sees I prepared a fix and regression tests on top of your current head. The fix only replaces the header target when the actual targeting parameter exists. Supplying both still returns 400. The diff also corrects the guide's 404 to the agreed 400 and clarifies the hostname shorthand rule. Linux verification: 29 tests passed; both routing regressions fail before the fixTested at
To take the fix and its Javadoc formatting follow-up: git switch SOLR-18537-proxyRequestsByHeader
git fetch https://github.com/nick-boss-tech/solr.git solr-18537-submit
git merge --ff-only 46bc7e428b5be519a497ecf65dcd0256b65fa84cYou're welcome to take the commits or adapt the changes. |
|
Much appreciated Nick! |
|
will merge tomorrow |
Any request can now be routed to a specific SolrCloud node by setting the `X-Solr-targetNode` header (or, for GET requests, a query parameter of the same name). The receiving node proxies the request there. This is useful for reaching a particular node behind a load balancer, including for node-level admin APIs. Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: Nick Shanin <nick.boss.us@gmail.com> (cherry picked from commit 439b2e5)


https://issues.apache.org/jira/browse/SOLR-18537