NGSOK-1852 Backport AuthenticationFilter and add MetricsAuthFilter to path-scope auth on the Spark UI#50
Merged
Conversation
Spark's HTTP security is UI-wide: spark.ui.filters, the ACLs and the TLS connector all apply to every path served by the Spark UI, so there is no built-in way to require a bearer token on /metrics/* while leaving the human UI on Kerberos. A Prometheus/vmagent scraper cannot perform SPNEGO, so a UI-wide SPNEGO filter would block scraping outright. MetricsAuthFilter is a single spark.ui.filters filter that dispatches by path: bearer-guarded (or open) for /metrics/*, and an optional delegate to Hadoop's javax AuthenticationFilter (SPNEGO/pseudo) for the rest of the UI. Spark 3.5's UI is javax.servlet, so Hadoop's own AuthenticationFilter plugs in directly - no Spark wrapper is needed, unlike Spark 4 whose jakarta UI requires one. The delegate is loaded reflectively so this compiles against the shaded hadoop-client-api while the unshaded hadoop-auth supplies the real filter at runtime. Ships in spark-core, configured via spark.org.apache.spark.filter.MetricsAuthFilter.param.*. Both this filter and using Hadoop's AuthenticationFilter directly are documented in docs/security.md.
…ark 4 On Spark 3.5 the UI is javax.servlet, so Hadoop's own AuthenticationFilter can protect the whole Web UI directly - no Spark class is strictly required (unlike Spark 4, whose jakarta UI needs the org.apache.spark.filter.AuthenticationFilter shim). This adds a thin org.apache.spark.filter.AuthenticationFilter that forwards init/doFilter/destroy to Hadoop's javax filter (loaded reflectively to compile against the shaded hadoop-client-api; the unshaded hadoop-auth supplies the real filter at runtime). Its only purpose is configuration parity: the same spark.ui.filters value and spark.org.apache.spark.filter.AuthenticationFilter.param.* keys now work on Spark 3.5 and Spark 4 alike, and are shorter than naming Hadoop's class directly. MetricsAuthFilter now delegates to this wrapper so both filters share one class. docs/security.md updated accordingly.
27afdb2 to
c8eb05f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Spark's HTTP security is UI-wide: spark.ui.filters, the ACLs and the TLS connector all apply to every path served by the Spark UI, so there is no built-in way to require a bearer token on /metrics/* while leaving the human UI on Kerberos. A Prometheus/vmagent scraper cannot perform SPNEGO, so a UI-wide SPNEGO filter would block scraping outright.
MetricsAuthFilter is a single spark.ui.filters filter that dispatches by path: bearer-guarded (or open) for /metrics/*, and an optional delegate to Hadoop's javax AuthenticationFilter (SPNEGO/pseudo) for the rest of the UI. Spark 3.5's UI is javax.servlet, so Hadoop's own AuthenticationFilter plugs in directly - no Spark wrapper is needed, unlike Spark 4 whose jakarta UI requires one. The delegate is loaded reflectively so this compiles against the shaded hadoop-client-api while the unshaded hadoop-auth supplies the real filter at runtime.
Ships in spark-core, configured via
spark.org.apache.spark.filter.MetricsAuthFilter.param.*. Both this filter and using Hadoop's AuthenticationFilter directly are documented in docs/security.md.