Skip to content

Commit

Permalink
v2: correct and test controller RBAC
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chrisseto committed Nov 11, 2024
1 parent 3a34a83 commit 4ef451c
Show file tree
Hide file tree
Showing 7 changed files with 558 additions and 51 deletions.
4 changes: 4 additions & 0 deletions operator/config/rbac/bases/operator/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ rules:
- clusterroles
verbs:
- create
- delete
- get
- list
- patch
Expand Down Expand Up @@ -215,6 +216,8 @@ rules:
resources:
- configmaps
- pods
- rolebindings
- roles
- secrets
- serviceaccounts
- services
Expand Down Expand Up @@ -394,6 +397,7 @@ rules:
- apiGroups:
- monitoring.coreos.com
resources:
- podmonitors
- servicemonitors
verbs:
- create
Expand Down
39 changes: 28 additions & 11 deletions operator/config/rbac/v2-manager-role/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ rules:
- get
- patch
- update
- apiGroups:
- rbac.authorization.k8s.io
resources:
- clusterrolebindings
- clusterroles
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
Expand All @@ -63,15 +76,15 @@ rules:
- apiGroups:
- ""
resources:
- events
- configmaps
- pods
- rolebindings
- roles
- secrets
- serviceaccounts
- services
verbs:
- create
- patch
- apiGroups:
- ""
resources:
- persistentvolumeclaims
verbs:
- delete
- get
- list
Expand All @@ -81,12 +94,15 @@ rules:
- apiGroups:
- ""
resources:
- pods
- secrets
- serviceaccounts
- services
- events
verbs:
- create
- patch
- apiGroups:
- ""
resources:
- persistentvolumeclaims
verbs:
- delete
- get
- list
Expand Down Expand Up @@ -231,6 +247,7 @@ rules:
- apiGroups:
- monitoring.coreos.com
resources:
- podmonitors
- servicemonitors
verbs:
- create
Expand Down
12 changes: 5 additions & 7 deletions operator/internal/controller/redpanda/redpanda_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,22 +104,20 @@ type RedpandaReconciler struct {

// any resource that Redpanda helm creates and flux controller needs to reconcile them
// +kubebuilder:rbac:groups="",namespace=default,resources=pods,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,namespace=default,resources=rolebindings,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,namespace=default,resources=roles,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,resources=clusterroles;clusterrolebindings,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=rbac.authorization.k8s.io,namespace=default,resources=roles;rolebindings,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=batch,namespace=default,resources=jobs,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,namespace=default,resources=secrets,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,namespace=default,resources=services,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,namespace=default,resources=serviceaccounts,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=core,namespace=default,resources=configmaps;roles;rolebindings;secrets;services;serviceaccounts,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=apps,namespace=default,resources=statefulsets,verbs=get;list;watch;create;update;patch;delete;
// +kubebuilder:rbac:groups=policy,namespace=default,resources=poddisruptionbudgets,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=apps,namespace=default,resources=deployments,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=cert-manager.io,namespace=default,resources=certificates,verbs=get;create;update;patch;delete;list;watch
// +kubebuilder:rbac:groups=cert-manager.io,namespace=default,resources=issuers,verbs=get;create;update;patch;delete;list;watch
// +kubebuilder:rbac:groups="monitoring.coreos.com",namespace=default,resources=servicemonitors,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=networking.k8s.io,namespace=default,resources=ingresses,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups="monitoring.coreos.com",namespace=default,resources=podmonitors;servicemonitors,verbs=get;list;watch;create;update;patch;delete

// Console chart
// +kubebuilder:rbac:groups=autoscaling,namespace=default,resources=horizontalpodautoscalers,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=networking.k8s.io,namespace=default,resources=ingresses,verbs=get;list;watch;create;update;patch;delete

// redpanda resources
// +kubebuilder:rbac:groups=cluster.redpanda.com,namespace=default,resources=redpandas,verbs=get;list;watch;create;update;patch;delete
Expand Down
Loading

0 comments on commit 4ef451c

Please sign in to comment.