Skip to content

fix(router): add auth header for workload manager#186

Merged
volcano-sh-bot merged 2 commits intovolcano-sh:mainfrom
acsoto:fix-router-wm-auth-header
Feb 6, 2026
Merged

fix(router): add auth header for workload manager#186
volcano-sh-bot merged 2 commits intovolcano-sh:mainfrom
acsoto:fix-router-wm-auth-header

Conversation

@acsoto
Copy link
Copy Markdown
Member

@acsoto acsoto commented Jan 30, 2026

What type of PR is this?

/kind bug

What this PR does / why we need it:
Adds Authorization header for Router->Workload Manager sandbox creation using service account token, so WM auth works when enabled.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:
Router now reads /var/run/secrets/kubernetes.io/serviceaccount/token for WM calls.

Does this PR introduce a user-facing change?:

NONE

Copilot AI review requested due to automatic review settings January 30, 2026 08:04
@volcano-sh-bot volcano-sh-bot added the kind/bug Something isn't working label Jan 30, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @acsoto, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a critical security enhancement by implementing an authentication mechanism for communications between the Router and the Workload Manager. It ensures that sandbox creation requests are properly authorized, allowing the Workload Manager to enforce its security policies by utilizing either an API token or a Kubernetes service account token.

Highlights

  • Authentication Header Addition: An 'Authorization' header is now included in requests from the Router to the Workload Manager for sandbox creation.
  • Flexible Token Sourcing: The authentication token is sourced from either the 'API_TOKEN' environment variable or a Kubernetes service account token file ('/var/run/secrets/kubernetes.io/serviceaccount/token').
  • Enabling WM Authentication: This change ensures that Workload Manager authentication functions correctly when enabled.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

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

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 correctly adds an Authorization header to requests sent from the router to the workload manager, which is an important security improvement. The implementation correctly prioritizes the API_TOKEN environment variable before falling back to the service account token. I have one suggestion to simplify the error handling logic in loadWorkloadManagerAuthToken. However, a significant concern is the absence of unit tests for this new functionality. Tests should be added to verify that the token is loaded correctly from both sources and that the Authorization header is properly set on outgoing requests.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds authentication support for Router->Workload Manager communication by including an Authorization header with a Bearer token. The token is sourced from either the API_TOKEN environment variable or a Kubernetes service account token file.

Changes:

  • Added loadWorkloadManagerAuthToken() function to read auth tokens from environment or service account file
  • Modified createSandbox() to set Authorization header when token is available
  • Defined constant for standard Kubernetes service account token path

@acsoto acsoto force-pushed the fix-router-wm-auth-header branch from 29056c2 to 7ffe317 Compare January 30, 2026 08:10
@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Jan 30, 2026

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 36.00%. Comparing base (845b798) to head (da42071).
⚠️ Report is 44 commits behind head on main.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #186      +/-   ##
==========================================
+ Coverage   35.60%   36.00%   +0.39%     
==========================================
  Files          29       29              
  Lines        2533     2558      +25     
==========================================
+ Hits          902      921      +19     
- Misses       1505     1511       +6     
  Partials      126      126              
Flag Coverage Δ
unittests 36.00% <100.00%> (+0.39%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@acsoto acsoto force-pushed the fix-router-wm-auth-header branch from 7ffe317 to b14c363 Compare January 30, 2026 08:18
Copilot AI review requested due to automatic review settings January 30, 2026 08:18
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Signed-off-by: Zhou Zihang <z@mcac.cc>
@acsoto acsoto force-pushed the fix-router-wm-auth-header branch from b14c363 to 359fbe3 Compare January 30, 2026 08:26
hzxuzhonghu
hzxuzhonghu previously approved these changes Jan 31, 2026
Copy link
Copy Markdown
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

Thanks for the fix! Adding the Authorization header from API_TOKEN / service account token makes sense, and the tests cover env/file/missing/error cases well.

Non-blocking suggestions:

  • Consider caching the token read if sandbox creation is frequent.
  • If token file is missing in some deployments, a lower-verbosity log might avoid noise.

LGTM otherwise.

return nil, fmt.Errorf("failed to create HTTP request: %w", err)
}
req.Header.Set("Content-Type", "application/json")
if token := loadWorkloadManagerAuthToken(); token != "" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So with this PR, the router will created session for us by default and the 401 issues I mentioned before will not happen again?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think so because SDK uses this logic sdk-python/agentcube/clients/control_plane.py to create

if token:
    self.session.headers["Authorization"] = f"Bearer {token}"

}

func loadWorkloadManagerAuthToken() string {
if token := strings.TrimSpace(os.Getenv("API_TOKEN")); token != "" {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not complete, how does this work with workloadmanager

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

SDK uses the same logic sdk-python/agentcube/clients/control_plane.py

token_path = "/var/run/secrets/kubernetes.io/serviceaccount/token"
token = auth_token or os.getenv("API_TOKEN") or read_token_from_file(token_path)

...
if token:
    self.session.headers["Authorization"] = f"Bearer {token}"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

WM pkg/workloadmanager/auth.go

authHeader := c.GetHeader("Authorization")
...
parts := strings.SplitN(authHeader, " ", 2)
if len(parts) != 2 || parts[0] != "Bearer" { ... }
token := parts[1]

authenticated, serviceAccount, err := s.validateServiceAccountToken(...)

tokenReview := &authv1.TokenReview{ Spec: authv1.TokenReviewSpec{ Token: token } }
result, err := s.k8sClient.clientset.AuthenticationV1().TokenReviews().Create(...)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I mean if the API_TOKEN is injected from a thirdparty identity provider, how should workload manager validate it

Copy link
Copy Markdown
Member Author

@acsoto acsoto Feb 2, 2026

Choose a reason for hiding this comment

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

That's a valid point. After reviewing the implementation, I’ve confirmed that WM now exclusively accepts K8s TokenReview with system:serviceaccount:*. Both the Router and SDK currently utilize ServiceAccount tokens. The API_TOKEN mentioned in previous versions of the SDK and documentation was a legacy feature; I have removed it to prevent further confusion.

Copilot AI review requested due to automatic review settings February 2, 2026 13:19
@acsoto acsoto force-pushed the fix-router-wm-auth-header branch from 6196507 to efa073c Compare February 2, 2026 13:20
@acsoto acsoto force-pushed the fix-router-wm-auth-header branch from efa073c to da42071 Compare February 2, 2026 13:22
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

@acsoto
Copy link
Copy Markdown
Member Author

acsoto commented Feb 4, 2026

Legacy API_TOKEN has been deleted. Now SDK and router will bear K8s token in header to reach wm.
@hzxuzhonghu @YaoZengzeng Please take a look

@hzxuzhonghu
Copy link
Copy Markdown
Member

/lgtm

@hzxuzhonghu
Copy link
Copy Markdown
Member

/approve

@volcano-sh-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hzxuzhonghu

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot volcano-sh-bot merged commit 7a6d6ff into volcano-sh:main Feb 6, 2026
14 checks passed
@acsoto acsoto deleted the fix-router-wm-auth-header branch February 6, 2026 06:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants