fix(cpo): diff SG permissions before AuthorizeSecurityGroupIngress - #8869
fix(cpo): diff SG permissions before AuthorizeSecurityGroupIngress#8869sdminonne wants to merge 1 commit into
Conversation
Move permission-diff logic from awsprivatelink controller to shared support/awsutil package and extend it to handle UserIdGroupPair rules in addition to IpRange rules. Apply the diff check in createAWSDefaultSecurityGroup so the operator only calls AuthorizeSecurityGroupIngress for genuinely missing rules instead of blindly upserting and relying on InvalidPermission.Duplicate errors, which pollute customer AWS CloudTrail logs. Closes: OCPBUGS-93738 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
📝 WalkthroughWalkthroughA new exported Sequence Diagram(s)No sequence diagram generated — the change is a refactor extracting shared utility logic without introducing new component interactions. 🚥 Pre-merge checks | ✅ 11✅ Passed checks (11 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sdminonne 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
support/awsutil/sg_test.go (1)
140-150: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueAssertions don't verify range/pair contents.
The comparison loop only checks
FromPort/ToPort/IpProtocol. Cases like "different group ID" pass solely on length+port, never asserting the returnedUserIdGroupPairs/IpRangescontent. Consider asserting the full entry (or usingreflect.DeepEqual/GomegaEqual) so a regression inequalUserIdGroupPairs/equalIPRangesfield comparison is caught.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@support/awsutil/sg_test.go` around lines 140 - 150, The test loop in sg_test.go only compares port/protocol fields and can miss regressions in the security group rule contents. Update the assertion around the result/tt.expected comparison in the relevant test to verify the full permission entry, including UserIdGroupPairs and IpRanges, not just FromPort/ToPort/IpProtocol. Use a full-struct equality check or explicit deep comparison so changes in equalUserIdGroupPairs and equalIPRanges are actually validated.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@support/awsutil/sg_test.go`:
- Around line 140-150: The test loop in sg_test.go only compares port/protocol
fields and can miss regressions in the security group rule contents. Update the
assertion around the result/tt.expected comparison in the relevant test to
verify the full permission entry, including UserIdGroupPairs and IpRanges, not
just FromPort/ToPort/IpProtocol. Use a full-struct equality check or explicit
deep comparison so changes in equalUserIdGroupPairs and equalIPRanges are
actually validated.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Central YAML (inherited)
Review profile: CHILL
Plan: Enterprise
Run ID: 91e85069-40da-4cb1-909c-e8e27e118ad3
📒 Files selected for processing (5)
control-plane-operator/controllers/awsprivatelink/awsprivatelink_controller.gocontrol-plane-operator/controllers/awsprivatelink/awsprivatelink_controller_test.gocontrol-plane-operator/controllers/hostedcontrolplane/hostedcontrolplane_controller.gosupport/awsutil/sg.gosupport/awsutil/sg_test.go
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #8869 +/- ##
=======================================
Coverage 43.19% 43.19%
=======================================
Files 767 767
Lines 94914 94931 +17
=======================================
+ Hits 40998 41007 +9
- Misses 51052 51059 +7
- Partials 2864 2865 +1
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
@sdminonne: all tests passed! Full PR test history. Your PR dashboard. 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. I understand the commands that are listed here. |
|
Now I have the complete picture. The The
In import (
"testing"
"github.com/aws/aws-sdk-go-v2/aws"
ec2types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
)The In And the verify job shows that I now have all the data needed for the report. Test Failure Analysis CompleteJob Information
Test Failure AnalysisErrorSummaryBoth CI jobs failed because two files modified in the PR — Root CauseThe PR moves 1. 2. The project's Both the Recommendations
Evidence
|
|
Stale PRs are closed after 21d of inactivity. If this PR is still relevant, comment to refresh it or remove the stale label. If this PR is safe to close now please do so with /lifecycle stale |
Summary
This is a follow-up to #8768, which fixed the main source of CloudTrail spam by adding
diffPermissionsto the awsprivatelink controller'sreconcileAWSEndpointSecurityGroup(the path running every 5 minutes on port 443).This PR addresses the remaining blind-upsert path in
createAWSDefaultSecurityGroup:diffPermissions,isPermissionPresent,equalIPRanges) from the awsprivatelink controller tosupport/awsutil/sg.goas shared utilitiesUserIdGroupPairrules (used byDefaultWorkerSGIngressRules) via a newequalUserIdGroupPairshelpercreateAWSDefaultSecurityGroupso the operator only callsAuthorizeSecurityGroupIngressfor genuinely missing rules, instead of blindly upserting and relying onInvalidPermission.DuplicateerrorsCloses: OCPBUGS-93738
Test plan
support/awsutil/sg_test.gocovering IpRanges, UserIdGroupPairs, mixed, and partial-match scenariosTestDiffPermissionsin awsprivatelink controller updated to use the shared functiongo test ./support/awsutil/...passesgo test ./control-plane-operator/controllers/awsprivatelink/...passesgo test ./control-plane-operator/controllers/hostedcontrolplane/...passes🤖 Generated with Claude Code