-
Notifications
You must be signed in to change notification settings - Fork 650
Add support for Ray token auth #4179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,6 +132,7 @@ rules: | |
| resources: | ||
| - events | ||
| - pods/status | ||
| - secrets | ||
| - services | ||
| verbs: | ||
| - create | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,7 @@ rules: | |
| resources: | ||
| - events | ||
| - pods/status | ||
| - secrets | ||
| - services | ||
| verbs: | ||
| - create | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -221,6 +221,10 @@ func DefaultHeadPodTemplate(ctx context.Context, instance rayv1.RayCluster, head | |||||||||
| podTemplate.Spec.Containers[utils.RayContainerIndex].Ports = append(podTemplate.Spec.Containers[utils.RayContainerIndex].Ports, metricsPort) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if utils.IsAuthEnabled(&instance.Spec) { | ||||||||||
| setTokenAuthEnvVars(instance.Name, &podTemplate) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return podTemplate | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
@@ -236,6 +240,47 @@ func setAutoscalerV2EnvVars(podTemplate *corev1.PodTemplateSpec) { | |||||||||
| }) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| // setTokenAuthEnvVars sets environment variables required for Ray token authentication | ||||||||||
| func setTokenAuthEnvVars(clusterName string, podTemplate *corev1.PodTemplateSpec) { | ||||||||||
| podTemplate.Spec.Containers[utils.RayContainerIndex].Env = append(podTemplate.Spec.Containers[utils.RayContainerIndex].Env, corev1.EnvVar{ | ||||||||||
| Name: utils.RAY_AUTH_MODE_ENV_VAR, | ||||||||||
| Value: "token", | ||||||||||
| }) | ||||||||||
|
Comment on lines
+247
to
+248
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| secretName := utils.CheckName(clusterName) | ||||||||||
| podTemplate.Spec.Containers[utils.RayContainerIndex].Env = append(podTemplate.Spec.Containers[utils.RayContainerIndex].Env, corev1.EnvVar{ | ||||||||||
| Name: utils.RAY_AUTH_TOKEN_ENV_VAR, | ||||||||||
| ValueFrom: &corev1.EnvVarSource{ | ||||||||||
| SecretKeyRef: &corev1.SecretKeySelector{ | ||||||||||
| LocalObjectReference: corev1.LocalObjectReference{Name: secretName}, | ||||||||||
| Key: utils.RAY_AUTH_TOKEN_SECRET_KEY, | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| }) | ||||||||||
|
|
||||||||||
| // Configure auth token for wait-gcs-ready init container if it exists | ||||||||||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sampan-s-nayak is it expected for "ray healh-check` to require auth token?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is ray autoscaler also require auth token?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch, I'll add this logic shortly |
||||||||||
| for i, initContainer := range podTemplate.Spec.InitContainers { | ||||||||||
| if initContainer.Name != "wait-gcs-ready" { | ||||||||||
| continue | ||||||||||
| } | ||||||||||
|
|
||||||||||
| podTemplate.Spec.InitContainers[i].Env = append(podTemplate.Spec.InitContainers[i].Env, corev1.EnvVar{ | ||||||||||
| Name: utils.RAY_AUTH_MODE_ENV_VAR, | ||||||||||
| Value: "token", | ||||||||||
| }) | ||||||||||
|
|
||||||||||
| podTemplate.Spec.InitContainers[i].Env = append(podTemplate.Spec.InitContainers[i].Env, corev1.EnvVar{ | ||||||||||
| Name: utils.RAY_AUTH_TOKEN_ENV_VAR, | ||||||||||
| ValueFrom: &corev1.EnvVarSource{ | ||||||||||
| SecretKeyRef: &corev1.SecretKeySelector{ | ||||||||||
| LocalObjectReference: corev1.LocalObjectReference{Name: secretName}, | ||||||||||
| Key: utils.RAY_AUTH_TOKEN_SECRET_KEY, | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| }) | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| func getEnableInitContainerInjection() bool { | ||||||||||
| if s := os.Getenv(EnableInitContainerInjectionEnvKey); strings.ToLower(s) == "false" { | ||||||||||
| return false | ||||||||||
|
|
@@ -358,6 +403,10 @@ func DefaultWorkerPodTemplate(ctx context.Context, instance rayv1.RayCluster, wo | |||||||||
| podTemplate.Spec.RestartPolicy = corev1.RestartPolicyNever | ||||||||||
| } | ||||||||||
|
|
||||||||||
| if utils.IsAuthEnabled(&instance.Spec) { | ||||||||||
| setTokenAuthEnvVars(instance.Name, &podTemplate) | ||||||||||
| } | ||||||||||
|
|
||||||||||
| return podTemplate | ||||||||||
| } | ||||||||||
|
|
||||||||||
|
|
||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it’s better to set the default to
disabled, as token authentication requires Ray >= 2.51.0 and some users may still be on older pinned versions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's worth mentioning the mode only defaults to
tokenwhenauthOptions != nil