Skip to content

SOLR-18048 Move authentication into a Servlet Filter#4120

Merged
gus-asf merged 6 commits intoapache:mainfrom
gus-asf:enhancement/SOLR-18048
Mar 17, 2026
Merged

SOLR-18048 Move authentication into a Servlet Filter#4120
gus-asf merged 6 commits intoapache:mainfrom
gus-asf:enhancement/SOLR-18048

Conversation

@gus-asf
Copy link
Copy Markdown
Contributor

@gus-asf gus-asf commented Feb 9, 2026

*
* @param eventType the audit event
*/
public boolean shouldAudit(AuditEvent.EventType eventType) {
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 don't see callers to what you added. We should be conservative in adding yet more methods to CoreContainer.

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.

Yeah I generally agree. There are more places it can be used, but I shied away from fully applying these methods since it seemed like scope creep. I wound up adding them because , but there was just a ton of duplicated logic always checking null and then checking the type and it all seems a bit like a Law of Demeter code smell with core container handing out it's object rather than just answering the question too, so I added these. However you are probably right that I need to finish the intention here or punt it. Otherwise it just becomes another half done thing hanging out in the code base, so next update will put this stuff to full use.... actually, broader use seems to lead to fewer methods anyway...

@dsmiley
Copy link
Copy Markdown
Contributor

dsmiley commented Feb 19, 2026

I'm looking forward to this :-)

@gus-asf
Copy link
Copy Markdown
Contributor Author

gus-asf commented Feb 19, 2026

Yeah will get back to it soon, other distractions at the moment :)

…voked, also fixed some minor filter name nonsense in web.xml
import static org.apache.solr.common.params.CollectionParams.CollectionAction.CREATE;
import static org.apache.solr.common.params.CollectionParams.CollectionAction.DELETE;
import static org.apache.solr.common.params.CollectionParams.CollectionAction.RELOAD;
import static org.apache.solr.servlet.HttpSolrCall.shouldAudit;
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.

good riddance to this import!

/* Private ctor prevents instantiation */
}

@SuppressWarnings("ClassCanBeRecord")
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.

why suppress this warning? It doesn't fail the build; does it? This seems like a suitable record.

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.

Once the check-mark in the IDE is yellow all manner of stuff gets ignored... converting it is off topic for this pr however.

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 understand the conversion is out of scope. But I don't think we should suppress a valid recommendation that we simply haven't prioritized addressing. I recommend simply accepting that your IDE/tools are going to recommend things you don't want to do now, if ever.

Comment on lines +46 to +48
* A servlet filter to handle authentication. Anything that needs to be served without
* authentication (such as UI) must be resolved and returned by a filter preceding this one,
* typically by forwarding to the default servlet. Also, any tracing, auditing and ratelimiting
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.

Anything that needs to be served without authentication (such as UI) must be resolved and returned by a filter preceding this one, typically by forwarding to the default servlet.

This statement is false; it presumes that the only way to do this is the way it's working now. I will show how to do so in a follow-on PR but have been waiting for this PR and others to land.

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.

At present this wraps everything. Obviously if something is not wrapped it will be unaffected (which would be better for stuff we never mean to authenticate in the first place). I'll qualify the statement.


// we want to prevent any attempts to close our request or response prematurely
chain.doFilter(closeShield(req), closeShield(res));
} catch (SolrException e) {
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.

good catch

Copy link
Copy Markdown
Contributor Author

@gus-asf gus-asf Mar 8, 2026

Choose a reason for hiding this comment

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

Turns out instantiating an AuditEvent parses parameters and that can throw a SolrException, which I don't like, but stopped myself from fixing. Luckily we have a test that sends bad data in the parameters and checks that it results in 400 not 500 :)

@gus-asf
Copy link
Copy Markdown
Contributor Author

gus-asf commented Mar 8, 2026

Plan to merge/backport next weekend, unless encouraged by 2 or more reviewers to merge sooner.

Copy link
Copy Markdown
Contributor

@dsmiley dsmiley left a comment

Choose a reason for hiding this comment

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

Please merge at your convenience

# Conflicts:
#	solr/core/src/java/org/apache/solr/security/AuthorizationUtils.java
@gus-asf gus-asf merged commit 2cd2e4e into apache:main Mar 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants