Skip to content

SOLR-18537: Proxy requests to a node via X-Solr-targetNode - #5112

Merged
dsmiley merged 13 commits into
apache:mainfrom
dsmiley:SOLR-18537-proxyRequestsByHeader
Nov 2, 2026
Merged

dsmiley merged 13 commits into
apache:mainfrom
dsmiley:SOLR-18537-proxyRequestsByHeader

Conversation

@dsmiley

@dsmiley dsmiley commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

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

It can be very useful for Solr to proxy requests to another node, specified in a header or param. The intended scenario is when there's an HTTP proxy in front of Solr, and the backing Solr nodes aren't directly reachable. Solr is doing that now for a few admin endpoints that have already been coded for it, using GenericV1RequestProxy internally (e.g. for logging, info, ...). The issue here instead proposes a generic mechanism that doesn't require Solr handlers to be coded any differently.

Header or param.
Useful to reach a specific node.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@dsmiley

dsmiley commented Oct 12, 2026

Copy link
Copy Markdown
Contributor Author

FYI I've been using this for awhile at work.
Marking as Draft because needs a test and documentation.

Are there security concerns here? I don't think so. This is live-nodes only.

code: use Solr's URL param parsing
@github-actions github-actions Bot added documentation Improvements or additions to documentation test-framework tests labels Oct 20, 2026
@dsmiley
dsmiley marked this pull request as ready for review October 20, 2026 20:42
@janhoy
janhoy requested a balanced review from Copilot October 21, 2026 08:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@janhoy janhoy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 janhoy left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some manual review comments as I'm out of copilot credit...

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Caller identity preservation and request-routing correctness need correction before approval.

5 open issues

Review effort: Balanced

Comment on lines +99 to +101
HttpClient httpClient =
((HttpJettySolrClient) cores.getDefaultHttpSolrClient()).getHttpClient();
HttpSolrProxy.doHttpProxy(httpClient, req, resp, url);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm investigating this separately.

dsmiley and others added 9 commits October 21, 2026 19:43
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>
@dsmiley

dsmiley commented Oct 22, 2026

Copy link
Copy Markdown
Contributor Author

It's really remarkable how much this PR has improved/evolved as a result of such peer-review/scrutiny.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

technically, this aspect is a small bug fix to possible encoding issue in the path. That's very unlikely to happen in practice IMO.

Comment on lines +74 to +90
// 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);
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment on lines +91 to +92
// wrap the request to filter out the header & param.
// NOTE: we assume downstream processing only accesses such data via what we override !!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@nick-boss-tech

Copy link
Copy Markdown
Contributor

AI Review:
P2, new: A GET query such as ?foo=X-Solr-targetNode causes the filter to overwrite a valid targeting header with null. The request then runs on the receiving node instead of the selected node. Preserve the header unless the actual targeting parameter exists. Code
P3: The guide promises 404 for unknown nodes; the agreed implementation and tests use 400.
Existing concern: Certificate-based caller identity remains unresolved. The new Basic Auth tests do not close that already-raised issue.

@dsmiley

dsmiley commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

P2, new: A GET query such as ?foo=X-Solr-targetNode causes the filter to overwrite a valid targeting header with null.
@nick-boss-tech can you elaborate; I don't understand.

@nick-boss-tech

Copy link
Copy Markdown
Contributor

🤖 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_solr

The substring check sees X-Solr-targetNode inside foo's value, so it parses the query. But params.get(TARGET_NODE_HEADER) returns null: the only parameter is foo. Assigning that null to targetNode discards the header, and /admin/info/system runs on A instead of B.

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 fix

Tested at 46bc7e428b5b, seed 5112C0DE:

  • NodeTargetProxyFilterTest and NodeTargetProxyFilterAuthTest: 18 passed, no failures, errors or skips.
  • HttpSolrProxyTest and SolrRequestParserTest: 11 passed, no failures, errors or skips.
  • Both new header-loss regressions fail on your original production code with the new test file: they expect the selected node but receive the original node. These cover the header name appearing in an unrelated query value and in a longer parameter name. The other two new tests, for no-header handling and header/query conflict, passed with the fix; they were not run against the original code.
  • tidy leaves a clean tree. check -x test passed with NODE_ENV unset after reinstalling the Antora tabs dependency. Two earlier attempts failed because NODE_ENV=production caused npm to omit that devDependency.

Verification details.

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 46bc7e428b5be519a497ecf65dcd0256b65fa84c

You're welcome to take the commits or adapt the changes.

@dsmiley

dsmiley commented Oct 27, 2026

Copy link
Copy Markdown
Contributor Author

Much appreciated Nick!

@dsmiley

dsmiley commented Oct 29, 2026

Copy link
Copy Markdown
Contributor Author

will merge tomorrow

@dsmiley
dsmiley merged commit 439b2e5 into apache:main Nov 2, 2026
5 checks passed
@dsmiley
dsmiley deleted the SOLR-18537-proxyRequestsByHeader branch November 2, 2026 18:42
@dsmiley dsmiley added this to the 10.x milestone Nov 3, 2026
dsmiley added a commit that referenced this pull request Nov 3, 2026
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants