diff --git a/docs/configuration/settings.md b/docs/configuration/settings.md index 6d7fe046af5..44aa8062c85 100644 --- a/docs/configuration/settings.md +++ b/docs/configuration/settings.md @@ -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 | diff --git a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala index 64bf5b49eb9..22051bc37cb 100644 --- a/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala +++ b/kyuubi-common/src/main/scala/org/apache/kyuubi/config/KyuubiConf.scala @@ -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] = diff --git a/kyuubi-server/src/main/scala/org/apache/kyuubi/session/HadoopGroupProvider.scala b/kyuubi-server/src/main/scala/org/apache/kyuubi/session/HadoopGroupProvider.scala index 8235c9d53eb..1b9c9f28aa1 100644 --- a/kyuubi-server/src/main/scala/org/apache/kyuubi/session/HadoopGroupProvider.scala +++ b/kyuubi-server/src/main/scala/org/apache/kyuubi/session/HadoopGroupProvider.scala @@ -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 } diff --git a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerGroupSuite.scala b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerGroupSuite.scala index 72367bf9b41..87505b083d7 100644 --- a/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerGroupSuite.scala +++ b/kyuubi-server/src/test/scala/org/apache/kyuubi/operation/KyuubiOperationPerGroupSuite.scala @@ -80,7 +80,7 @@ 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()) @@ -88,6 +88,16 @@ class KyuubiOperationPerGroupSuite extends WithKyuubiServer with SparkQueryTests 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") {