Skip to content

Conversation

@a-hilaly
Copy link
Member

@a-hilaly a-hilaly commented Sep 23, 2025

Adds protection against attempting to manage AWS resources that exist in a
different region or account than the controller is configured to use. This
prevents accidental resource hijacking and provides clear error messages.

  • Add regionDrifted() and accountDrifted() helper functions
  • Check for drift before creating resource manager in Reconcile
  • Return terminal errors when drift is detected
  • Add comprehensive tests for both region and account drift scenarios

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ack-prow ack-prow bot requested review from jlbutler and michaelhtm September 23, 2025 18:07
@ack-prow ack-prow bot added the approved label Sep 23, 2025
@a-hilaly a-hilaly force-pushed the feat/account-region-protection branch from 513c7b4 to 1ca522a Compare September 23, 2025 18:07
@michaelhtm
Copy link
Member

/test unit-test

@a-hilaly a-hilaly force-pushed the feat/account-region-protection branch from 1ca522a to 4cf28f2 Compare September 24, 2025 03:40
Copy link
Member

@michaelhtm michaelhtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch @a-hilaly!
left a few comments below

}
parsedARN, err := arn.Parse(string(roleARN))
if err != nil {
return ctrlrt.Result{}, fmt.Errorf("parsing role ARN %q from %q configmap: %v", roleARN, ackrtcache.ACKRoleTeamMap, err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use https://github.com/aws-controllers-k8s/runtime/blob/main/pkg/runtime/reconciler.go#L1146-L1167 to return here? so that this error can be patched to the resource status

Comment on lines 262 to +275
region := r.getRegion(desired)
endpointURL := r.getEndpointURL(desired)
gvk := r.rd.GroupVersionKind()

// If the user has specified a region that is different from the
// region the resource currently exists in, we need to fail the
// reconciliation with a terminal error.
if r.regionDrifted(desired) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use the region in line 267? It already parses resource annotation - namespace annotation - config

@a-hilaly
Copy link
Member Author

/retest

2 similar comments
@a-hilaly
Copy link
Member Author

/retest

@a-hilaly
Copy link
Member Author

/retest

@michaelhtm michaelhtm force-pushed the feat/account-region-protection branch 2 times, most recently from c763f55 to 2a128db Compare November 10, 2025 19:27
@michaelhtm
Copy link
Member

/test ecr-controller-test

@michaelhtm
Copy link
Member

/retest

@michaelhtm
Copy link
Member

/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Nov 10, 2025
@michaelhtm
Copy link
Member

/hold

@ack-prow ack-prow bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 10, 2025
… resources

Adds protection against attempting to manage AWS resources that exist in a
different region or account than the controller is configured to use. This
prevents accidental resource hijacking and provides clear error messages.

- Add `regionDrifted()` and `accountDrifted()` helper functions
- Check for drift before creating resource manager in Reconcile
- Return terminal errors when drift is detected
- Add comprehensive tests for both region and account drift scenarios
@michaelhtm michaelhtm force-pushed the feat/account-region-protection branch from 2a128db to c271c63 Compare November 10, 2025 21:58
@ack-prow ack-prow bot removed the lgtm Indicates that a PR is ready to be merged. label Nov 10, 2025
@michaelhtm
Copy link
Member

/lgtm
/unhold

@ack-prow ack-prow bot added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Nov 10, 2025
@ack-prow
Copy link

ack-prow bot commented Nov 10, 2025

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: a-hilaly, michaelhtm

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [a-hilaly,michaelhtm]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@michaelhtm
Copy link
Member

/test s3-controller-test

@michaelhtm
Copy link
Member

/test ec2-controller-test

@ack-prow
Copy link

ack-prow bot commented Nov 10, 2025

@a-hilaly: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
verify-attribution c271c63 link false /test verify-attribution

Full PR test history. Your PR dashboard.

Instructions 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/test-infra repository. I understand the commands that are listed here.

@michaelhtm
Copy link
Member

/test sagemaker-controller-test

@ack-prow ack-prow bot merged commit c101a18 into aws-controllers-k8s:main Nov 11, 2025
7 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants