Skip to content
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

v2: correct and test controller RBAC #301

Merged
merged 1 commit into from
Nov 12, 2024
Merged

Conversation

chrisseto
Copy link
Contributor

Prior to this commit the declared permissions for the RedpandaReconciler had become out of date. This went unnoticed due to tests utilizing admin permissions or the inflated permissions required for executing rpk debug bundle.

This commit corrects the permission declaration of the RedpandaReconciler, updates its tests to use the ClusterRole and Role generated by controller-gen, and adds a test to statically assert the correctness of the permissions.

role := roles[1].(*rbacv1.Role)
clusterRole := roles[0].(*rbacv1.ClusterRole)

for _, typ := range redpandachart.Types() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we have this same test equivalent in the helm chart-defined role? Seems like it'd be nice since we're relying on the generated role.yaml in our tests here, but the RBAC rules are actually a part of the operator chart currently.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's a WIP PR from Rafal that tests based off the operator's role.yaml: redpanda-data/helm-charts#1593 that I've been patching up to work with these updates. It's a bit less than ideal because the dependency is external to the repo but it'll work for now :/

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@RafalKorepta
Copy link
Contributor

RafalKorepta commented Nov 12, 2024

--
  | W1111 22:10:41.304096   64797 reflector.go:547] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: failed to list *v1beta2.HelmRepository: helmrepositories.source.toolkit.fluxcd.io is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "helmrepositories" in API group "source.toolkit.fluxcd.io" in the namespace "testenv-xhjlh"
  | E1111 22:10:41.304143   64797 reflector.go:150] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: Failed to watch *v1beta2.HelmRepository: failed to list *v1beta2.HelmRepository: helmrepositories.source.toolkit.fluxcd.io is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "helmrepositories" in API group "source.toolkit.fluxcd.io" in the namespace "testenv-xhjlh"
  | W1111 22:11:08.386420   64797 reflector.go:547] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: failed to list *v1.PersistentVolumeClaim: persistentvolumeclaims is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "persistentvolumeclaims" in API group "" in the namespace "testenv-xhjlh"
  | E1111 22:11:08.386455   64797 reflector.go:150] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: Failed to watch *v1.PersistentVolumeClaim: failed to list *v1.PersistentVolumeClaim: persistentvolumeclaims is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "persistentvolumeclaims" in API group "" in the namespace "testenv-xhjlh"
  | W1111 22:11:09.881148   64797 reflector.go:547] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: failed to list *v1.PodDisruptionBudget: poddisruptionbudgets.policy is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "poddisruptionbudgets" in API group "policy" in the namespace "testenv-xhjlh"
  | E1111 22:11:09.881183   64797 reflector.go:150] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: Failed to watch *v1.PodDisruptionBudget: failed to list *v1.PodDisruptionBudget: poddisruptionbudgets.policy is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "poddisruptionbudgets" in API group "policy" in the namespace "testenv-xhjlh"
  | W1111 22:11:12.443445   64797 reflector.go:547] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: failed to list *v1.RoleBinding: rolebindings.rbac.authorization.k8s.io is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "rolebindings" in API group "rbac.authorization.k8s.io" in the namespace "testenv-xhjlh"
  | E1111 22:11:12.443478   64797 reflector.go:150] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: Failed to watch *v1.RoleBinding: failed to list *v1.RoleBinding: rolebindings.rbac.authorization.k8s.io is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "rolebindings" in API group "rbac.authorization.k8s.io" in the namespace "testenv-xhjlh"
--
  | W1111 22:11:31.281544   64797 reflector.go:547] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: failed to list *v1.Ingress: ingresses.networking.k8s.io is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "ingresses" in API group "networking.k8s.io" in the namespace "testenv-xhjlh"
  | E1111 22:11:31.281572   64797 reflector.go:150] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: Failed to watch *v1.Ingress: failed to list *v1.Ingress: ingresses.networking.k8s.io is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "ingresses" in API group "networking.k8s.io" in the namespace "testenv-xhjlh"
  | W1111 22:11:33.060144   64797 reflector.go:547] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: failed to list *v1.Role: roles.rbac.authorization.k8s.io is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "roles" in API group "rbac.authorization.k8s.io" in the namespace "testenv-xhjlh"
  | E1111 22:11:33.060176   64797 reflector.go:150] pkg/mod/k8s.io/[email protected]/tools/cache/reflector.go:232: Failed to watch *v1.Role: failed to list *v1.Role: roles.rbac.authorization.k8s.io is forbidden: User "system:serviceaccount:testenv-xhjlh:testenv-8asldm" cannot list resource "roles" in API group "rbac.authorization.k8s.io" in the namespace "testenv-xhjlh"

https://buildkite.com/redpanda/redpanda-operator/builds/3231#01931d36-8a5c-4eab-907f-b35ee6858857/1181-3146

Prior to this commit the declared permissions for the RedpandaReconciler had
become out of date. This went unnoticed due to tests utilizing admin
permissions or the inflated permissions required for executing `rpk debug
bundle`.

This commit corrects the permission declaration of the RedpandaReconciler,
updates its tests to use the ClusterRole and Role generated by controller-gen,
and adds a test to statically assert the correctness of the permissions.
@chrisseto chrisseto merged commit 6678387 into main Nov 12, 2024
5 checks passed
@chrisseto chrisseto deleted the chris/p/correct-rbac branch November 12, 2024 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants