Skip to content

Commit

Permalink
Update to preferred groups
Browse files Browse the repository at this point in the history
  • Loading branch information
Madhukar525722 committed Oct 28, 2024
1 parent 638a44d commit 8332035
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/configuration/settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ You can configure the Kyuubi properties in `$KYUUBI_HOME/conf/kyuubi-defaults.co
| kyuubi.session.idle.timeout | PT6H | session idle timeout, it will be closed when it's not accessed for this duration | duration | 1.2.0 |
| kyuubi.session.local.dir.allow.list || The local dir list that are allowed to access by the kyuubi session application. End-users might set some parameters such as `spark.files` and it will upload some local files when launching the kyuubi engine, if the local dir allow list is defined, kyuubi will check whether the path to upload is in the allow list. Note that, if it is empty, there is no limitation for that. And please use absolute paths. | set | 1.6.0 |
| kyuubi.session.name | <undefined> | A human readable name of the session and we use empty string by default. This name will be recorded in the event. Note that, we only apply this value from session conf. | string | 1.4.0 |
| kyuubi.session.preferGroup | <undefined> | The hadoop group name for the group engine launch. This will be checked for the presence in the list of user's allowed groups. If present, it will take precedence for GROUP SHARE LEVEL execution. If this is not configured, the session will use the first group name from the list of groups as the primary group. | string | 1.9.3 |
| kyuubi.session.preferGroups | <undefined> | Comma separated list of hadoop group name for the group engine launch. The first preferred and valid group from this list will be used for GROUP SHARE LEVEL execution. If this is not configured, the engine will use the first group name from the users list of groups as the primary group. | seq | 1.9.3 |
| kyuubi.session.proxy.user | <undefined> | An alternative to hive.server2.proxy.user. The current behavior is consistent with hive.server2.proxy.user and now only takes effect in RESTFul API. When both parameters are set, kyuubi.session.proxy.user takes precedence. | string | 1.9.0 |
| kyuubi.session.timeout | PT6H | (deprecated)session timeout, it will be closed when it's not accessed for this duration | duration | 1.0.0 |
| kyuubi.session.user.sign.enabled | false | Whether to verify the integrity of session user name on the engine side, e.g. Authz plugin in Spark. | boolean | 1.7.0 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2779,15 +2779,15 @@ object KyuubiConf {
}
.createWithDefault("hadoop")

val PREFERRED_GROUP: OptionalConfigEntry[String] =
buildConf("kyuubi.session.preferGroup")
.doc("The hadoop group name for the group engine launch. This will be checked " +
"for the presence in the list of user's allowed groups. If present, it will " +
"take precedence for GROUP SHARE LEVEL execution. If this is not configured, " +
"the session will use the first group name from the list of groups as the " +
"primary group.")
val PREFERRED_GROUPS: OptionalConfigEntry[Seq[String]] =
buildConf("kyuubi.session.preferGroups")
.doc("Comma separated list of hadoop group name for the group engine launch. " +
"The first preferred and valid group from this list will be used for GROUP " +
"SHARE LEVEL execution. If this is not configured, the engine will use " +
"the first group name from the users list of groups as the primary group.")
.version("1.9.3")
.stringConf
.toSequence()
.createOptional

val SERVER_NAME: OptionalConfigEntry[String] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,25 @@ import org.apache.kyuubi.plugin.GroupProvider
*/
class HadoopGroupProvider extends GroupProvider with Logging {
override def primaryGroup(user: String, sessionConf: JMap[String, String]): String = {
val preferredGroup: Option[String] = if (sessionConf != null) {
Option(sessionConf.get(KyuubiConf.PREFERRED_GROUP.key))
val preferredGroups: Option[Seq[String]] = if (sessionConf != null) {
Option(sessionConf.get(KyuubiConf.PREFERRED_GROUPS.key)).map(_.split(",").toSeq)
} else {
None
}

val userGroups: Array[String] = groups(user, sessionConf)

val primaryGroup = preferredGroup match {
case Some(group) if userGroups.contains(group) => group
val primaryGroup = preferredGroups match {
case Some(groups) =>
groups.find(userGroups.contains) match {
case Some(group) => group
case None => userGroups.headOption.getOrElse {
throw new NoSuchElementException("No groups available for the user")
}
}
case None => userGroups.headOption.getOrElse {
throw new NoSuchElementException("No groups available for the user")
}
case Some(group) =>
throw new IllegalArgumentException(s"User is not part of the preferred group: $group")
}
primaryGroup
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,24 @@ class KyuubiOperationPerGroupSuite extends WithKyuubiServer with SparkQueryTests

test("ensure preferred group is chosen from list of groups") {
withSessionConf(Map("hive.server2.proxy.user" -> "user1"))(Map(
KyuubiConf.PREFERRED_GROUP.key -> "group_tt"))(Map.empty) {
KyuubiConf.PREFERRED_GROUPS.key -> "test,group_tt,testGG"))(Map.empty) {
withJdbcStatement() { statement =>
val res = statement.executeQuery("set spark.app.name")
assert(res.next())
val engineName = res.getString("value")
assert(engineName.startsWith(s"kyuubi_GROUP_${conf.get(KyuubiConf.ENGINE_TYPE)}_group_tt"))
}
}

withSessionConf(Map("hive.server2.proxy.user" -> "user1"))(Map(
KyuubiConf.PREFERRED_GROUPS.key -> "test"))(Map.empty) {
withJdbcStatement() { statement =>
val res = statement.executeQuery("set spark.app.name")
assert(res.next())
val engineName = res.getString("value")
assert(engineName.startsWith(s"kyuubi_GROUP_${conf.get(KyuubiConf.ENGINE_TYPE)}_testGG"))
}
}
}

test("support real user for kyuubi session") {
Expand Down

0 comments on commit 8332035

Please sign in to comment.