Skip to content

fix(helm): Ensure non-default service account name works with namespaces-cache and configmaps-cache role bindings #557

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

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

gunzy83
Copy link
Contributor

@gunzy83 gunzy83 commented Nov 1, 2024

Issue #, if available: N/A

Relates to aws-controllers-k8s/kms-controller#83

Description of changes: This change ensures that the required ClusterRoleBinding and RoleBinding objects apply to a ServiceAccount with a custom name.

Error seen with custom service account name:

pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: Failed to watch *v1.ConfigMap: failed to list *v1.ConfigMap: configmaps is forbidden: User "system:serviceaccount:kms-controller:kms-controller" cannot list resource "configmaps" in API group "" in the namespace "kms-controller"

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

…ces-cache and configmaps-cache role bindings
@ack-prow ack-prow bot requested review from a-hilaly and jlbutler November 1, 2024 00:51
Copy link

ack-prow bot commented Nov 1, 2024

Hi @gunzy83. 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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

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.

@ack-prow ack-prow bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Nov 1, 2024
Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

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

Thank you @gunzy83!!
/approve
/assign @michaelhtm

@a-hilaly
Copy link
Member

a-hilaly commented Nov 1, 2024

/ok-to-test

@ack-prow ack-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Nov 1, 2024
Copy link

ack-prow bot commented Nov 1, 2024

@gunzy83: 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 141a7cd 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.

@a-hilaly
Copy link
Member

a-hilaly commented Nov 1, 2024

/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 1, 2024
@a-hilaly
Copy link
Member

a-hilaly commented Nov 1, 2024

@mtougeron @eadasiak any thoughts on this change? i'm wondering how did this work with all the CARM installations we've done before?

@mtougeron
Copy link

@mtougeron @eadasiak any thoughts on this change? i'm wondering how did this work with all the CARM installations we've done before?

I'm not sure about the code that generates these templates, but I'm assuming it's probably that whatever populates name: {{ .ServiceAccountName }} here https://github.com/aws-controllers-k8s/code-generator/blob/main/templates/helm/values.yaml.tpl#L141 sets it essentially to the same value by default. So it you didn't change from the ServiceAccount name the chart uses by default it would work fine. But if you did try to change it, it wouldn't work properly.

For example, the rendered Deployment manifest uses serviceAccountName: {{ IncludeTemplate "service-account.name" }} so if someone sets

serviceAccount:
  name: foo

in their values.yaml (or via --set serviceAccount.name=foo) that field would be properly updated. But the ClusterRoleBinding & RoleBinding would still have ack-ec2-controller

@gunzy83
Copy link
Contributor Author

gunzy83 commented Nov 3, 2024

@mtougeron @eadasiak any thoughts on this change? i'm wondering how did this work with all the CARM installations we've done before?

I'm not sure about the code that generates these templates, but I'm assuming it's probably that whatever populates name: {{ .ServiceAccountName }} here https://github.com/aws-controllers-k8s/code-generator/blob/main/templates/helm/values.yaml.tpl#L141 sets it essentially to the same value by default. So it you didn't change from the ServiceAccount name the chart uses by default it would work fine. But if you did try to change it, it wouldn't work properly.

For example, the rendered Deployment manifest uses serviceAccountName: {{ IncludeTemplate "service-account.name" }} so if someone sets

serviceAccount:
  name: foo

in their values.yaml (or via --set serviceAccount.name=foo) that field would be properly updated. But the ClusterRoleBinding & RoleBinding would still have ack-ec2-controller

I think this is only a problem when installScope is namespace. When installScope is cluster the cluster role provides enough permissions and the binding for that is updated with a custom service account name. Perhaps the subset of users who both run with installScope=namespace and a custom service account name is small.

@a-hilaly
Copy link
Member

a-hilaly commented Nov 4, 2024

Thank you @gunzy83 and @mtougeron !! Yeah looks like there is an edge case where there is a namespace mismatch between the service account name and the binding. I just tested this patch with new controllers and it's indeed generating the expected namespace value.

@a-hilaly
Copy link
Member

a-hilaly commented Nov 4, 2024

/unhold

@ack-prow ack-prow bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Nov 4, 2024
@michaelhtm
Copy link
Member

👍
/lgtm

@ack-prow ack-prow bot added the lgtm Indicates that a PR is ready to be merged. label Nov 4, 2024
Copy link

ack-prow bot commented Nov 4, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: a-hilaly, gunzy83, 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:

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

@ack-prow ack-prow bot merged commit 9715a2a into aws-controllers-k8s:main Nov 4, 2024
18 of 19 checks passed
@gunzy83
Copy link
Contributor Author

gunzy83 commented Nov 4, 2024

Thanks everyone! 🎉

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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants