-
Notifications
You must be signed in to change notification settings - Fork 919
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[KYUUBI #6001] Fix RESTful protocol security enabled evaluation
# 🔍 Description ## Issue References 🔗 #5568 (comment) ## Describe Your Solution 🔧 Only when Kerberos is enabled or effectivePlainAuthType is not NONE, RESTful security is enabled ## Types of changes 🔖 - [x] Bugfix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) ## Test Plan 🧪 #### Behavior Without This Pull Request ⚰️ when `kyuubi.authentication=KERBEROS` and use RESTful API, the exception is thrown `AuthenticationException("Kerberos is not supported for thrift http mode")` #### Behavior With This Pull Request 🎉 when `kyuubi.authentication=KERBEROS`, the RESTful API uses SPNego authN. #### Related Unit Tests Add some `*KyuubiRestFrontendServiceSuite` --- # Checklist 📝 - [x] This patch was not authored or co-authored using [Generative Tooling](https://www.apache.org/legal/generative-tooling.html) **Be nice. Be informative.** Closes #6001 from pan3793/auth-krb. Closes #6001 3640424 [Cheng Pan] nit 69d33fb [Cheng Pan] fix f18cf84 [Cheng Pan] Fix RESTful security enabled evaluation Authored-by: Cheng Pan <[email protected]> Signed-off-by: Cheng Pan <[email protected]>
- Loading branch information
Showing
8 changed files
with
131 additions
and
79 deletions.
There are no files selected for viewing
This file contains 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
72 changes: 72 additions & 0 deletions
72
kyuubi-common/src/main/scala/org/apache/kyuubi/service/authentication/AuthUtils.scala
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* 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.service.authentication | ||
|
||
import java.io.IOException | ||
|
||
import org.apache.hadoop.conf.Configuration | ||
import org.apache.hadoop.security.UserGroupInformation | ||
import org.apache.hadoop.security.authentication.util.KerberosName | ||
import org.apache.hadoop.security.authorize.ProxyUsers | ||
|
||
import org.apache.kyuubi.{KyuubiSQLException, Logging} | ||
import org.apache.kyuubi.service.authentication.AuthTypes.{AuthType, KERBEROS, NOSASL} | ||
|
||
object AuthUtils extends Logging { | ||
val HS2_PROXY_USER = "hive.server2.proxy.user" | ||
|
||
@throws[KyuubiSQLException] | ||
def verifyProxyAccess( | ||
realUser: String, | ||
proxyUser: String, | ||
ipAddress: String, | ||
hadoopConf: Configuration): Unit = { | ||
try { | ||
val sessionUgi = { | ||
if (UserGroupInformation.isSecurityEnabled) { | ||
val kerbName = new KerberosName(realUser) | ||
UserGroupInformation.createProxyUser( | ||
kerbName.getServiceName, | ||
UserGroupInformation.getLoginUser) | ||
} else { | ||
UserGroupInformation.createRemoteUser(realUser) | ||
} | ||
} | ||
|
||
if (!proxyUser.equalsIgnoreCase(realUser)) { | ||
ProxyUsers.refreshSuperUserGroupsConfiguration(hadoopConf) | ||
ProxyUsers.authorize(UserGroupInformation.createProxyUser(proxyUser, sessionUgi), ipAddress) | ||
} | ||
} catch { | ||
case e: IOException => | ||
throw KyuubiSQLException( | ||
"Failed to validate proxy privilege of " + realUser + " for " + proxyUser, | ||
e) | ||
} | ||
} | ||
|
||
def saslDisabled(authTypes: Seq[AuthType]): Boolean = authTypes == Seq(NOSASL) | ||
|
||
def kerberosEnabled(authTypes: Seq[AuthType]): Boolean = authTypes.contains(KERBEROS) | ||
|
||
// take the first declared SASL/PLAIN auth type | ||
def effectivePlainAuthType(authTypes: Seq[AuthType]): Option[AuthType] = authTypes.find { | ||
case NOSASL | KERBEROS => false | ||
case _ => true | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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