github-advanced-security[bot] commented on code in PR #19011:
URL: https://github.com/apache/druid/pull/19011#discussion_r2880245177


##########
server/src/main/java/org/apache/druid/server/http/CoordinatorBrokerConfigsResource.java:
##########
@@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.server.http;
+
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.google.inject.Inject;
+import com.sun.jersey.spi.container.ResourceFilters;
+import org.apache.druid.audit.AuditManager;
+import org.apache.druid.client.broker.BrokerClient;
+import org.apache.druid.client.broker.BrokerClientImpl;
+import org.apache.druid.common.config.JacksonConfigManager;
+import org.apache.druid.discovery.DiscoveryDruidNode;
+import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
+import org.apache.druid.discovery.NodeRole;
+import org.apache.druid.guice.annotations.EscalatedGlobal;
+import org.apache.druid.guice.annotations.Json;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.rpc.FixedServiceLocator;
+import org.apache.druid.rpc.ServiceClientFactory;
+import org.apache.druid.rpc.ServiceLocation;
+import org.apache.druid.rpc.StandardRetryPolicy;
+import org.apache.druid.server.DruidNode;
+import org.apache.druid.server.broker.BrokerDynamicConfig;
+import org.apache.druid.server.http.security.ConfigResourceFilter;
+import org.apache.druid.server.security.AuthorizationUtils;
+
+import javax.annotation.Nullable;
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.Consumes;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.Collection;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicReference;
+
+@Path("/druid/coordinator/v1/broker/config")
+@ResourceFilters(ConfigResourceFilter.class)
+public class CoordinatorBrokerConfigsResource
+{
+  private static final Logger log = new 
Logger(CoordinatorBrokerConfigsResource.class);
+
+  private final JacksonConfigManager configManager;
+  private final AuditManager auditManager;
+  private final AtomicReference<BrokerDynamicConfig> currentConfig;
+  private final ServiceClientFactory clientFactory;
+  private final ObjectMapper jsonMapper;
+  private final DruidNodeDiscoveryProvider druidNodeDiscovery;
+  private final ExecutorService exec;
+
+  @Inject
+  public CoordinatorBrokerConfigsResource(
+      JacksonConfigManager configManager,
+      AuditManager auditManager,
+      @EscalatedGlobal ServiceClientFactory clientFactory,
+      @Json ObjectMapper jsonMapper,
+      DruidNodeDiscoveryProvider druidNodeDiscoveryProvider
+  )
+  {
+    this.configManager = configManager;
+    this.auditManager = auditManager;
+    this.currentConfig = configManager.watch(
+        BrokerDynamicConfig.CONFIG_KEY,
+        BrokerDynamicConfig.class,
+        new BrokerDynamicConfig(null)
+    );
+    this.clientFactory = clientFactory;
+    this.jsonMapper = jsonMapper;
+    this.druidNodeDiscovery = druidNodeDiscoveryProvider;
+    this.exec = Execs.singleThreaded("CoordinatorBrokerConfigPush-%d");
+  }
+
+  @GET
+  @Produces(MediaType.APPLICATION_JSON)
+  public Response getBrokerDynamicConfig()
+  {
+    return Response.ok(currentConfig.get()).build();
+  }
+
+  @POST
+  @Consumes(MediaType.APPLICATION_JSON)
+  public Response setBrokerDynamicConfig(
+      BrokerDynamicConfig newConfig,
+      @Context HttpServletRequest req
+  )
+  {
+    try {
+      configManager.set(
+          BrokerDynamicConfig.CONFIG_KEY,
+          newConfig,
+          AuthorizationUtils.buildAuditInfo(req)
+      );
+
+      // Push config to all brokers synchronously (with short timeout) for 
immediate effect
+      pushConfigToBrokers(newConfig);
+
+      return Response.ok().build();
+    }
+    catch (Exception e) {
+      log.error(e, "Failed to set broker dynamic config");
+      return Response.serverError().entity(e.getMessage()).build();

Review Comment:
   ## Information exposure through an error message
   
   [Error information](1) can be exposed to an external user.
   [Error information](2) can be exposed to an external user.
   [Error information](3) can be exposed to an external user.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/10855)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to