fix(keda): add defensive length check when accessing service Ports#3813
fix(keda): add defensive length check when accessing service Ports#3813Elvand-Lie wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Elvand-Lie 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 |
|
Hi @Elvand-Lie. Thanks for your PR. I'm waiting for a knative member to verify that this patch is reasonable to test. If it is, they should reply with Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3813 +/- ##
==========================================
- Coverage 53.42% 53.41% -0.02%
==========================================
Files 200 200
Lines 23426 23429 +3
==========================================
- Hits 12515 12514 -1
- Misses 9655 9658 +3
- Partials 1256 1257 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
In pkg/keda/deployer.go, the code accesses service.Spec.Ports[0].Port to build the HTTP ScaledObject. The service object is fetched live from the Kubernetes cluster. While the upstream deployers will always generate a service with exactly one port during normal operations, this code lacks a defensive length check on the Ports slice. If a user or an external controller manually modifies the service in the cluster to remove its ports, the KEDA deployer will crash with an out of bounds panic during reconciliation. Added a defensive check for len(service.Spec.Ports) > 0 to prevent this. Fixes knative#3812
e83ad6a to
9092f58
Compare
Problem
In pkg/keda/deployer.go, the code accesses service.Spec.Ports[0].Port to build the HTTP ScaledObject. The service object is fetched live from the Kubernetes cluster.
While the upstream deployers will always generate a service with exactly one port during normal operations, this code lacks a defensive length check on the Ports slice. If a user or an external controller manually modifies the service in the cluster to remove its ports, the KEDA deployer will crash with an out of bounds panic during reconciliation.
Fix
Added a defensive check for len(service.Spec.Ports) > 0 to prevent this.
Fixes #3812