controller-tools icon indicating copy to clipboard operation
controller-tools copied to clipboard

Handling Identical Kubebuilder Annotations in Different CRs with * Verbs

Open OdedViner opened this issue 1 year ago • 1 comments

When there are two identical Kubebuilder annotations (same API groups) in different Custom Resource (CR) files, and one of them uses the verb *, we need to account for a condition where the verb is *, but not * combined with specific verbs like list, update, etc.

For example:

// controllers/storagecluster/reconcile.go
// +kubebuilder:rbac:groups=storage.k8s.io,resources=storageclasses,verbs=*
func (r *StorageClusterReconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {}

// controllers/storagerequest/storagerequest_controller.go
// +kubebuilder:rbac:groups=storage.k8s.io,resources=storageclasses,verbs=get;list;watch;create;update;patch;delete
func (r *StorageRequestReconciler) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) {}

In the RBAC role configuration:

# config/rbac/role.yaml
- apiGroups:
  - storage.k8s.io
  resources:
  - storageclasses
  verbs:
  - '*'
  - create
  - delete
  - get
  - list
  - patch
  - update
  - watch

The role definition currently allows both * and specific verbs such as create, delete, and list. The issue arises from the fact that * includes all verbs, making the additional specific verbs redundant. We should add a condition to avoid this overlap.

Reference: ocs-operator role.yaml

OdedViner avatar Oct 20 '24 13:10 OdedViner

Makes sense, feel free to open a PR

(cc @chrischdi just fyi)

sbueringer avatar Oct 21 '24 06:10 sbueringer

Makes sense, feel free to open a PR

(cc @chrischdi just fyi)

https://github.com/kubernetes-sigs/controller-tools/pull/1081

OdedViner avatar Oct 27 '24 12:10 OdedViner

Was fixed in

  • #1081

/close

chrischdi avatar Nov 18 '24 14:11 chrischdi

@chrischdi: Closing this issue.

In response to this:

Was fixed in

#1081

/close

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-sigs/prow repository.

k8s-ci-robot avatar Nov 18 '24 14:11 k8s-ci-robot