Skip to content

Conversation

@a-hilaly
Copy link
Member

Implements aws-controllers-k8s/community#2628 (mostly)

Introduces a new IAMRoleSelector CRD that enables dynamic IAM role
assignment based on namespace and resource type selectors. This feature
provides an alternative to CARM for role selection and cannot be used
simultaneously with CARM (enforced by validation).

Key components:

  • New IAMRoleSelector CRD with namespace and resource type selectors
  • Selector matching logic with AND between selector types, OR within arrays
  • Dynamic informer-based cache for IAMRoleSelector resources
  • Integration into the reconciler to override CARM role selection
  • Alpha feature gate (IAMRoleSelector) defaulting to disabled

Note: ResourceTypeSelector uses schema.GroupVersionKind in the API,
which differs from the separate fields approach in the original types.
This may need adjustment based on CRD generation requirements.

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 24, 2025 06:04
@ack-prow
Copy link

ack-prow bot commented Sep 24, 2025

[APPROVALNOTIFIER] This PR is APPROVED

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

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:

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

Implements aws-controllers-k8s/community#2628 (mostly)

Introduces a new IAMRoleSelector CRD that enables dynamic IAM role
assignment based on namespace and resource type selectors. This feature
provides an alternative to CARM for role selection and cannot be used
simultaneously with CARM (enforced by validation).

Key components:
- New IAMRoleSelector CRD with namespace and resource type selectors
- Selector matching logic with AND between selector types, OR within arrays
- Dynamic informer-based cache for IAMRoleSelector resources
- Integration into the reconciler to override CARM role selection
- Alpha feature gate (IAMRoleSelector) defaulting to disabled

Note: ResourceTypeSelector uses schema.GroupVersionKind in the API,
which differs from the separate fields approach in the original types.
This may need adjustment based on CRD generation requirements.
@a-hilaly
Copy link
Member Author

/retest

1 similar comment
@a-hilaly
Copy link
Member Author

/retest

@cheeseandcereal cheeseandcereal self-requested a review September 25, 2025 18:46
@a-hilaly
Copy link
Member Author

/retest

2 similar comments
@a-hilaly
Copy link
Member Author

/retest

@a-hilaly
Copy link
Member Author

a-hilaly commented Oct 7, 2025

/retest

@ack-prow
Copy link

ack-prow bot commented Oct 8, 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 cd39d65 link false /test verify-attribution
sagemaker-controller-test cd39d65 link true /test sagemaker-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.

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 work @a-hilaly 🚀
left a few comments

}

type IAMRoleSelectorSpec struct {
ARN string `json:"arn"`
Copy link
Member

Choose a reason for hiding this comment

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

nit: calling this ARN seems a bit weird/misleading..makes it feel like it's a new AWS resource.
should we call it RoleARN instead?

Copy link
Member

Choose a reason for hiding this comment

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

also, should we mark this as required in the CRD?

Comment on lines +56 to +57
Group: "services.k8s.aws",
Version: "v1alpha1",
Copy link
Member

Choose a reason for hiding this comment

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

nit: maybe we can import these values?

Comment on lines +87 to +91
// Validate before storing
if err := validateSelector(selector); err != nil {
c.log.Error(err, "invalid IAMRoleSelector, not caching", "name", selector.Name)
return
}
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 patch the IAMSelector status with this information?

Comment on lines +109 to +111
if err := validateSelector(selector); err != nil {
c.log.Error(err, "invalid IAMRoleSelector, removing from cache", "name", selector.Name)
// Remove from cache if it becomes invalid
Copy link
Member

Choose a reason for hiding this comment

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

ditto

Comment on lines +100 to +144
// validateSelector checks if an IAMRoleSelector is valid
func validateSelector(selector *ackv1alpha1.IAMRoleSelector) error {
if selector == nil {
return fmt.Errorf("selector cannot be nil")
}

if selector.Spec.ARN == "" {
return fmt.Errorf("ARN cannot be empty")
}

// parse ARN to ensure it's valid
if _, err := arn.Parse(selector.Spec.ARN); err != nil {
return fmt.Errorf("invalid ARN: %w", err)
}

// Validate namespace selector
if err := validateNamespaceSelector(selector.Spec.NamespaceSelector); err != nil {
return fmt.Errorf("invalid namespace selector: %w", err)
}

// Validate resource type selectors
if err := validateResourceTypeSelectors(selector.Spec.ResourceTypeSelector); err != nil {
return fmt.Errorf("invalid resource type selector: %w", err)
}

return nil
}

func validateNamespaceSelector(nsSelector ackv1alpha1.NamespaceSelector) error {
// Check for duplicate namespace names
seen := make(map[string]bool)
for _, name := range nsSelector.Names {
if name == "" {
return fmt.Errorf("namespace name cannot be empty")
}
if seen[name] {
return fmt.Errorf("duplicate namespace name: %s", name)
}
seen[name] = true
}

// Validate label selector
if len(nsSelector.LabelSelector.MatchLabels) > 0 {
for key := range nsSelector.LabelSelector.MatchLabels {
if key == "" {
Copy link
Member

Choose a reason for hiding this comment

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

nit: should we move all validations to a new file? called validator...they don't seem to be related to matcher

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