Apache Solr open-source search software
SOLR-13472: Forwarded requests should skip authorization on receiving nodes
Ishan Chattopadhyaya7e0af71c1e4c
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 1bb48760bba..971e4e4c609 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -221,6 +221,8 @@ Bug Fixes* SOLR-13532: Fix http timeout and error logging bugs in RecoveryStrategy. (Suril Shah, hossman)+* SOLR-13472: Forwarded requests should skip authorization on receiving nodes (adfel, Ishan Chattopadhyaya)+Other Changes----------------------diff --git a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.javaindex 0ca46d00cd0..2ed00f4dd7a 100644--- a/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java+++ b/solr/core/src/java/org/apache/solr/servlet/HttpSolrCall.java@@ -464,6 +464,35 @@ public class HttpSolrCall {}}+ Action authorize() throws IOException {+ AuthorizationContext context = getAuthCtx();+ log.debug("AuthorizationContext : {}", context);+ AuthorizationResponse authResponse = cores.getAuthorizationPlugin().authorize(context);+ if (authResponse.statusCode == AuthorizationResponse.PROMPT.statusCode) {+ Map<String, String> headers = (Map) getReq().getAttribute(AuthenticationPlugin.class.getName());+ if (headers != null) {+ for (Map.Entry<String, String> e : headers.entrySet()) response.setHeader(e.getKey(), e.getValue());+ }+ log.debug("USER_REQUIRED "+req.getHeader("Authorization")+" "+ req.getUserPrincipal());+ if (shouldAudit(EventType.REJECTED)) {+ cores.getAuditLoggerPlugin().doAudit(new AuditEvent(EventType.REJECTED, req, context));+ }+ }+ if (!(authResponse.statusCode == HttpStatus.SC_ACCEPTED) && !(authResponse.statusCode == HttpStatus.SC_OK)) {+ log.info("USER_REQUIRED auth header {} context : {} ", req.getHeader("Authorization"), context);+ sendError(authResponse.statusCode,+ "Unauthorized request, Response code: " + authResponse.statusCode);+ if (shouldAudit(EventType.UNAUTHORIZED)) {+ cores.getAuditLoggerPlugin().doAudit(new AuditEvent(EventType.UNAUTHORIZED, req, context));+ }+ return RETURN;+ }+ if (shouldAudit(EventType.AUTHORIZED)) {+ cores.getAuditLoggerPlugin().doAudit(new AuditEvent(EventType.AUTHORIZED, req, context));+ }+ return null;+ }+/*** This method processes the request.*/@@ -491,36 +520,20 @@ public class HttpSolrCall {try {init();- /* Authorize the request if- 1. Authorization is enabled, and- 2. The requested resource is not a known static file- */- if (cores.getAuthorizationPlugin() != null && shouldAuthorize()) {- AuthorizationContext context = getAuthCtx();- log.debug("AuthorizationContext : {}", context);- AuthorizationResponse authResponse = cores.getAuthorizationPlugin().authorize(context);- if (authResponse.statusCode == AuthorizationResponse.PROMPT.statusCode) {- Map<String, String> headers = (Map) getReq().getAttribute(AuthenticationPlugin.class.getName());- if (headers != null) {- for (Map.Entry<String, String> e : headers.entrySet()) response.setHeader(e.getKey(), e.getValue());- }- log.debug("USER_REQUIRED "+req.getHeader("Authorization")+" "+ req.getUserPrincipal());- if (shouldAudit(EventType.REJECTED)) {- cores.getAuditLoggerPlugin().doAudit(new AuditEvent(EventType.REJECTED, req, context));- }- }- if (!(authResponse.statusCode == HttpStatus.SC_ACCEPTED) && !(authResponse.statusCode == HttpStatus.SC_OK)) {- log.info("USER_REQUIRED auth header {} context : {} ", req.getHeader("Authorization"), context);- sendError(authResponse.statusCode,- "Unauthorized request, Response code: " + authResponse.statusCode);- if (shouldAudit(EventType.UNAUTHORIZED)) {- cores.getAuditLoggerPlugin().doAudit(new AuditEvent(EventType.UNAUTHORIZED, req, context));- }- return RETURN;- }- if (shouldAudit(EventType.AUTHORIZED)) {- cores.getAuditLoggerPlugin().doAudit(new AuditEvent(EventType.AUTHORIZED, req, context));- }++ // Perform authorization here, if:+ // (a) Authorization is enabled, and+ // (b) The requested resource is not a known static file+ // (c) And this request should be handled by this node (see NOTE below)+ // NOTE: If the query is to be handled by another node, then let that node do the authorization.+ // In case of authentication using BasicAuthPlugin, for example, the internode request+ // is secured using PKI authentication and the internode request here will contain the+ // original user principal as a payload/header, using which the receiving node should be+ // able to perform the authorization.+ if (cores.getAuthorizationPlugin() != null && shouldAuthorize()+ && !(action == REMOTEQUERY || action == FORWARD)) {+ Action authorizationAction = authorize();+ if (authorizationAction != null) return authorizationAction;}HttpServletResponse resp = response;