Beta. The CRDs are v1, but until 1.0 a change that cannot be additive is named in the changelog. What that means.
A binding acts with the operator's permissions, not its author's. Anyone who can create a DeviceBinding in a namespace can read, and through commands write, any field of any kind the operator can reach in that namespace. Granting create on DeviceBinding is granting that reach; grant it as you would write access to those kinds.
The operator's own RBAC is the policy. The shipped ClusterRole (config/rbac/role.yaml) grants nothing on targets. Add a rule for each kind you want to expose: get, list and watch to publish it, and patch for commands.
One namespace
A DeviceBinding needs them in its own namespace only. The operator watches a kind in each namespace whose DeviceBindings use it, so a Role is enough. To expose Deployments in home and nowhere else (this is config/samples/target_rbac.yaml):
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata: {name: kubeassistant-targets, namespace: home}
rules:
- apiGroups: [apps]
resources: [deployments]
verbs: [get, list, watch, patch]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata: {name: kubeassistant-targets, namespace: home}
roleRef: {apiGroup: rbac.authorization.k8s.io, kind: Role, name: kubeassistant-targets}
subjects:
- {kind: ServiceAccount, name: kubeassistant, namespace: kubeassistant}
Across the cluster
A ClusterDeviceBinding needs them across the cluster, so use a ClusterRole with the same rules and a ClusterRoleBinding. While a ClusterDeviceBinding uses a kind, the operator watches it with one cluster-wide informer, which serves that kind's DeviceBindings too; when the last one goes, it returns to one informer per namespace. An informer stops when no binding uses it.
Before watching a kind, the operator asks the API server (a SelfSubjectAccessReview) whether it may list and watch it, in the binding's namespace for a DeviceBinding and across the cluster for a ClusterDeviceBinding. A binding whose kind is forbidden reports TargetWatched=False with reason Forbidden and is retried every minute, so a grant takes effect without touching the binding. Bindings that already published keep their devices while forbidden.
Field types come from /openapi/v3, which Kubernetes lets every authenticated user read through the default system:discovery role; the operator needs no grant for it.
Secrets
Secret is refused as a target whatever the RBAC says: publishing to MQTT puts the value on a broker every Home Assistant client can read.