Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit 51dee38

Browse files
mgaido91MatthewRBruce
authored andcommitted
[SPARK-24506][UI] Add UI filters to tabs added after binding
Currently, `spark.ui.filters` are not applied to the handlers added after binding the server. This means that every page which is added after starting the UI will not have the filters configured on it. This can allow unauthorized access to the pages. The PR adds the filters also to the handlers added after the UI starts. manual tests (without the patch, starting the thriftserver with `--conf spark.ui.filters=org.apache.hadoop.security.authentication.server.AuthenticationFilter --conf spark.org.apache.hadoop.security.authentication.server.AuthenticationFilter.params="type=simple"` you can access `http://localhost:4040/sqlserver`; with the patch, 401 is the response as for the other pages). Author: Marco Gaido <[email protected]> Closes apache#21523 from mgaido91/SPARK-24506. (cherry picked from commit f53818d) Signed-off-by: Marcelo Vanzin <[email protected]>
1 parent c1a9414 commit 51dee38

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ class HistoryServer(
151151
completed: Boolean) {
152152
assert(serverInfo.isDefined, "HistoryServer must be bound before attaching SparkUIs")
153153
ui.getHandlers.foreach(attachHandler)
154-
addFilters(ui.getHandlers, conf)
155154
}
156155

157156
/** Detach a reconstructed UI from this server. Only valid after bind(). */

core/src/main/scala/org/apache/spark/ui/JettyUtils.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ private[spark] object JettyUtils extends Logging {
250250
filters.foreach {
251251
case filter : String =>
252252
if (!filter.isEmpty) {
253-
logInfo("Adding filter: " + filter)
253+
logInfo(s"Adding filter $filter to ${handlers.map(_.getContextPath).mkString(", ")}.")
254254
val holder : FilterHolder = new FilterHolder()
255255
holder.setClassName(filter)
256256
// Get any parameters for each filter
@@ -393,7 +393,7 @@ private[spark] object JettyUtils extends Logging {
393393
}
394394

395395
pool.setMaxThreads(math.max(pool.getMaxThreads, minThreads))
396-
ServerInfo(server, httpPort, securePort, collection)
396+
ServerInfo(server, httpPort, securePort, conf, collection)
397397
} catch {
398398
case e: Exception =>
399399
server.stop()
@@ -492,10 +492,12 @@ private[spark] case class ServerInfo(
492492
server: Server,
493493
boundPort: Int,
494494
securePort: Option[Int],
495+
conf: SparkConf,
495496
private val rootHandler: ContextHandlerCollection) {
496497

497-
def addHandler(handler: ContextHandler): Unit = {
498+
def addHandler(handler: ServletContextHandler): Unit = {
498499
handler.setVirtualHosts(JettyUtils.toVirtualHosts(JettyUtils.SPARK_CONNECTOR_NAME))
500+
JettyUtils.addFilters(Seq(handler), conf)
499501
rootHandler.addHandler(handler)
500502
if (!handler.isStarted()) {
501503
handler.start()

0 commit comments

Comments
 (0)