fix: autoscaler use target's namespace if specified#797
fix: autoscaler use target's namespace if specified#797dblate wants to merge 1 commit intovolcano-sh:mainfrom
Conversation
Signed-off-by: yuhui06 <173983476@qq.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Summary of ChangesHello, 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 addresses a bug in the autoscaler's metric collection logic. It ensures that the autoscaler correctly identifies and uses the namespace of the target modelserving pod, rather than solely relying on the autoscaling policy binding's namespace. This change is crucial for scenarios where the target pod resides in a different namespace than the autoscaler itself, preventing incorrect pod location and ensuring accurate metric collection. Highlights
🧠 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. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Pull request overview
Updates autoscaler metric collection to correctly locate model-serving pods when the autoscaler’s namespace differs from the target workload’s namespace by preferring the target’s explicitly specified namespace.
Changes:
- Derive the metric-collection namespace from
target.TargetRef.Namespacewhen set. - Fall back to
binding.Namespacewhen the target reference doesn’t specify a namespace.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review. Take the survey.
There was a problem hiding this comment.
Code Review
This pull request modifies pkg/autoscaler/autoscaler/metric_collector.go to correctly determine the namespace for metric collection, prioritizing the namespace specified in the target.TargetRef and falling back to the AutoscalingPolicyBinding's namespace. While this change aligns with the expectation that targets can exist in different namespaces, it introduces a significant security risk related to cross-namespace access control. Specifically, the NewMetricCollector function now accepts a namespace from the target reference without verifying it against the binding's namespace, potentially allowing unauthorized users to scrape metrics from pods in namespaces they should not have access to. It is recommended to add a validation check to ensure the target namespace matches the binding's namespace or implement a robust authorization mechanism for cross-namespace references.
| namespace := target.TargetRef.Namespace | ||
| if namespace == "" { | ||
| namespace = binding.Namespace | ||
| } |
There was a problem hiding this comment.
The introduction of target.TargetRef.Namespace as a source for the collection namespace without validation creates a Broken Access Control vulnerability. An attacker who can create an AutoscalingPolicyBinding in one namespace can now target and collect metrics from pods in any other namespace across the cluster. Since the autoscaler controller typically operates with high privileges, this allows unauthorized cross-namespace data access. You should ensure that the target namespace is either empty or explicitly matches the namespace of the binding.
hzxuzhonghu
left a comment
There was a problem hiding this comment.
The target cannot be set a namespace != binding, i think we can validate it in the webhook, and not change this palce
If the target cannot be set a namespace != binding, I have a scenario and would like to ask for advice on the practical approach:
|
|
The controller can be deployed in any namespace, it has nothing to do with the api object. if |
|
@dblate Please update this PR |
What type of PR is this?
/kind bug
What this PR does / why we need it: When the namespace of the modelserving pod differs from that of the autoscaler, the namespace corresponding to the modelserving pod is used first to ensure the pod is correctly located.
Which issue(s) this PR fixes:
Fixes autoscaler, use target's namespace if specified
Special notes for your reviewer:
Does this PR introduce a user-facing change?: NONE