Skip to content

fix: attach policies to Role on create #136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions apis/v1alpha1/ack-generate-metadata.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ack_generate_info:
build_date: "2025-05-13T05:08:01Z"
build_hash: 55bf57b2806c33a7fcd074be403f26ce3f8e58db
go_version: go1.24.2
version: v0.46.2
build_date: "2025-05-14T20:54:45Z"
build_hash: 016d4c53082b4b78942ec154e4bf4bf36c4db11d
go_version: go1.24.3
version: v0.46.2-2-g016d4c5
api_directory_checksum: 7e1c19231d3275a1147157f6943a7391953f7001
api_version: v1alpha1
aws_sdk_go_version: v1.32.6
Expand Down
19 changes: 19 additions & 0 deletions pkg/resource/role/hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,25 @@ import (
commonutil "github.com/aws-controllers-k8s/iam-controller/pkg/util"
)

func (rm *resourceManager) attachPolicies(ctx context.Context, r *resource) (err error) {
rlog := ackrtlog.FromContext(ctx)
exit := rlog.Trace("rm.attachPolicies")
defer func() { exit(err) }()
for _, p := range r.ko.Spec.Policies {
err := rm.addManagedPolicy(ctx, r, p)
if err != nil {
return err
}
}
for n, p := range r.ko.Spec.InlinePolicies {
err := rm.addInlinePolicy(ctx, r, n, p)
if err != nil {
return err
}
}
return nil
}

// putRolePermissionsBoundary calls the IAM API to set a given role
// permission boundary.
func (rm *resourceManager) putRolePermissionsBoundary(
Expand Down
4 changes: 4 additions & 0 deletions pkg/resource/role/sdk.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions templates/hooks/role/sdk_create_post_set_output.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@
ko.Spec.AssumeRolePolicyDocument = &doc
}
}
err = rm.attachPolicies(ctx, &resource{ko})
if err != nil {
return &resource{ko}, err
}
ackcondition.SetSynced(&resource{ko}, corev1.ConditionFalse, nil, nil)