โ† Back to Pull requests

๐Ÿ› fix: awsmachinetemplate: use cluster-scoped credentials for ec2 clients #6282

Open
unknown opened this pull request with 448 lines diff across 5 files
View on GitHub
unknown unknown commented on Oct 01, 2026 22:30 UTC
Author

<!-- Thanks for this PR! If this is your first PR please read the [contributing guide](../CONTRIBUTING.md) -->
<!-- If this PR is still work-in-progress and is being open for visibility please prefix the title with WIP: -->

What type of PR is this?
/kind bug

<!--
Add one of the following kinds:
/kind feature
/kind bug
/kind api-change
/kind cleanup
/kind deprecation
/kind design
/kind documentation
/kind failing-test
/kind flake
/kind regression
/kind support
-->

What this PR does / why we need it:

<!-- Enter a description of the change and why this change is needed -->

Replace the global controller AWS session with cluster-scoped credentials when querying EC2 for capacity and nodeInfo.

  • For AWSCluster, ClusterScope is used

  • For AWSManagedControlPlane, ManagedControlPlaneScope is used.
  • This ensure EC2 API calls are scoped correctly to the cluster's account ID in multi-account setup. This is a follow-up for concerns in https://github.com/kubernetes-sigs/cluster-api-provider-aws/pull/6196#pullrequestreview-5366793598 and https://github.com/kubernetes-sigs/cluster-api-provider-aws/pull/6196#discussion_r4136216528.

    Which issue(s) this PR fixes _(optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged)_:
    Fixes #6232

    Special notes for your reviewer:

    I couldn't find the reasons for using global-scoped credentials in the original commits, but the current awsmachinetemplate controller code has a comment:

    // Create global scope for this region

    // Reference: exp/instancestate/awsinstancestate_controller.go:68-76

    As far as I understand, the awsinstancestate controller manages an SQS queue in the management (controller) account; thus, the global scope is correct there.

    However, for awsmachinetemplate, the machine resources (i.e. instance types, AMIs) "live" in the cluster account instead. Therefore, using cluster-scoped credentials should be the right approach, and the comment is "incorrect".

    AI Usage:

    <!-- Declare if this PR has benefited from AI assistance in any way. Whether that's Cursor, Claude, Copilot, Codex, a local LLM, or another other AI assistant. If AI has been used please try to provide as much information as possible.

    NOTE: basic autocompletion doesn't need to be declared.

    If no AI assistance was used then used, write "None".
    -->

    I had help from Claude Code (model claude-opus-4-6) for code suggestions, and code reviews.

    Checklist:

    <!-- Put an "X" character inside the brackets of each completed task. Some may be optional depending on the PR in which case these can be deleted

    Please add an icon to the title of this PR, the icon will be either โš ๏ธ (:warning:, major or breaking changes), โœจ (:sparkles:, feature additions), ๐Ÿ› (:bug:, patch and bugfixes), ๐Ÿ“– (:book:, documentation or proposals), or ๐ŸŒฑ (:seedling:, minor or other)
    -->

  • squashed commits

  • includes documentation

  • includes AI generated content

  • includes emoji in title

  • adds unit tests

  • adds or updates e2e tests
  • Release note:

    <!-- Write your release note:
    1. Enter your extended release note in the below block. If the PR requires additional action from users switching to the new release, include the string "action required".
    2. If no release note is required, just write "NONE".
    -->

    ``release-note
    fix: AWSMachineTemplate controller to construct EC2 client from cluster-scoped credentials instead of the global-scoped one.
    ``

    Diff: 448 lines (+336 / -112) across 5 files Reviewer: tthvo Review duration: 27427m
    All Vouch review confidence checks passed
    Residual risk 0.24 = Change Risk (0.45) ร— (1 โˆ’ Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 ยท Change Risk (XGBoost)
    Score: 0.45 ยท 448 lines diff across 5 files
    0.45
    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.365
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #6282"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    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: 45.4% (MEDIUM) ยท Higher = larger blast radius
    45.4%
    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: 24.2% ยท Safe to merge
    24.2%