kedacore / charts

Helm charts for KEDA
Apache License 2.0
152 stars 216 forks source link

More secure rbac #625

Closed jkremser closed 5 months ago

jkremser commented 5 months ago

Issue #624

the changes rely on WATCH_NAMESPACE variable. So if it is empty, we basically install almost the same rbac as before (ClusterRole with ClusterRoleBinding so that it can watch for events in all the namespaces).

If it contains one or multiple namespaces (so it assumes this change is merged), it will use normal RoleBinding together with the cluster role so that these rules are namespaced for each listed namespace in that env var.

Note: Normal RoleBinding + ClusterRole works the same way as RoleBinding with normal Role, but this way we can reuse the same resource and lower the complexity of helm chart a bit.

It also contains a way to restrict the set of secrets, the operator should be able to look into. By default it's the same behavior as before, (well, if WATCH_NAMESPACE is not empty, it will be restricted only to secrets in that ns), but one can also specify: --set permissions.operator.restrict.namesAllowList="{foo,bar}" so that the operator can read only secrets in that namespace called "foo" and "bar"

The other RBAC-related change is the whitelisting of CRDs that can be scaled by the operator. Again, by default it's the same behavior as before, but if requested, one can restrict the set of CRDs that can be referenced by scaled object in advance during the helm installation by:

rbac:
  enabledCustomScaledRefKinds: true
  scaledRefKinds:
   - apiGroup: argoproj.io
     kind: Rollout
   - apiGroup: cluster.x-k8s.io
     kind: MachineDeployment
   - apiGroup: cluster.x-k8s.io
     kind: MachinePool

The PR also splits the RBAC for all three individual components so that webhooks or metric server don't have the same rights as the operator itself(that actually had a right to read ("get") every single resource in the cluster). Now each component has its own service account with a taylored roles attached to it.

Since the PR is quite complex to review, I've prepared some deployment scenarios and captured the resulting RBAC using the rbac-tool kubectl plugin.

note: for all four scenarios, I've created a Deployment, ScaledObject, checked that hpa was created and deleted it and was checking if there were any rbac related issues

JorTurFer commented 5 months ago

WOW, this PR is a great idea! I'm checking it in depth because you said, it's complex and RBAC is risky, but I'll post something asap

joebowbeer commented 2 weeks ago

@jkremser Should the instructions for restricting access to secrets be updated?

https://keda.sh/docs/2.15/operate/cluster/#restrict-secret-access

Also see https://github.com/kedacore/keda-docs/issues/1307