@@ -230,22 +230,41 @@ def generate_tls_cert(cluster_name, namespace, days=30):
230
230
231
231
def export_env (cluster_name , namespace ):
232
232
"""
233
- Sets environment variables to configure TLS for a Ray cluster.
233
+ Sets environment variables to configure TLS for a Ray client connection when mTLS is enabled.
234
+
235
+ The `tls.crt` and `tls.key` files generated by `generate_tls_cert` are client-side credentials,
236
+ signed by the cluster's CA. `ca.crt` is the cluster's CA certificate.
237
+
238
+ This function sets:
239
+ - `RAY_USE_TLS="1"` to enable TLS.
240
+ - `RAY_TLS_CA_CERT` to the path of `ca.crt` for server certificate verification.
241
+ - `RAY_TLS_CLIENT_CERT` and `RAY_TLS_CLIENT_KEY` to the paths of the client's `tls.crt`
242
+ and `tls.key` respectively, for client authentication by the server.
243
+ - `RAY_TLS_SERVER_CERT` and `RAY_TLS_SERVER_KEY` are also set to the client's `tls.crt`
244
+ and `tls.key`. This is maintained based on previous observations that these might be
245
+ utilized by certain Ray client setups, ensuring broad compatibility.
234
246
235
247
Args:
236
248
cluster_name (str):
237
249
The name of the Ray cluster.
238
250
namespace (str):
239
251
The Kubernetes namespace where the Ray cluster is located.
240
-
241
- Environment Variables Set:
242
- - RAY_USE_TLS: Enables TLS for Ray.
243
- - RAY_TLS_SERVER_CERT: Path to the TLS server certificate.
244
- - RAY_TLS_SERVER_KEY: Path to the TLS server private key.
245
- - RAY_TLS_CA_CERT: Path to the CA certificate.
246
252
"""
247
253
tls_dir = os .path .join (os .getcwd (), f"tls-{ cluster_name } -{ namespace } " )
254
+ client_cert_path = os .path .join (tls_dir , "tls.crt" )
255
+ client_key_path = os .path .join (tls_dir , "tls.key" )
256
+ ca_cert_path = os .path .join (tls_dir , "ca.crt" )
257
+
248
258
os .environ ["RAY_USE_TLS" ] = "1"
249
- os .environ ["RAY_TLS_SERVER_CERT" ] = os .path .join (tls_dir , "tls.crt" )
250
- os .environ ["RAY_TLS_SERVER_KEY" ] = os .path .join (tls_dir , "tls.key" )
251
- os .environ ["RAY_TLS_CA_CERT" ] = os .path .join (tls_dir , "ca.crt" )
259
+
260
+ # CA certificate for verifying the server
261
+ os .environ ["RAY_TLS_CA_CERT" ] = ca_cert_path
262
+
263
+ # Standard mTLS client variables: client's own certificate and key
264
+ os .environ ["RAY_TLS_CLIENT_CERT" ] = client_cert_path
265
+ os .environ ["RAY_TLS_CLIENT_KEY" ] = client_key_path
266
+
267
+ # Also set RAY_TLS_SERVER_CERT/KEY to client cert/key, maintaining previous setup style
268
+ # while ensuring client certs are explicitly available via RAY_TLS_CLIENT_*
269
+ os .environ ["RAY_TLS_SERVER_CERT" ] = client_cert_path
270
+ os .environ ["RAY_TLS_SERVER_KEY" ] = client_key_path
0 commit comments