Skip to content

Commit

Permalink
rbac: add permissions for imagestreams, daemonsets, apiservices
Browse files Browse the repository at this point in the history
Prepare for watching v1 resources (issue opendatahub-io#637)

To enable watching for DaemonSet and APIService (REST api resources
daemonsets and apiservices) reading/watching permissions required
for the operator's role. Otherwise it gets errors like:

```
User "system:serviceaccount:openshift-operators:opendatahub-operator-controller-manager" cannot list resource "daemonsets" in API group "apps" at the cluster scope

E1018 20:00:55.374514       1 reflector.go:140] go/pkg/mod/k8s.io/client-go@v0.26.0/tools/cache/reflector.go:169: Failed to watch *v1.DaemonSet: failed to list *v1.DaemonSet: daemonsets.apps is forbidden: User "system:serviceaccount:openshift-operators:opendatahub-operator-controller-manager" cannot list resource "daemonsets" in API group "apps" at the cluster scope
```

For ImageStream `get` permissing is needed for cli.Get() in deploy's
manageResources()[1], otherwise it does not set
ownersReference (missing the branch apierrs.IsNotFound(err) since
err is related to permissions).

Autogenerated files:
- config/rbac/role.yaml (make manifests)

[1] https://github.com/opendatahub-io/opendatahub-operator/blob/13a7e822c0c75f361c319f8256a2d199d031d97c/pkg/deploy/deploy.go#L199

Signed-off-by: Yauheni Kaliuta <ykaliuta@redhat.com>
  • Loading branch information
ykaliuta committed Nov 5, 2023
1 parent 9ff16dd commit cf40712
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 17 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,22 @@ rules:
- list
- patch
- watch
- apiGroups:
- apiregistration.k8s.io
resources:
- apiservices
verbs:
- get
- list
- watch
- apiGroups:
- apps
resources:
- daemonsets
verbs:
- get
- list
- watch
- apiGroups:
- apps
resources:
Expand Down Expand Up @@ -675,6 +691,7 @@ rules:
verbs:
- create
- delete
- get
- list
- patch
- update
Expand Down
6 changes: 5 additions & 1 deletion controllers/datasciencecluster/kubebuilder_rbac.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ package datasciencecluster
// +kubebuilder:rbac:groups="operators.coreos.com",resources=operatorconditions,verbs=get;list;watch

/* This is for operator */
// +kubebuilder:rbac:groups="apiregistration.k8s.io",resources=apiservices,verbs=get;list;watch

// +kubebuilder:rbac:groups="apps",resources=daemonsets,verbs=get;list;watch

// +kubebuilder:rbac:groups="operators.coreos.com",resources=catalogsources,verbs=get;list;watch

// +kubebuilder:rbac:groups="apiextensions.k8s.io",resources=customresourcedefinitions,verbs=get;list;watch
Expand Down Expand Up @@ -128,7 +132,7 @@ package datasciencecluster
// +kubebuilder:rbac:groups="integreatly.org",resources=rhmis,verbs=list;watch;patch;delete

// +kubebuilder:rbac:groups="image.openshift.io",resources=imagestreams,verbs=patch;create;update;delete
// +kubebuilder:rbac:groups="image.openshift.io",resources=imagestreams,verbs=create;list;watch;patch;delete
// +kubebuilder:rbac:groups="image.openshift.io",resources=imagestreams,verbs=create;list;watch;patch;delete;get

// +kubebuilder:rbac:groups="extensions",resources=replicasets,verbs=*
// +kubebuilder:rbac:groups="extensions",resources=ingresses,verbs=list;watch;patch;delete;get
Expand Down

0 comments on commit cf40712

Please sign in to comment.