Skip to content

Commit a55de38

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. (cherry picked from commit f53818d) Signed-off-by: Marcelo Vanzin <[email protected]>
1 parent 63e1da1 commit a55de38

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
@@ -406,7 +406,7 @@ private[spark] object JettyUtils extends Logging {
406406
}
407407

408408
pool.setMaxThreads(math.max(pool.getMaxThreads, minThreads))
409-
ServerInfo(server, httpPort, securePort, collection)
409+
ServerInfo(server, httpPort, securePort, conf, collection)
410410
} catch {
411411
case e: Exception =>
412412
server.stop()
@@ -506,10 +506,12 @@ private[spark] case class ServerInfo(
506506
server: Server,
507507
boundPort: Int,
508508
securePort: Option[Int],
509+
conf: SparkConf,
509510
private val rootHandler: ContextHandlerCollection) {
510511

511-
def addHandler(handler: ContextHandler): Unit = {
512+
def addHandler(handler: ServletContextHandler): Unit = {
512513
handler.setVirtualHosts(JettyUtils.toVirtualHosts(JettyUtils.SPARK_CONNECTOR_NAME))
514+
JettyUtils.addFilters(Seq(handler), conf)
513515
rootHandler.addHandler(handler)
514516
if (!handler.isStarted()) {
515517
handler.start()

0 commit comments

Comments
 (0)