Skip to content

Commit

Permalink
[KYUUBI #6041] RESTful API supports isolated authentication enable co…
Browse files Browse the repository at this point in the history
…nfiguration
  • Loading branch information
wangjunbo committed Feb 4, 2024
1 parent a2179cc commit e0bc999
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,14 @@ object KyuubiConf {
.checkValues(AuthTypes)
.createWithDefault(Seq(AuthTypes.NONE.toString))

val RESTFUL_AUTHENTICATION: ConfigEntry[Boolean] =
buildConf("kyuubi.restful.security.enabled")
.doc("Whether to enable kyuubi server restful api secure access.")
.version("1.9.0")
.serverOnly
.booleanConf
.createWithDefault(true)

val AUTHENTICATION_CUSTOM_CLASS: OptionalConfigEntry[String] =
buildConf("kyuubi.authentication.custom.class")
.doc("User-defined authentication implementation of " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import scala.collection.mutable

import org.apache.kyuubi.Logging
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.{AUTHENTICATION_METHOD, FRONTEND_PROXY_HTTP_CLIENT_IP_HEADER}
import org.apache.kyuubi.config.KyuubiConf.{AUTHENTICATION_METHOD, FRONTEND_PROXY_HTTP_CLIENT_IP_HEADER, RESTFUL_AUTHENTICATION}
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}
Expand Down Expand Up @@ -79,7 +79,14 @@ class AuthenticationFilter(conf: KyuubiConf) extends Filter with Logging {
}

override def init(filterConfig: FilterConfig): Unit = {
initAuthHandlers()
if (conf.get(RESTFUL_AUTHENTICATION)) {
initAuthHandlers()
} else {
Set(NOSASL).foreach { basicAuthType =>
val basicHandler = new BasicAuthenticationHandler(basicAuthType)
addAuthHandler(basicHandler)
}
}
}

private[kyuubi] def getMatchedHandler(authorization: String): Option[AuthenticationHandler] = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.kyuubi.operation

import javax.servlet.http.HttpServletResponse

import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.service.authentication.InternalSecurityAccessor

class KyuubiRestDisableAuthenticationSuite extends KyuubiRestAuthenticationSuite {

override protected val otherConfigs: Map[String, String] = {
Map(
KyuubiConf.RESTFUL_AUTHENTICATION.key -> "false",
KyuubiConf.ENGINE_SECURITY_ENABLED.key -> "true",
KyuubiConf.ENGINE_SECURITY_SECRET_PROVIDER.key -> "simple",
KyuubiConf.SIMPLE_SECURITY_SECRET_PROVIDER_PROVIDER_SECRET.key -> "_KYUUBI_REST_",
// allow to impersonate other users with spnego authentication
s"hadoop.proxyuser.$clientPrincipalUser.groups" -> "*",
s"hadoop.proxyuser.$clientPrincipalUser.hosts" -> "*")
}

override def beforeAll(): Unit = {
super.beforeAll()
InternalSecurityAccessor.initialize(conf, true)
}

test("test without authorization when disable kyuubi.restful.security.enabled") {
val response = webTarget.path("api/v1/sessions/count")
.request()
.get()

assert(HttpServletResponse.SC_OK == response.getStatus)
}
}

0 comments on commit e0bc999

Please sign in to comment.