temporalio / temporalio/temporal-worker-controller

[Feature Request] Eliminate ClusterRole requirement in namespace-scoped mode

Open
#530 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

rbac
Dominant language
Go
Stars
187
Forks
70
Avg merge
4d 1h
Merged PRs (30d)
31

Description

Is your feature request related to a problem? Please describe.

When rbac.restrictWatchNamespaces is set, the chart still creates a ClusterRole
(<release>-<ns>-manager-cluster-role, rbac.yaml:300-321) with two grants:

  • namespaces get (pinned to the release namespace)
  • subjectaccessreviews create

Clusters with policies that block ClusterRole/ClusterRoleBinding creation (common in
multi-tenant setups) can't install the chart in namespace-scoped mode at all, even
though the controller only operates within its watched namespaces.

Both grants are ClusterRoles only because their resource types are cluster-scoped, not
because the controller needs cluster-wide reach. Each should be reducible to a
namespaced Role.

Describe the solution you'd like

Make namespace-scoped mode require zero manager ClusterRoles by switching both grants
to namespaced equivalents:

  1. SubjectAccessReview to LocalSubjectAccessReview
    NewWorkerResourceTemplateValidator uses authorizationv1.SubjectAccessReview
    (workerresourcetemplate_webhook.go:526, 572), a cluster-scoped resource. Switching to
    LocalSubjectAccessReview (namespaced), with the object's Namespace set to
    wrt.Namespace, folds the grant into the per-namespace Role. The webhook already
    rejects non-namespaced kinds (webhook.go:511-517) and always checks within
    wrt.Namespace, so a local review is always sufficient.

  2. Identity suffix source: ServiceAccount UID instead of Namespace UID
    At startup the controller reads its own namespace UID for the manager identity
    suffix (main.go:195-203), used to claim Worker Deployment ownership
    (execplan.go:199-211). Reading the controller's own ServiceAccount UID instead
    (get serviceaccounts, namespaced, pinnable via resourceNames) preserves the
    "recreated -> new identity" property, since the chart owns the SA lifecycle, and
    removes the namespaces get grant.

With both changes, the manager runs on a plain namespaced Role in namespace-scoped
mode. (The optional end-user editor/viewer ClusterRoles are already gated behind
createEndUserRoles.)

Additional context

Open question for point 2: is switching the identity suffix from namespace UID to SA UID
acceptable, or is there a reason the namespace UID specifically is required? If the
recreation-detection guarantee can be relaxed, using the namespace name (already
available via POD_NAMESPACE, no API read) is an even simpler alternative.

Happy to open a PR for point 1 on its own, since it's low-risk and independent of the
identity question.

Scope caveat on "zero ClusterRoles": these two changes remove the manager
ClusterRole, but a ClusterRole still remains for the metrics auth proxy when
metrics.disableAuth is false (the default). auth_proxy.yaml grants the sidecar
tokenreviews and subjectaccessreviews create; TokenReview is inherently
cluster-scoped with no namespaced form, so it cannot be reduced to a Role.
Operators who need zero ClusterRoles in namespace-scoped mode must also set
metrics.disableAuth: true (the chart already suggests NetworkPolicy or
same-namespace Prometheus as the alternative). Worth deciding whether the chart
should validate/warn on that combination, but that is separate from this request.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with rbac.yaml:300-321 and trace NewWorkerResourceTemplateValidator in workerresourcetemplate_webhook.go, including the checks in webhook.go:511-517. Then read main.go:195-203 and execplan.go:199-211 to resolve whether the identity suffix should use the ServiceAccount UID or namespace name. Done means namespace-scoped mode no longer needs the manager ClusterRole, while the metrics auth proxy caveat remains explicit.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, kubernetes
Domain
devops, infrastructure, security
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.