Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[KYUUBI #6041] RESTful API supports isolated authentication configuration #6042

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
clean code
  • Loading branch information
wangjunbo committed Feb 22, 2024
commit dee53411e7d9041b2b7d429694e0635bc2052f8a
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ class KyuubiRestFrontendService(override val serverable: Serverable)

private def startInternal(): Unit = {
val contextHandler = ApiRootResource.getServletHandler(this)
val holder = new FilterHolder(
new AuthenticationFilter(
conf,
conf.get(FRONTEND_REST_AUTHENTICATION_METHOD).map(AuthTypes.withName),
REST))
val holder = new FilterHolder(new AuthenticationFilter(conf, REST))
contextHandler.addFilter(holder, "/v1/*", EnumSet.allOf(classOf[DispatcherType]))
val authenticationFactory = new KyuubiHttpAuthenticationFactory(conf)
server.addHandler(authenticationFactory.httpHandlerWrapperFactory.wrapHandler(contextHandler))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ class ThriftHttpServlet(
private var isCookieSecure = false
private var isHttpOnlyCookie = false
private val X_FORWARDED_FOR_HEADER = "X-Forwarded-For"
private val authenticationFilter =
new AuthenticationFilter(
conf,
conf.get(AUTHENTICATION_METHOD).map(AuthTypes.withName),
THRIFT_HTTP)
private val authenticationFilter = new AuthenticationFilter(conf, THRIFT_HTTP)

override def init(): Unit = {
isCookieAuthEnabled = conf.get(KyuubiConf.FRONTEND_THRIFT_HTTP_COOKIE_AUTH_ENABLED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ import scala.collection.mutable

import org.apache.kyuubi.Logging
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.FRONTEND_PROXY_HTTP_CLIENT_IP_HEADER
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.FrontendProtocol
import org.apache.kyuubi.config.KyuubiConf.{AUTHENTICATION_METHOD, FRONTEND_PROXY_HTTP_CLIENT_IP_HEADER, FRONTEND_REST_AUTHENTICATION_METHOD}
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.{FrontendProtocol, REST}
import org.apache.kyuubi.server.http.util.HttpAuthUtils.AUTHORIZATION_HEADER
import org.apache.kyuubi.service.authentication.{AuthTypes, InternalSecurityAccessor}
import org.apache.kyuubi.service.authentication.AuthTypes.{KERBEROS, NOSASL}

class AuthenticationFilter(
conf: KyuubiConf,
authTypes: Seq[AuthTypes.Value],
protocol: FrontendProtocol) extends Filter
class AuthenticationFilter(conf: KyuubiConf, protocol: FrontendProtocol) extends Filter
with Logging {
import AuthenticationFilter._
import AuthSchemes._
Expand All @@ -60,6 +57,10 @@ class AuthenticationFilter(
}

private[kyuubi] def initAuthHandlers(): Unit = {
val authTypes = protocol match {
case REST => conf.get(FRONTEND_REST_AUTHENTICATION_METHOD).map(AuthTypes.withName)
case _ => conf.get(AUTHENTICATION_METHOD).map(AuthTypes.withName)
}
val spnegoKerberosEnabled = authTypes.contains(KERBEROS)
val basicAuthTypeOpt = {
if (authTypes == Set(NOSASL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ package org.apache.kyuubi.server.http.authentication

import org.apache.kyuubi.KyuubiFunSuite
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.AUTHENTICATION_METHOD
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.REST
import org.apache.kyuubi.service.authentication.AuthTypes

class RestAuthenticationFilterSuite extends KyuubiFunSuite {
test("add auth handler and destroy") {
val conf = KyuubiConf()
val filter =
new AuthenticationFilter(
conf,
conf.get(AUTHENTICATION_METHOD).map(AuthTypes.withName),
REST)
val filter = new AuthenticationFilter(conf, REST)
filter.addAuthHandler(new BasicAuthenticationHandler(null, REST))
assert(filter.authSchemeHandlers.isEmpty)
filter.addAuthHandler(new BasicAuthenticationHandler(AuthTypes.LDAP, REST))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ package org.apache.kyuubi.server.http.authentication

import org.apache.kyuubi.KyuubiFunSuite
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.AUTHENTICATION_METHOD
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.THRIFT_HTTP
import org.apache.kyuubi.service.authentication.AuthTypes

class ThriftHttpAuthenticationFilterSuite extends KyuubiFunSuite {
test("add auth handler and destroy") {
val conf = KyuubiConf()
val filter =
new AuthenticationFilter(
conf,
conf.get(AUTHENTICATION_METHOD).map(AuthTypes.withName),
THRIFT_HTTP)
val filter = new AuthenticationFilter(conf, THRIFT_HTTP)
filter.addAuthHandler(new BasicAuthenticationHandler(null, THRIFT_HTTP))
assert(filter.authSchemeHandlers.isEmpty)
filter.addAuthHandler(new BasicAuthenticationHandler(AuthTypes.LDAP, THRIFT_HTTP))
Expand Down
Loading