You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Cherry pick: #58729
Signed-off-by: Andrew Sy Kim <[email protected]>
Signed-off-by: Edward Oakes <[email protected]>
Co-authored-by: Andrew Sy Kim <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
# Configure Ray clusters with authentication and access control using KubeRay
3
+
# Configure Ray clusters to use token authentication
4
4
5
-
This guide demonstrates how to secure Ray clusters deployed with KubeRay by enabling authentication and access control using Kubernetes Role-Based Access Control (RBAC).
6
-
7
-
> **Note:** This guide is only supported for the RayCluster custom resource.
5
+
This guide demonstrates how to enable Ray token authentication with KubeRay.
8
6
9
7
## Prerequisites
10
8
11
9
* A Kubernetes cluster. This guide uses GKE, but the concepts apply to other Kubernetes distributions.
12
10
*`kubectl` installed and configured to interact with your cluster.
13
11
*`gcloud` CLI installed and configured, if using GKE.
* A `RayCluster` resource with a `kube-rbac-proxy` sidecar container on the Head Pod. This proxy handles authentication and authorization.
40
-
* A `ConfigMap` for kube-rbac-proxy, containing resource attributes required for authorization.
41
-
* A `ServiceAccount`, `ClusterRole`, and `ClusterRoleBinding` that allow the `kube-rbac-proxy` to access the Kubernetes TokenReview and SubjectAccessReview APIs.
42
-
43
-
## Verify initial unauthorized access
35
+
When enabled, the KubeRay operator will:
36
+
* Create a Kubernetes Secret containing a randomly generated token.
37
+
* Automatically set the `RAY_AUTH_TOKEN` and `RAY_AUTH_MODE` environment variables on all Ray containers.
44
38
45
-
Attempt to submit a Ray job to the cluster to verify that authentication is required. You should receive a `401 Unauthorized` error:
39
+
If you are using a KubeRay version older than v1.5.1, you can enable token authentication by creating a Kubernetes Secret containing
40
+
your token and configuring the `RAY_AUTH_MODE` and `RAY_AUTH_TOKEN` environment variables.
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: http://localhost:8265/api/version
57
-
```
58
-
59
-
This error confirms that the Ray cluster requires authentication.
60
-
61
-
## Configure Kubernetes RBAC for access control
62
-
63
-
To access the RayCluster, you need:
64
-
***Authentication:** Provide a valid authentication token (e.g., a Kubernetes service account token or a cloud IAM token) in the request headers.
65
-
***Authorization:** Your authenticated user or service account must have the necessary Kubernetes RBAC permissions to access the `RayCluster` resource.
66
-
67
-
This guide demonstrates granting access using a Kubernetes service account, but the same principles apply to individual Kubernetes users or cloud IAM users.
68
-
69
-
### Create a Kubernetes service account
70
-
71
-
Create a service account that represents your Ray job submitter:
72
-
73
-
```bash
74
-
kubectl create serviceaccount ray-user
75
-
```
47
+
## Verify initial unauthenticated access
76
48
77
-
Confirm that the service account currently can't access the `RayCluster` resource:
49
+
Attempt to submit a Ray job to the cluster to verify that authentication is required. You should receive a `401 Unauthorized` error:
78
50
79
51
```bash
80
-
kubectl auth can-i get rayclusters.ray.io/ray-cluster-with-auth --as=system:serviceaccount:default:ray-user
81
-
```
82
-
83
-
The output should be `no`.
84
-
85
-
### Grant access using Kubernetes RBAC
86
-
87
-
Create a `Role` and `RoleBinding` to grant the necessary permissions to the `ray-user` service account:
Most cloud providers allow you to authenticate to the Kubernetes cluster as your cloud IAM user. This method is a convenient way to interact with the cluster without managing separate Kubernetes credentials.
The job should succeed if your cloud user has the necessary Kubernetes RBAC permissions. You may need to configure additional RBAC rules for your cloud user.
198
-
199
-
## View the Ray dashboard (optional)
200
-
201
-
To view the Ray dashboard from your browser, first configure port-forwarding:
120
+
Then open `localhost:8265`in your browser. You will be prompted to provide the auth token for the cluster, which can be retrieved with:
kubectl get secrets ray-cluster-with-auth --template={{.data.auth_token}} | base64 -d
205
124
```
206
-
207
-
Use a Chrome extension like [Requestly](https://requestly.com/) to automatically add authorization headers to requests for the dashboard endpoint `http://localhost:8265`. The authorization header format is: `Authorization: Bearer <token>`.
0 commit comments