← Back to Pull requests

fix(clusterapi): check RBAC before syncing infrastructure template cache #10619

Open
unknown opened this pull request with 327 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 03, 2026 18:52 UTC
Author

What type of PR is this?

/kind bug

What this PR does / why we need it:

When getInfrastructureResource looks up an infrastructure machine template (from CanScaleFromZero -> InstanceCapacity or TemplateNodeInfo -> InstanceCapacity / InstanceSystemInfo), it creates and starts a dynamic informer via c.managementInformerFactory.ForResource(resource) and waits on cache.WaitForCacheSync(c.stopChannel, informer.Informer().HasSynced).

If the Cluster Autoscaler ServiceAccount does not have RBAC permissions to list and watch the infrastructure machine template resource (for example, when capacity is configured via capacity.cluster-autoscaler.kubernetes.io/ annotations on the MachineDeployment/MachineSet, or when scaling from non-zero replicas without scale-from-zero RBAC), the reflector's ListAndWatch fails with 403 Forbidden, informer.Informer().HasSynced() never becomes true, and cache.WaitForCacheSync blocks indefinitely until c.stopChannel is closed. Because this happens synchronously on the main autoscaler loop, all scale-up and scale-down operations stall across the cluster.

This change follows the approach from #6498 by checking list and watch permissions on the management cluster (in the namespace scope watched by managementInformerFactory) via SelfSubjectAccessReview with a 30s request timeout before starting and syncing the infrastructure resource informer, caching allowed and denied decisions for 1 minute (infraAccessCacheTTL, matching kindVersionCacheTTL) across wrapper rebuilds. When access is not allowed, getInfrastructureResource returns nil, nil, allowing InstanceCapacity() to fall back to capacity.cluster-autoscaler.kubernetes.io/ annotations when present or return empty capacity without blocking the reconciliation loop.

Which issue(s) this PR fixes:

Fixes #10416
Fixes #6490

Special notes for your reviewer:

Builds on #6498 by @jackfrancis, adding the SelfSubjectAccessReview reactor in NewTestMachineController (since fakekube.NewSimpleClientset() returns Status.Allowed: false by default for SelfSubjectAccessReview objects) along with unit tests covering denied list/watch access, namespace-scoped grants, and access-review caching.

Does this PR introduce a user-facing change?

``release-note
Fix Cluster API provider hanging indefinitely in WaitForCacheSync when the autoscaler lacks RBAC permissions to list or watch infrastructure machine templates.


#### Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

docs

``

Diff: 327 lines (+245 / -82) across 4 files Reviewer: elmiko Review duration: 43560m
All Vouch review confidence checks passed
Residual risk 0.35 = Change Risk (0.65) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.65 · 327 lines diff across 4 files
0.65
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
0.02
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
46%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.347
Shallow Review Depth shallow_review_depth
0.344
Sensitive Paths sensitive_paths
0.065
Real PR Conversation Timeline
1 comments
"Review active on #10619"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 46.7% reviewed sensitive_module
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 65.2% (HIGH) · Higher = larger blast radius
65.2%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 46.7% · Lower = rushed or shallow review
46.7%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 34.8% · Safe to merge
34.8%