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.

Change test files from `runtime_test` to `runtime` package to enable
testing of package private functions. Remove ackrt import alias
as tests now have direct access to runtime package symbols.
@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

… 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
@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 267 to +274
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

Copy link

ack-prow bot commented Sep 24, 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

@a-hilaly
Copy link
Member Author

/retest

2 similar comments
@a-hilaly
Copy link
Member Author

/retest

@a-hilaly
Copy link
Member Author

/retest

Copy link

ack-prow bot commented Sep 24, 2025

@a-hilaly: The following tests 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 4cf28f2 link false /test verify-attribution
ecr-controller-test 4cf28f2 link true /test ecr-controller-test
s3-controller-test 4cf28f2 link true /test s3-controller-test
iam-controller-test 4cf28f2 link true /test iam-controller-test
sagemaker-controller-test 4cf28f2 link true /test sagemaker-controller-test
ec2-controller-test 4cf28f2 link true /test ec2-controller-test

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants