Skip to content

Commit 818992d

Browse files
committed
update
1 parent 3b94013 commit 818992d

File tree

1 file changed

+33
-99
lines changed

1 file changed

+33
-99
lines changed

docs/modules/spark-k8s/pages/usage-guide/security.adoc

Lines changed: 33 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ Currently, the only supported authentication mechanism is Kerberos, which is dis
66

77
Kerberos is a network authentication protocol that works on the basis of "tickets" to allow nodes communicating over a non-secure network to prove their identity to one another securely. It is used in Spark to authenticate users and to secure communication between Spark components.
88

9-
In this guide we show how to configure Spark applications to use Kerberos. The Stackable Secret Operator is used to generate the keytab files. In production environments, users might have different means to provision the keytab files.
9+
In this guide we show how to configure Spark applications to use Kerberos while accessing data in HDFS cluster. The Stackable Secret Operator is used to generate the keytab files. In production environments, users might have different means to provision the keytab files.
1010

1111

1212
== Prerequisites
1313

1414
It is assumed that you have a KDC server running in your cluster and that the Stackable Secret Operator is configured to provision the keytab files as described in xref:home:secret-operator:secretclass.adoc#backend-kerberoskeytab[secret-operator documentation].
1515

16-
If the Spark application processes data from a kerberized Hadoop cluster, follow the xref:hdfs-operator:usage-guide:security.adoc[HDFS operator guide] to configure HDFS with Kerberos.
16+
For details on HDFS and Kerberos, see the xref:hdfs-operator:usage-guide:security.adoc[HDFS operator guide].
1717

18-
This guide makes use of a SecretClass named `kerberos-default`. It is assumed that this class exists and is configured with a `kerberosBackend`.
18+
This guide makes use of a SecretClass named `kerberos`. It is assumed that this class exists and is configured with a `kerberosBackend`.
1919

2020
== Steps
2121

@@ -29,33 +29,42 @@ There are three steps to configure a Spark application to use Kerberos:
2929

3030
Install the keytab and the `krb5.conf` files in the Spark pods. The keytab file contains the credentials of the user that is used to authenticate with the Kerberos server. The `krb5.conf` file contains the configuration settings for the Kerberos client.
3131

32-
In the example below, the Stackable Secret Operator is used to provision the keytab via a volume claim. The `krb5.conf` file is mounted as a ConfigMap.
32+
In the example below, the Stackable Secret Operator is used to provision the keytab via a volume claim. For brevity the configuration shared by the job, driver and executor pods is only specified once and then referenced in all other places where needed.
3333

3434
[source,yaml]
3535
----
3636
...
37-
driver:
38-
config:
37+
job:
38+
config: &config
3939
volumeMounts:
4040
- name: kerberos
4141
mountPath: /stackable/kerberos <1>
42-
executor:
43-
config:
44-
volumeMounts:
4542
- name: kerberos
46-
mountPath: /stackable/kerberos <2>
43+
mountPath: /etc/krb5.conf <2>
44+
subPath: krb5.conf
45+
- name: hdfs-config
46+
mountPath: /stackable/config/hdfs <3>
47+
envOverrides:
48+
HADOOP_CONF_DIR: /stackable/config/hdfs
49+
50+
driver:
51+
config: *config
52+
53+
executor:
54+
config: *config
55+
4756
volumes:
48-
- name: kerberos-config
57+
- name: hdfs-config <4>
4958
configMap:
50-
name: krb5-kdc <3>
59+
name: hdfs
5160
- name: kerberos
5261
ephemeral:
5362
volumeClaimTemplate:
5463
metadata:
5564
annotations:
56-
secrets.stackable.tech/class: kerberos-default <4>
57-
secrets.stackable.tech/scope: service=spark-teragen <5>
58-
secrets.stackable.tech/kerberos.service.names: testuser <6>
65+
secrets.stackable.tech/class: kerberos <5>
66+
secrets.stackable.tech/scope: service=spark <6>
67+
secrets.stackable.tech/kerberos.service.names: spark <7>
5968
spec:
6069
storageClassName: secrets.stackable.tech
6170
accessModes:
@@ -64,100 +73,25 @@ volumes:
6473
requests:
6574
storage: "1"
6675
----
67-
<1> Mount the keytab volume in the driver pod.
68-
<2> Mount the keytab volume in the executor pods.
69-
<3> Mount the `krb5.conf` file as a ConfigMap.
70-
<4> Name of the Secret class used to provision the keytab.
71-
<5> Scope of the Secret.
72-
<6> Name of the user for which the keytab is provisioned.
73-
74-
75-
=== Job pod
76-
77-
Install the keytab and the `krb5.conf` files in the Spark `job` pod. This must be currently done via pod overrides. This is because the Spark application volumes are not currently visible to the `job` pod. We hope to address this limitation in a future release.
78-
79-
[source,yaml]
80-
----
81-
job:
82-
podOverrides:
83-
spec:
84-
volumes:
85-
- name: kerberos-config
86-
configMap:
87-
name: krb5-kdc <1>
88-
- name: kerberos
89-
ephemeral:
90-
volumeClaimTemplate:
91-
metadata:
92-
annotations:
93-
secrets.stackable.tech/class: kerberos-default <2>
94-
secrets.stackable.tech/scope: service=spark-teragen <3>
95-
secrets.stackable.tech/kerberos.service.names: testuser <4>
96-
spec:
97-
storageClassName: secrets.stackable.tech
98-
accessModes:
99-
- ReadWriteOnce
100-
resources:
101-
requests:
102-
storage: "1"
103-
containers:
104-
- name: spark-submit
105-
volumeMounts:
106-
- name: kerberos <5>
107-
mountPath: /stackable/kerberos
108-
----
109-
<1> Mount the `krb5.conf` file as a ConfigMap.
110-
<2> Name of the Secret class used to provision the keytab.
111-
<3> Scope of the Secret.
112-
<4> Name of the user for which the keytab is provisioned.
113-
<5> Mount the keytab volume in the job pod.
114-
76+
<1> Mount the keytab from the kerberos volume.
77+
<2> Mount the `krb5.conf` file from the kerberos volume.
78+
<3> Mount the Hadoop configuration files from the `hdfs-config` module.
79+
<4> Hadoop configuration files as published by the Hdfs operator.
80+
<5> Name of the Secret class used to provision the keytab.
81+
<6> Scope of the Secret.
82+
<7> Name of the user for which the keytab is provisioned.
11583

11684

11785
=== Spark application
11886

11987
Instruct the Spark application to use Kerberos by setting the `spark.kerberos.keytab` and `spark.kerberos.principal` properties in the `SparkApplication` CRD.
12088

121-
Finally, instruct Spark to use the keytab and `krb5.conf` files provisioned in the previous steps.
122-
12389
[source,yaml]
12490
----
12591
sparkConf:
12692
"spark.kerberos.keytab": "/stackable/kerberos/keytab" <1>
127-
"spark.kerberos.principal": "testuser/[email protected]" <2>
128-
"spark.driver.extraJavaOptions": "-Djava.security.krb5.conf=/stackable/kerberos/krb5.conf" <3>
129-
"spark.executor.extraJavaOptions": "-Djava.security.krb5.conf=/stackable/kerberos/krb5.conf" <4>
93+
"spark.kerberos.principal": "spark/[email protected]" <2>
13094
----
13195
<1> Location of the keytab file.
132-
<2> Principal name. This needs to have the format `<SERVICE_NAME>.default.svc.cluster.local@<REALM>` where `SERVICE_NAME` matches the volume claim annotation `secrets.stackable.tech/kerberos.service.names` and `REALM` must be `CLUSTER.LOCAL`.
133-
<3> Location of the Kerberos configuration for the application driver.
134-
<4> Location of the Kerberos configuration for the application executors.
135-
136-
=== Hadoop
137-
138-
When reading and writing data from a kerberized Hadoop cluster, a the HDFS discovery map must mounted the `SparkApplication` pods as follows:
139-
140-
For the driver and executor pods:
141-
142-
[source,yaml]
143-
----
144-
...
145-
driver:
146-
config:
147-
volumeMounts:
148-
- name: hdfs-config
149-
mountPath: /etc/hadoop/conf <1>
150-
executor:
151-
config:
152-
volumeMounts:
153-
- name: hdfs-config
154-
mountPath: /etc/hadoop/conf <2>
155-
volumes:
156-
- name: hdfs-config
157-
configMap:
158-
name: hdfs-discovery-cm <3>
159-
----
160-
<1> Location of the HDFS configuration for the driver.
161-
<2> Location of the HDFS configuration for the executors.
162-
<3> Name of the HDFS discovery ConfigMap as published by the HDFS operator.
96+
<2> Principal name. This needs to have the format `<SERVICE_NAME>.default.svc.cluster.local@<REALM>` where `SERVICE_NAME` matches the volume claim annotation `secrets.stackable.tech/kerberos.service.names` and `REALM` must be `CLUSTER.LOCAL` unless a different realm was used explicitly. In that case, the `KERBEROS_REALM` environment variable must also be set accordingly.
16397

0 commit comments

Comments
 (0)