Skip to content

[core] Use dedicated service account path for Ray auth tokens#60409

Merged
edoakes merged 1 commit into
ray-project:masterfrom
andrewsykim:update-ray-token-path
Jan 22, 2026
Merged

[core] Use dedicated service account path for Ray auth tokens#60409
edoakes merged 1 commit into
ray-project:masterfrom
andrewsykim:update-ray-token-path

Conversation

@andrewsykim

Copy link
Copy Markdown
Member

Description

This PR updates the default service account token path for Raylet from /var/run/secrets/kubernetes.io/serviceaccount/token to /var/run/secrets/ray.io/serviceaccount/token. This is to avoid using the same token that would be used for Kubernetes API access.

Raylet pods can be configured with additional audience-specific tokens using a feature called serviceAccountToken projected volumes. E.g.:

spec:
  containers:
  - name: ray-worker
    ...
    volumeMounts:
    - name: token-vol
      mountPath: "/var/run/secrets/ray.io/service-account"
      readOnly: true
  serviceAccountName: default
  volumes:
  - name: token-vol
    projected:
      sources:
      - serviceAccountToken:
          audience: ray.io
          expirationSeconds: 3600
          path: token

Related issues

Link related issues: "Fixes #1234", "Closes #1234", or "Related to #1234".

Additional information

Optional: Add implementation details, API changes, usage examples, screenshots, etc.

@andrewsykim andrewsykim requested a review from a team as a code owner January 22, 2026 14:51
@andrewsykim

Copy link
Copy Markdown
Member Author

@sampan-s-nayak PTAL

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the service account token path to use a dedicated path for Ray, which is a good security practice. The changes correctly replace the old token path constant with a new one across the codebase. My review includes a few suggestions to improve code clarity by renaming variables that now refer to this new Ray-specific token path. Overall, the changes are solid and achieve the intended goal.

@@ -153,7 +153,7 @@ TokenLoadResult AuthenticationTokenLoader::TryLoadTokenFromSources() {

// Precedence 3 (ENABLE_K8S_TOKEN_AUTH only): Load Kubernetes service account token
if (IsK8sTokenAuthEnabled()) {
const std::string k8s_token_path(k8s::kK8sSaTokenPath);
const std::string k8s_token_path(k8s::kRaySaTokenPath);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While this change is correct, the variable name k8s_token_path is now a bit misleading as it points to the Ray-specific service account token path (kRaySaTokenPath) instead of the generic Kubernetes one. For improved code clarity and maintainability, consider renaming this variable to something like ray_sa_token_path and updating its usages within this if block.

Comment thread src/ray/rpc/authentication/k8s_util.cc Outdated
Comment on lines 72 to 73
std::string k8s_sa_token = ReadFile(kRaySaTokenPath);
if (k8s_sa_token.empty()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better clarity, since we are now reading the Ray-specific service account token, consider renaming the variable k8s_sa_token to ray_sa_token to reflect this change.

Suggested change
std::string k8s_sa_token = ReadFile(kRaySaTokenPath);
if (k8s_sa_token.empty()) {
std::string ray_sa_token = ReadFile(kRaySaTokenPath);
if (ray_sa_token.empty()) {

Comment thread src/ray/rpc/authentication/k8s_util.cc Outdated
@@ -91,7 +91,7 @@ void InitK8sClientConfig() {
bool K8sApiPost(const std::string &path,
const nlohmann::json &body,
nlohmann::json &response_json) {
static std::string k8s_sa_token = ReadFile(kK8sSaTokenPath);
static std::string k8s_sa_token = ReadFile(kRaySaTokenPath);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The static variable k8s_sa_token is now initialized from kRaySaTokenPath, which is the path to a Ray-specific token. To avoid confusion and improve clarity, please consider renaming k8s_sa_token to ray_sa_token and updating its usage within this function.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Comment thread src/ray/rpc/authentication/k8s_util.cc Outdated
Signed-off-by: Andrew Sy Kim <andrewsy@google.com>
@andrewsykim andrewsykim force-pushed the update-ray-token-path branch from 8c91a3a to 53253b8 Compare January 22, 2026 17:23
@ray-gardener ray-gardener Bot added core Issues that should be addressed in Ray Core community-contribution Contributed by the community labels Jan 22, 2026
@edoakes edoakes added the go add ONLY when ready to merge, run all tests label Jan 22, 2026
@edoakes edoakes enabled auto-merge (squash) January 22, 2026 21:40
@edoakes edoakes merged commit 1ca4899 into ray-project:master Jan 22, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community core Issues that should be addressed in Ray Core go add ONLY when ready to merge, run all tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ray fails to serialize self-reference objects

2 participants