Apache Solr open-source search software
SOLR-16730: Exclude username, roles and permissions for inter-node requests to SystemInfoHandler (#1511)
Tomas Eduardo Fernandez Lobbec9e8fb89fe16
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txtindex 07d8e7bf1e9..a183e0d2694 100644--- a/solr/CHANGES.txt+++ b/solr/CHANGES.txt@@ -96,6 +96,9 @@ Bug Fixes* SOLR-16734: SOLR_DATA_HOME is only honored in verbode mode (Kevin Risden)+* SOLR-16730: Fix NPE in SystemInfoHandler for inter-node requests that would cause the Nodes page not to load.+ SystemInfoHandler no longer populates the username, roles and permissions in inter-node requests. (Tomás Fernández Löbbe)+Dependency Upgrades---------------------* PR#1494: Upgrade forbiddenapis to 3.5 (Uwe Schindler)diff --git a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.javaindex 327d5bbdade..e9c5061c7e1 100644--- a/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java+++ b/solr/core/src/java/org/apache/solr/handler/admin/SystemInfoHandler.java@@ -50,6 +50,7 @@ import org.apache.solr.response.SolrQueryResponse;import org.apache.solr.schema.IndexSchema;import org.apache.solr.security.AuthorizationContext;import org.apache.solr.security.AuthorizationPlugin;+import org.apache.solr.security.PKIAuthenticationPlugin;import org.apache.solr.security.RuleBasedAuthorizationPluginBase;import org.apache.solr.util.RTimer;import org.apache.solr.util.RedactionUtils;@@ -328,11 +329,10 @@ public class SystemInfoHandler extends RequestHandlerBase {}}- // User principal- String username = null;- if (req.getUserPrincipal() != null) {- username = req.getUserPrincipal().getName();- info.add("username", username);+ if (req.getUserPrincipal() != null+ && req.getUserPrincipal() != PKIAuthenticationPlugin.CLUSTER_MEMBER_NODE) {+ // User principal+ info.add("username", req.getUserPrincipal().getName());// Mapped roles for this principal@SuppressWarnings("resource")@@ -341,10 +341,14 @@ public class SystemInfoHandler extends RequestHandlerBase {RuleBasedAuthorizationPluginBase rbap = (RuleBasedAuthorizationPluginBase) auth;Set<String> roles = rbap.getUserRoles(req.getUserPrincipal());info.add("roles", roles);- info.add(- "permissions",- rbap.getPermissionNamesForRoles(- Stream.concat(roles.stream(), Stream.of("*", null)).collect(Collectors.toSet())));+ if (roles == null) {+ info.add("permissions", Set.of());+ } else {+ info.add(+ "permissions",+ rbap.getPermissionNamesForRoles(+ Stream.concat(roles.stream(), Stream.of("*", null)).collect(Collectors.toSet())));+ }}}diff --git a/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java b/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.javaindex a126bfaa3a6..6a005559f9b 100644--- a/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java+++ b/solr/core/src/java/org/apache/solr/security/PKIAuthenticationPlugin.java@@ -179,7 +179,9 @@ public class PKIAuthenticationPlugin extends AuthenticationPlugin}final Principal principal =- "$".equals(headerData.userName) ? SU : new BasicUserPrincipal(headerData.userName);+ "$".equals(headerData.userName)+ ? CLUSTER_MEMBER_NODE+ : new BasicUserPrincipal(headerData.userName);numAuthenticated.inc();filterChain.doFilter(wrapWithPrincipal(request, principal), response);@@ -402,7 +404,7 @@ public class PKIAuthenticationPlugin extends AuthenticationPlugin}public boolean needsAuthorization(HttpServletRequest req) {- return req.getUserPrincipal() != SU;+ return req.getUserPrincipal() != CLUSTER_MEMBER_NODE;}private class HttpHeaderClientInterceptor implements HttpRequestInterceptor {@@ -515,5 +517,5 @@ public class PKIAuthenticationPlugin extends AuthenticationPluginpublic static final String HEADER_V2 = "SolrAuthV2";public static final String NODE_IS_USER = "$";// special principal to denote the cluster member- private static final Principal SU = new BasicUserPrincipal("$");+ public static final Principal CLUSTER_MEMBER_NODE = new BasicUserPrincipal("$");}