Feat/iam role policy attachment#184
Conversation
|
Hi @anas099. Thanks for your PR. I'm waiting for a aws-controllers-k8s member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. 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. |
|
@michaelhtm please have a look when you have time |
Problem: ACK IAM controller lacks a first-class resource to attach policies to existing roles, forcing users to rely on out-of-band tooling for role-policy relationships. Solution: introduce RolePolicyAttachment with generated API/manager/CRD artifacts, controller wiring, RBAC updates, and e2e coverage for reference/direct attachment flows. Validation: manual cluster tests on dev34 confirmed attach and detach lifecycle for ACK-managed and existing AWS IAM roles/policies; compile checks pass.
Move local usage examples to parent ack-cont/examples workspace directory to keep upstream contribution focused on generated resource, controller wiring, RBAC, and tests.
Introduce an opt-in annotation on the Role resource:
iam.services.k8s.aws/policy-reconciliation-mode: additive
When set, the controller attaches the managed policies listed in
Spec.Policies but never detaches managed policies that were attached
out-of-band (e.g. by a RolePolicyAttachment resource, or by a role
shared across clusters/accounts). The default behavior (annotation
absent) remains authoritative and unchanged, so existing Role manifests
are fully backward compatible.
- hooks.go: add isAdditivePolicyMode() + comparePolicies(); skip the
detach set in syncManagedPolicies when additive.
- generator.yaml: mark Spec.Policies compare is_ignored so comparison is
delegated to comparePolicies() in customPreCompare (mode-aware).
- delta.go: drop the generated Spec.Policies comparison accordingly.
- delete path (template + sdk.go): clear the annotation on the delete
copy so DeleteRole still performs a full detach (IAM requires no
attached managed policies before deletion).
- delta_test.go: unit tests for authoritative vs additive comparison.
- e2e: test_role_additive_policies.py verifies out-of-band policies are
not detached, new desired policies are still attached, and the
resource stays synced (no drift loop).
127ea77 to
36bae8d
Compare
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: anas099 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 |
Summary
This PR adds a new IAM ACK resource,
RolePolicyAttachment, to manage policy-role bindings declaratively in Kubernetes similar to Terraform resource (aws_iam_role_policy_attachment)Problem
The IAM controller currently supports
RoleandPolicyresources, but does not provide a first-class attachment resource for existing IAM roles and managed policies.Because of this gap, users must rely on out-of-band tooling to attach policies to roles, especially for existing AWS IAM roles that are not created by ACK.
Solution
This PR introduces
RolePolicyAttachmentwith generated API and controller artifacts, plus controller and RBAC wiring.Included changes:
RolePolicyAttachmentpkg/resource/role_policy_attachmentconfig/crdandhelm/crdsrolepolicyattachmentsBehavior
RolePolicyAttachmentsupports:spec.roleNamespec.policyARNspec.roleRefspec.policyRefLifecycle:
AttachRolePolicyListAttachedRolePoliciesDetachRolePolicyValidation
Build and compile
go test ./cmd/controller/... ./pkg/resource/role_policy_attachment/...passesManual cluster validation (local cluster)
attached=trueRolePolicyAttachmenttriggers detach successfully through finalizer pathE2E
RolePolicyAttachmentGeneration and versions
Regenerated from pinned stable generator tag and Go toolchain:
v0.59.1go1.26.3v0.59.1Checklist