You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@spark.apache.org by GitBox <gi...@apache.org> on 2022/04/22 03:11:40 UTC
[GitHub] [spark] HyukjinKwon opened a new pull request, #36315: [SPARK-38992][CORE]Avoid using bash -c in ShellBasedGroupsMappingProvider
HyukjinKwon opened a new pull request, #36315:
URL: https://github.com/apache/spark/pull/36315
### 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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on a diff in pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on code in PR #36315:
URL: https://github.com/apache/spark/pull/36315#discussion_r855748245
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -38,8 +38,10 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
// shells out a "bash -c id -Gn username" to get user groups
Review Comment:
```suggestion
// shells out a "id -Gn username" to get user groups
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] JoshRosen commented on a diff in pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
JoshRosen commented on code in PR #36315:
URL: https://github.com/apache/spark/pull/36315#discussion_r855751881
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -36,10 +36,12 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
userGroups
}
- // shells out a "bash -c id -Gn username" to get user groups
+ // shells out a "id -Gn username" to get user groups
private def getUnixGroups(username: String): Set[String] = {
- val cmdSeq = Seq("bash", "-c", "id -Gn " + username)
+ val idPath = Utils.executeAndGetOutput("which" :: "id" :: Nil).stripLineEnd
Review Comment:
Are you concerned about whether the `id` command might resolve differently in bash vs. the default shell? That's fair: it might be unlikely to be different, but maybe we want to play it safe.
What do you think about caching the value in a `private lazy val` right before this method so we only invoke it once?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] gengliangwang commented on a diff in pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
gengliangwang commented on code in PR #36315:
URL: https://github.com/apache/spark/pull/36315#discussion_r855746240
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -38,8 +38,10 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
// shells out a "bash -c id -Gn username" to get user groups
private def getUnixGroups(username: String): Set[String] = {
- val cmdSeq = Seq("bash", "-c", "id -Gn " + username)
+ val idPath = Utils.executeAndGetOutput("which" :: "id" :: Nil).stripLineEnd
Review Comment:
I am not familiar with this. How can `executeAndGetOutput` avoid injection?
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -38,8 +38,10 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
// shells out a "bash -c id -Gn username" to get user groups
Review Comment:
Let's update the comment as well
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] JoshRosen commented on a diff in pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
JoshRosen commented on code in PR #36315:
URL: https://github.com/apache/spark/pull/36315#discussion_r855748988
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -36,10 +36,12 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
userGroups
}
- // shells out a "bash -c id -Gn username" to get user groups
+ // shells out a "id -Gn username" to get user groups
private def getUnixGroups(username: String): Set[String] = {
- val cmdSeq = Seq("bash", "-c", "id -Gn " + username)
+ val idPath = Utils.executeAndGetOutput("which" :: "id" :: Nil).stripLineEnd
Review Comment:
Why do we need a separate `which` command? Why can't we just invoke `id` directly (e.g. just change this to `val cmdSeq = Seq("id", "-Gn", username)` and leave line 43 unchanged)?
Are you concerned about whether the `id` command might resolve differently in bash vs. the default shell?
If we go with this approach (to be conservative), WDYT about caching the value in a `private lazy val` right before this method (so we only invoke it once)?
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -36,10 +36,12 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
userGroups
}
- // shells out a "bash -c id -Gn username" to get user groups
+ // shells out a "id -Gn username" to get user groups
private def getUnixGroups(username: String): Set[String] = {
- val cmdSeq = Seq("bash", "-c", "id -Gn " + username)
+ val idPath = Utils.executeAndGetOutput("which" :: "id" :: Nil).stripLineEnd
Review Comment:
Why do we need a separate `which` command? Why can't we just invoke `id` directly (e.g. just change this to `val cmdSeq = Seq("id", "-Gn", username)` and leave line 43 unchanged)?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] JoshRosen commented on a diff in pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
JoshRosen commented on code in PR #36315:
URL: https://github.com/apache/spark/pull/36315#discussion_r855748988
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -36,10 +36,12 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
userGroups
}
- // shells out a "bash -c id -Gn username" to get user groups
+ // shells out a "id -Gn username" to get user groups
private def getUnixGroups(username: String): Set[String] = {
- val cmdSeq = Seq("bash", "-c", "id -Gn " + username)
+ val idPath = Utils.executeAndGetOutput("which" :: "id" :: Nil).stripLineEnd
Review Comment:
Why do we need a separate `which` command? Why can't we just invoke `id` directly?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #36315:
URL: https://github.com/apache/spark/pull/36315#issuecomment-1106316771
Merged to master, branch-3.3, branch-3.2, branch-3.1, and branch-3.0.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] JoshRosen commented on a diff in pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
JoshRosen commented on code in PR #36315:
URL: https://github.com/apache/spark/pull/36315#discussion_r855748988
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -36,10 +36,12 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
userGroups
}
- // shells out a "bash -c id -Gn username" to get user groups
+ // shells out a "id -Gn username" to get user groups
private def getUnixGroups(username: String): Set[String] = {
- val cmdSeq = Seq("bash", "-c", "id -Gn " + username)
+ val idPath = Utils.executeAndGetOutput("which" :: "id" :: Nil).stripLineEnd
Review Comment:
Why do we need a separate `which` command? Why can't we just invoke `id` directly (e.g. just change this to `val cmdSeq = Seq("id", "-Gn", username)` and leave line 43 unchanged)?
Are you concerned about whether the `id` command might resolve differently in bash vs. the default shell?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on a diff in pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on code in PR #36315:
URL: https://github.com/apache/spark/pull/36315#discussion_r855751736
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -36,10 +36,12 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
userGroups
}
- // shells out a "bash -c id -Gn username" to get user groups
+ // shells out a "id -Gn username" to get user groups
private def getUnixGroups(username: String): Set[String] = {
- val cmdSeq = Seq("bash", "-c", "id -Gn " + username)
+ val idPath = Utils.executeAndGetOutput("which" :: "id" :: Nil).stripLineEnd
Review Comment:
We can do .. I wanted to keep the behavior as much as possible (e.g., bash might point a different `id`) .. but probably I was overthinking. Directly invoking `id` would be better.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] JoshRosen commented on a diff in pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
JoshRosen commented on code in PR #36315:
URL: https://github.com/apache/spark/pull/36315#discussion_r855748988
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -36,10 +36,12 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
userGroups
}
- // shells out a "bash -c id -Gn username" to get user groups
+ // shells out a "id -Gn username" to get user groups
private def getUnixGroups(username: String): Set[String] = {
- val cmdSeq = Seq("bash", "-c", "id -Gn " + username)
+ val idPath = Utils.executeAndGetOutput("which" :: "id" :: Nil).stripLineEnd
Review Comment:
Why do we need a separate `which` command? Why can't we just invoke `id` directly (e.g. just change this to `val cmdSeq = Seq("id", "-Gn", username)` and leave line 43 unchanged?
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -36,10 +36,12 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
userGroups
}
- // shells out a "bash -c id -Gn username" to get user groups
+ // shells out a "id -Gn username" to get user groups
private def getUnixGroups(username: String): Set[String] = {
- val cmdSeq = Seq("bash", "-c", "id -Gn " + username)
+ val idPath = Utils.executeAndGetOutput("which" :: "id" :: Nil).stripLineEnd
Review Comment:
Why do we need a separate `which` command? Why can't we just invoke `id` directly (e.g. just change this to `val cmdSeq = Seq("id", "-Gn", username)` and leave line 43 unchanged)?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon closed pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
HyukjinKwon closed pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
URL: https://github.com/apache/spark/pull/36315
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] gengliangwang commented on a diff in pull request #36315: [SPARK-38992][CORE] Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
gengliangwang commented on code in PR #36315:
URL: https://github.com/apache/spark/pull/36315#discussion_r855746240
##########
core/src/main/scala/org/apache/spark/security/ShellBasedGroupsMappingProvider.scala:
##########
@@ -38,8 +38,10 @@ private[spark] class ShellBasedGroupsMappingProvider extends GroupMappingService
// shells out a "bash -c id -Gn username" to get user groups
private def getUnixGroups(username: String): Set[String] = {
- val cmdSeq = Seq("bash", "-c", "id -Gn " + username)
+ val idPath = Utils.executeAndGetOutput("which" :: "id" :: Nil).stripLineEnd
Review Comment:
I am not familiar with this. How can `executeAndGetOutput` avoid injection?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org
[GitHub] [spark] HyukjinKwon commented on pull request #36315: [SPARK-38992][CORE]Avoid using bash -c in ShellBasedGroupsMappingProvider
Posted by GitBox <gi...@apache.org>.
HyukjinKwon commented on PR #36315:
URL: https://github.com/apache/spark/pull/36315#issuecomment-1105959105
cc @JoshRosen @gengliangwang mind taking a look please?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org