Skip to content

Commit c83618e

Browse files
committed
[SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
### What changes were proposed in this pull request? This PR proposes to avoid using `bash -c` in `ShellBasedGroupsMappingProvider`. This could allow users a command injection. ### Why are the changes needed? For a security purpose. ### Does this PR introduce _any_ user-facing change? Virtually no. ### How was this patch tested? Manually tested. Closes #36315 from HyukjinKwon/SPARK-38992. Authored-by: Hyukjin Kwon <[email protected]> Signed-off-by: Hyukjin Kwon <[email protected]>
1 parent 8d59fdb commit c83618e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import org.apache.spark.util.Utils
3030
private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingServiceProvider
3131
with Logging {
3232

33+
private lazy val idPath = Utils.executeAndGetOutput("which" :: "id" :: Nil).stripLineEnd
34+
3335
override def getGroups(username: String): Set[String] = {
3436
val userGroups = getUnixGroups(username)
3537
logDebug("User: " + username + " Groups: " + userGroups.mkString(","))
@@ -38,8 +40,7 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
3840

3941
// shells out a "bash -c id -Gn username" to get user groups
4042
private def getUnixGroups(username: String): Set[String] = {
41-
val cmdSeq = Seq("bash", "-c", "id -Gn " + username)
4243
// we need to get rid of the trailing "\n" from the result of command execution
43-
Utils.executeAndGetOutput(cmdSeq).stripLineEnd.split(" ").toSet
44+
Utils.executeAndGetOutput(idPath :: "-Gn" :: username :: Nil).stripLineEnd.split(" ").toSet
4445
}
4546
}

0 commit comments

Comments
 (0)