Skip to content

Commit f53818d

Browse files
mgaido91Marcelo Vanzin
authored andcommitted
[SPARK-24506][UI] Add UI filters to tabs added after binding
## What changes were proposed in this pull request? 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. ## How was this patch tested? 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 #21523 from mgaido91/SPARK-24506.
1 parent 0d3714d commit f53818d

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
@@ -152,7 +152,6 @@ class HistoryServer(
152152
assert(serverInfo.isDefined, "HistoryServer must be bound before attaching SparkUIs")
153153
handlers.synchronized {
154154
ui.getHandlers.foreach(attachHandler)
155-
addFilters(ui.getHandlers, conf)
156155
}
157156
}
158157

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ private[spark] object JettyUtils extends Logging {
263263
filters.foreach {
264264
case filter : String =>
265265
if (!filter.isEmpty) {
266-
logInfo("Adding filter: " + filter)
266+
logInfo(s"Adding filter $filter to ${handlers.map(_.getContextPath).mkString(", ")}.")
267267
val holder : FilterHolder = new FilterHolder()
268268
holder.setClassName(filter)
269269
// Get any parameters for each filter
@@ -407,7 +407,7 @@ private[spark] object JettyUtils extends Logging {
407407
}
408408

409409
pool.setMaxThreads(math.max(pool.getMaxThreads, minThreads))
410-
ServerInfo(server, httpPort, securePort, collection)
410+
ServerInfo(server, httpPort, securePort, conf, collection)
411411
} catch {
412412
case e: Exception =>
413413
server.stop()
@@ -507,10 +507,12 @@ private[spark] case class ServerInfo(
507507
server: Server,
508508
boundPort: Int,
509509
securePort: Option[Int],
510+
conf: SparkConf,
510511
private val rootHandler: ContextHandlerCollection) {
511512

512-
def addHandler(handler: ContextHandler): Unit = {
513+
def addHandler(handler: ServletContextHandler): Unit = {
513514
handler.setVirtualHosts(JettyUtils.toVirtualHosts(JettyUtils.SPARK_CONNECTOR_NAME))
515+
JettyUtils.addFilters(Seq(handler), conf)
514516
rootHandler.addHandler(handler)
515517
if (!handler.isStarted()) {
516518
handler.start()

0 commit comments

Comments
 (0)