Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Commit 35724a3

Browse files
mccheahash211
authored andcommitted
Allow providing an OAuth token for authenticating against k8s (#180)
* Allow providing an OAuth token for authenticating against k8s * Organize imports * Fix style * Remove extra newline * Use OAuth token data instead of a file. (cherry picked from commit 1aba361)
1 parent fece639 commit 35724a3

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

docs/running-on-kubernetes.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,14 @@ from the other deployment modes. See the [configuration page](configuration.html
222222
machine's disk.
223223
</td>
224224
</tr>
225+
<tr>
226+
<td><code>spark.kubernetes.submit.oauthToken</code></td>
227+
<td>(none)</td>
228+
<td>
229+
OAuth token to use when authenticating against the against the Kubernetes API server. Note that unlike the other
230+
authentication options, this should be the exact string value of the token to use for the authentication.
231+
</td>
232+
</tr>
225233
<tr>
226234
<td><code>spark.kubernetes.submit.serviceAccountName</code></td>
227235
<td><code>default</code></td>

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/kubernetes/Client.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import java.security.SecureRandom
2121
import java.util.ServiceLoader
2222
import java.util.concurrent.{CountDownLatch, TimeUnit}
2323

24+
import com.google.common.base.Charsets
2425
import com.google.common.io.Files
2526
import com.google.common.util.concurrent.SettableFuture
2627
import io.fabric8.kubernetes.api.model._
@@ -131,6 +132,11 @@ private[spark] class Client(
131132
sparkConf.get(KUBERNETES_CLIENT_CERT_FILE).foreach {
132133
f => k8ConfBuilder = k8ConfBuilder.withClientCertFile(f)
133134
}
135+
sparkConf.get(KUBERNETES_OAUTH_TOKEN).foreach { token =>
136+
k8ConfBuilder = k8ConfBuilder.withOauthToken(token)
137+
// Remove the oauth token from Spark conf so that its doesn't appear in the Spark UI.
138+
sparkConf.set(KUBERNETES_OAUTH_TOKEN, "<present_but_redacted>")
139+
}
134140

135141
val k8ClientConfig = k8ConfBuilder.build
136142
Utils.tryWithResource(new DefaultKubernetesClient(k8ClientConfig)) { kubernetesClient =>

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/kubernetes/config.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ package object config {
8383
.stringConf
8484
.createOptional
8585

86+
private[spark] val KUBERNETES_OAUTH_TOKEN =
87+
ConfigBuilder("spark.kubernetes.submit.oauthToken")
88+
.doc("""
89+
| OAuth token to use when authenticating against the
90+
| against the Kubernetes API server. Note that unlike
91+
| the other authentication options, this should be the
92+
| exact string value of the token to use for the
93+
| authentication.
94+
""".stripMargin)
95+
.stringConf
96+
.createOptional
97+
8698
private[spark] val KUBERNETES_SERVICE_ACCOUNT_NAME =
8799
ConfigBuilder("spark.kubernetes.submit.serviceAccountName")
88100
.doc("""

0 commit comments

Comments
 (0)