You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by vi...@apache.org on 2026/05/14 02:19:31 UTC

(superset-kubernetes-operator) branch main updated: feat: add namespace-scoped install mode (#54)

This is an automated email from the ASF dual-hosted git repository.

villebro pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/superset-kubernetes-operator.git


The following commit(s) were added to refs/heads/main by this push:
     new 7a01fb7  feat: add namespace-scoped install mode (#54)
7a01fb7 is described below

commit 7a01fb7e8ed357724d78b3422b06f3922991b714
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Wed May 13 19:19:26 2026 -0700

    feat: add namespace-scoped install mode (#54)
---
 charts/superset-operator/templates/_helpers.tpl    | 70 ++++++++++++++++++++++
 .../superset-operator/templates/clusterrole.yaml   | 40 ++-----------
 .../templates/clusterrolebinding.yaml              |  2 +
 charts/superset-operator/templates/deployment.yaml |  5 ++
 .../{clusterrolebinding.yaml => role.yaml}         | 24 ++++----
 .../{clusterrolebinding.yaml => rolebinding.yaml}  | 22 ++++---
 charts/superset-operator/values.yaml               | 24 ++++++++
 cmd/main.go                                        | 33 ++++++++++
 cmd/main_test.go                                   | 53 ++++++++++++++++
 .../components/watch-namespace/kustomization.yaml  | 53 ++++++++++++++++
 .../watch-namespace/manager_rolebinding.yaml       | 22 ++++---
 .../manager_watch_namespace_patch.yaml             | 26 ++++----
 config/default/kustomization.yaml                  |  9 +++
 docs/index.md                                      |  1 +
 docs/reference/security.md                         | 53 ++++++++++++----
 docs/user-guide/installation.md                    | 48 +++++++++++++++
 16 files changed, 401 insertions(+), 84 deletions(-)

diff --git a/charts/superset-operator/templates/_helpers.tpl b/charts/superset-operator/templates/_helpers.tpl
index 34251fc..7f39602 100644
--- a/charts/superset-operator/templates/_helpers.tpl
+++ b/charts/superset-operator/templates/_helpers.tpl
@@ -84,3 +84,73 @@ Manager image.
 {{- $tag := default .Chart.AppVersion .Values.image.tag }}
 {{- printf "%s:%s" .Values.image.repository $tag }}
 {{- end }}
+
+{{/*
+Validate watch.scope. Must be "cluster" or "namespaces".
+*/}}
+{{- define "superset-operator.validateWatchScope" -}}
+{{- $scope := default "cluster" .Values.watch.scope -}}
+{{- if not (has $scope (list "cluster" "namespaces")) -}}
+{{- fail (printf "watch.scope must be \"cluster\" or \"namespaces\", got %q" $scope) -}}
+{{- end -}}
+{{- end }}
+
+{{/*
+Canonical comma-separated list of watched namespaces. Empty/whitespace
+entries are skipped, duplicates removed. When the resulting list is empty
+the release namespace is used.
+*/}}
+{{- define "superset-operator.watchNamespacesCSV" -}}
+{{- $out := list -}}
+{{- range default (list) .Values.watch.namespaces -}}
+  {{- $t := trim . -}}
+  {{- if $t -}}{{- $out = append $out $t -}}{{- end -}}
+{{- end -}}
+{{- if not $out -}}{{- $out = list .Release.Namespace -}}{{- end -}}
+{{- $out | uniq | join "," -}}
+{{- end }}
+
+{{/*
+Manager RBAC rules. Shared by the cluster-scoped ClusterRole and the
+per-namespace Roles so the two render paths can't drift. Include with
+{{- include "superset-operator.managerRules" . | nindent N }} at the
+desired indentation.
+*/}}
+{{- define "superset-operator.managerRules" -}}
+- apiGroups: [""]
+  resources: [configmaps, serviceaccounts, services]
+  verbs: [create, delete, get, list, patch, update, watch]
+- apiGroups: [""]
+  resources: [pods]
+  verbs: [create, delete, get, list, watch]
+- apiGroups: [apps]
+  resources: [deployments]
+  verbs: [create, delete, get, list, patch, update, watch]
+- apiGroups: [autoscaling]
+  resources: [horizontalpodautoscalers]
+  verbs: [create, delete, get, list, patch, update, watch]
+- apiGroups: [events.k8s.io]
+  resources: [events]
+  verbs: [create, patch, update]
+- apiGroups: [gateway.networking.k8s.io]
+  resources: [httproutes]
+  verbs: [create, delete, get, list, patch, update, watch]
+- apiGroups: [monitoring.coreos.com]
+  resources: [servicemonitors]
+  verbs: [create, delete, get, list, patch, update, watch]
+- apiGroups: [networking.k8s.io]
+  resources: [ingresses, networkpolicies]
+  verbs: [create, delete, get, list, patch, update, watch]
+- apiGroups: [policy]
+  resources: [poddisruptionbudgets]
+  verbs: [create, delete, get, list, patch, update, watch]
+- apiGroups: [superset.apache.org]
+  resources: [supersetcelerybeats, supersetceleryflowers, supersetceleryworkers, supersetlifecycletasks, supersetmcpservers, supersetwebservers, supersetwebsocketservers]
+  verbs: [create, delete, get, list, patch, update, watch]
+- apiGroups: [superset.apache.org]
+  resources: [supersetcelerybeats/status, supersetceleryflowers/status, supersetceleryworkers/status, supersetlifecycletasks/status, supersetmcpservers/status, supersets/status, supersetwebservers/status, supersetwebsocketservers/status]
+  verbs: [get, patch, update]
+- apiGroups: [superset.apache.org]
+  resources: [supersets]
+  verbs: [get, list, watch]
+{{- end }}
diff --git a/charts/superset-operator/templates/clusterrole.yaml b/charts/superset-operator/templates/clusterrole.yaml
index 0e6cea1..5fbb720 100644
--- a/charts/superset-operator/templates/clusterrole.yaml
+++ b/charts/superset-operator/templates/clusterrole.yaml
@@ -13,6 +13,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+{{- include "superset-operator.validateWatchScope" . -}}
+{{- if eq (default "cluster" .Values.watch.scope) "cluster" }}
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRole
 metadata:
@@ -20,39 +22,5 @@ metadata:
   labels:
     {{- include "superset-operator.labels" . | nindent 4 }}
 rules:
-  - apiGroups: [""]
-    resources: [configmaps, serviceaccounts, services]
-    verbs: [create, delete, get, list, patch, update, watch]
-  - apiGroups: [""]
-    resources: [pods]
-    verbs: [create, delete, get, list, watch]
-  - apiGroups: [apps]
-    resources: [deployments]
-    verbs: [create, delete, get, list, patch, update, watch]
-  - apiGroups: [autoscaling]
-    resources: [horizontalpodautoscalers]
-    verbs: [create, delete, get, list, patch, update, watch]
-  - apiGroups: [events.k8s.io]
-    resources: [events]
-    verbs: [create, patch, update]
-  - apiGroups: [gateway.networking.k8s.io]
-    resources: [httproutes]
-    verbs: [create, delete, get, list, patch, update, watch]
-  - apiGroups: [monitoring.coreos.com]
-    resources: [servicemonitors]
-    verbs: [create, delete, get, list, patch, update, watch]
-  - apiGroups: [networking.k8s.io]
-    resources: [ingresses, networkpolicies]
-    verbs: [create, delete, get, list, patch, update, watch]
-  - apiGroups: [policy]
-    resources: [poddisruptionbudgets]
-    verbs: [create, delete, get, list, patch, update, watch]
-  - apiGroups: [superset.apache.org]
-    resources: [supersetcelerybeats, supersetceleryflowers, supersetceleryworkers, supersetlifecycletasks, supersetmcpservers, supersetwebservers, supersetwebsocketservers]
-    verbs: [create, delete, get, list, patch, update, watch]
-  - apiGroups: [superset.apache.org]
-    resources: [supersetcelerybeats/status, supersetceleryflowers/status, supersetceleryworkers/status, supersetlifecycletasks/status, supersetmcpservers/status, supersets/status, supersetwebservers/status, supersetwebsocketservers/status]
-    verbs: [get, patch, update]
-  - apiGroups: [superset.apache.org]
-    resources: [supersets]
-    verbs: [get, list, watch]
+  {{- include "superset-operator.managerRules" . | nindent 2 }}
+{{- end }}
diff --git a/charts/superset-operator/templates/clusterrolebinding.yaml b/charts/superset-operator/templates/clusterrolebinding.yaml
index f4b56d6..901f600 100644
--- a/charts/superset-operator/templates/clusterrolebinding.yaml
+++ b/charts/superset-operator/templates/clusterrolebinding.yaml
@@ -13,6 +13,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+{{- if eq (default "cluster" .Values.watch.scope) "cluster" }}
 apiVersion: rbac.authorization.k8s.io/v1
 kind: ClusterRoleBinding
 metadata:
@@ -27,3 +28,4 @@ subjects:
   - kind: ServiceAccount
     name: {{ include "superset-operator.serviceAccountName" . }}
     namespace: {{ .Release.Namespace }}
+{{- end }}
diff --git a/charts/superset-operator/templates/deployment.yaml b/charts/superset-operator/templates/deployment.yaml
index f6d2909..b0282cd 100644
--- a/charts/superset-operator/templates/deployment.yaml
+++ b/charts/superset-operator/templates/deployment.yaml
@@ -75,6 +75,11 @@ spec:
           readinessProbe:
             {{- toYaml . | nindent 12 }}
           {{- end }}
+          {{- if eq (default "cluster" .Values.watch.scope) "namespaces" }}
+          env:
+            - name: WATCH_NAMESPACE
+              value: {{ include "superset-operator.watchNamespacesCSV" . | quote }}
+          {{- end }}
           {{- with .Values.resources }}
           resources:
             {{- toYaml . | nindent 12 }}
diff --git a/charts/superset-operator/templates/clusterrolebinding.yaml b/charts/superset-operator/templates/role.yaml
similarity index 63%
copy from charts/superset-operator/templates/clusterrolebinding.yaml
copy to charts/superset-operator/templates/role.yaml
index f4b56d6..e19c156 100644
--- a/charts/superset-operator/templates/clusterrolebinding.yaml
+++ b/charts/superset-operator/templates/role.yaml
@@ -13,17 +13,19 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+{{- include "superset-operator.validateWatchScope" . -}}
+{{- if eq (default "cluster" .Values.watch.scope) "namespaces" }}
+{{- $root := . -}}
+{{- range $ns := splitList "," (include "superset-operator.watchNamespacesCSV" $root) }}
+---
 apiVersion: rbac.authorization.k8s.io/v1
-kind: ClusterRoleBinding
+kind: Role
 metadata:
-  name: {{ include "superset-operator.fullname" . }}-manager
+  name: {{ include "superset-operator.fullname" $root }}-manager
+  namespace: {{ $ns }}
   labels:
-    {{- include "superset-operator.labels" . | nindent 4 }}
-roleRef:
-  apiGroup: rbac.authorization.k8s.io
-  kind: ClusterRole
-  name: {{ include "superset-operator.fullname" . }}-manager
-subjects:
-  - kind: ServiceAccount
-    name: {{ include "superset-operator.serviceAccountName" . }}
-    namespace: {{ .Release.Namespace }}
+    {{- include "superset-operator.labels" $root | nindent 4 }}
+rules:
+  {{- include "superset-operator.managerRules" $root | nindent 2 }}
+{{- end }}
+{{- end }}
diff --git a/charts/superset-operator/templates/clusterrolebinding.yaml b/charts/superset-operator/templates/rolebinding.yaml
similarity index 59%
copy from charts/superset-operator/templates/clusterrolebinding.yaml
copy to charts/superset-operator/templates/rolebinding.yaml
index f4b56d6..67a1c44 100644
--- a/charts/superset-operator/templates/clusterrolebinding.yaml
+++ b/charts/superset-operator/templates/rolebinding.yaml
@@ -13,17 +13,25 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+{{- include "superset-operator.validateWatchScope" . -}}
+{{- if eq (default "cluster" .Values.watch.scope) "namespaces" }}
+{{- $root := . -}}
+{{- range $ns := splitList "," (include "superset-operator.watchNamespacesCSV" $root) }}
+---
 apiVersion: rbac.authorization.k8s.io/v1
-kind: ClusterRoleBinding
+kind: RoleBinding
 metadata:
-  name: {{ include "superset-operator.fullname" . }}-manager
+  name: {{ include "superset-operator.fullname" $root }}-manager
+  namespace: {{ $ns }}
   labels:
-    {{- include "superset-operator.labels" . | nindent 4 }}
+    {{- include "superset-operator.labels" $root | nindent 4 }}
 roleRef:
   apiGroup: rbac.authorization.k8s.io
-  kind: ClusterRole
-  name: {{ include "superset-operator.fullname" . }}-manager
+  kind: Role
+  name: {{ include "superset-operator.fullname" $root }}-manager
 subjects:
   - kind: ServiceAccount
-    name: {{ include "superset-operator.serviceAccountName" . }}
-    namespace: {{ .Release.Namespace }}
+    name: {{ include "superset-operator.serviceAccountName" $root }}
+    namespace: {{ $root.Release.Namespace }}
+{{- end }}
+{{- end }}
diff --git a/charts/superset-operator/values.yaml b/charts/superset-operator/values.yaml
index 99d2707..2aca74c 100644
--- a/charts/superset-operator/values.yaml
+++ b/charts/superset-operator/values.yaml
@@ -96,3 +96,27 @@ affinity: {}
 
 podAnnotations: {}
 podLabels: {}
+
+# watch controls which namespaces the operator reconciles.
+#
+# scope: cluster (default) — watch all namespaces. Manager RBAC is rendered
+#   as ClusterRole + ClusterRoleBinding. Requires cluster-scoped RBAC on
+#   install.
+# scope: namespaces — watch only the namespaces listed in watch.namespaces
+#   (empty list falls back to the release namespace). Manager RBAC is
+#   rendered as a Role + RoleBinding per watched namespace; no manager
+#   ClusterRole is created. Use this on restricted clusters that forbid
+#   cluster-scoped RBAC, or for single-tenant hardening.
+#
+# Constraints:
+# - CRD installation always requires cluster-admin, regardless of scope.
+# - Secure metrics auth still needs a cluster-scoped RBAC entry because
+#   TokenReview/SubjectAccessReview are cluster-level APIs. On clusters that
+#   forbid ClusterRole entirely, set metrics.enabled=false.
+# - Updating watch.namespaces requires `helm upgrade` and restarts the
+#   manager so the cache picks up the new list.
+# - Superset CRs created in namespaces outside watch.namespaces are not
+#   reconciled (no log, no status).
+watch:
+  scope: cluster
+  namespaces: []
diff --git a/cmd/main.go b/cmd/main.go
index e730fa8..5dc2eaa 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -23,6 +23,8 @@ import (
 	"flag"
 	"os"
 	"path/filepath"
+	"sort"
+	"strings"
 
 	// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
 	// to ensure that exec-entrypoint and run can make use of them.
@@ -32,6 +34,7 @@ import (
 	utilruntime "k8s.io/apimachinery/pkg/util/runtime"
 	clientgoscheme "k8s.io/client-go/kubernetes/scheme"
 	ctrl "sigs.k8s.io/controller-runtime"
+	"sigs.k8s.io/controller-runtime/pkg/cache"
 	"sigs.k8s.io/controller-runtime/pkg/certwatcher"
 	"sigs.k8s.io/controller-runtime/pkg/healthz"
 	"sigs.k8s.io/controller-runtime/pkg/log/zap"
@@ -151,12 +154,20 @@ func main() {
 		})
 	}
 
+	defaultNamespaces := parseWatchNamespaces(os.Getenv("WATCH_NAMESPACE"))
+	if len(defaultNamespaces) > 0 {
+		setupLog.Info("watching namespaces", "namespaces", sortedKeys(defaultNamespaces))
+	} else {
+		setupLog.Info("watching all namespaces (cluster-scoped)")
+	}
+
 	mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
 		Scheme:                 scheme,
 		Metrics:                metricsServerOptions,
 		HealthProbeBindAddress: probeAddr,
 		LeaderElection:         enableLeaderElection,
 		LeaderElectionID:       "258102fe.apache.org",
+		Cache:                  cache.Options{DefaultNamespaces: defaultNamespaces},
 		// LeaderElectionReleaseOnCancel defines if the leader should step down voluntarily
 		// when the Manager ends. This requires the binary to immediately end when the
 		// Manager is stopped, otherwise, this setting is unsafe. Setting this significantly
@@ -224,3 +235,25 @@ func main() {
 		os.Exit(1)
 	}
 }
+
+// parseWatchNamespaces parses a comma-separated namespace list from the
+// WATCH_NAMESPACE env var. Whitespace is trimmed and empty entries are
+// skipped. An empty result yields a cluster-scoped watch.
+func parseWatchNamespaces(raw string) map[string]cache.Config {
+	out := map[string]cache.Config{}
+	for ns := range strings.SplitSeq(raw, ",") {
+		if ns = strings.TrimSpace(ns); ns != "" {
+			out[ns] = cache.Config{}
+		}
+	}
+	return out
+}
+
+func sortedKeys(m map[string]cache.Config) []string {
+	keys := make([]string, 0, len(m))
+	for k := range m {
+		keys = append(keys, k)
+	}
+	sort.Strings(keys)
+	return keys
+}
diff --git a/cmd/main_test.go b/cmd/main_test.go
new file mode 100644
index 0000000..00f760a
--- /dev/null
+++ b/cmd/main_test.go
@@ -0,0 +1,53 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package main
+
+import (
+	"testing"
+)
+
+func TestParseWatchNamespaces(t *testing.T) {
+	tests := []struct {
+		name string
+		raw  string
+		want []string
+	}{
+		{"empty", "", nil},
+		{"whitespace only", "   ", nil},
+		{"single", "team-a", []string{"team-a"}},
+		{"single with whitespace", "  team-a  ", []string{"team-a"}},
+		{"csv", "team-a,team-b", []string{"team-a", "team-b"}},
+		{"csv with whitespace", "team-a, team-b , team-c", []string{"team-a", "team-b", "team-c"}},
+		{"empty entries skipped", "team-a, ,team-b,", []string{"team-a", "team-b"}},
+		{"duplicates collapsed", "team-a,team-a,team-b", []string{"team-a", "team-b"}},
+	}
+	for _, tc := range tests {
+		t.Run(tc.name, func(t *testing.T) {
+			got := parseWatchNamespaces(tc.raw)
+			if len(got) != len(tc.want) {
+				t.Fatalf("got %d namespaces, want %d: %v", len(got), len(tc.want), sortedKeys(got))
+			}
+			for _, ns := range tc.want {
+				if _, ok := got[ns]; !ok {
+					t.Errorf("missing namespace %q; got %v", ns, sortedKeys(got))
+				}
+			}
+		})
+	}
+}
diff --git a/config/components/watch-namespace/kustomization.yaml b/config/components/watch-namespace/kustomization.yaml
new file mode 100644
index 0000000..112198a
--- /dev/null
+++ b/config/components/watch-namespace/kustomization.yaml
@@ -0,0 +1,53 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Switches the operator from cluster-scoped to namespace-scoped reconciliation.
+# The manager watches only its own deployment namespace via the Downward API.
+# The ClusterRole generated by controller-gen is retained (it's the
+# authoritative source of the permission set), but the ClusterRoleBinding
+# is replaced with a namespaced RoleBinding that references the same
+# ClusterRole. A RoleBinding pointing at a ClusterRole limits the granted
+# permissions to the binding's namespace — so the operator's namespaced
+# resource access is confined to where the binding lives.
+#
+# For multi-namespace watch via kustomize, extend this component: add one
+# RoleBinding per target namespace and set WATCH_NAMESPACE to a comma-
+# separated list (replace the Downward API patch below with a literal value).
+#
+# CRD installation still requires cluster-admin regardless of watch scope.
+# Secure metrics auth still needs cluster-scoped RBAC (TokenReview /
+# SubjectAccessReview are cluster-level APIs). If you cannot grant that,
+# comment out the metrics_auth_role.yaml, metrics_auth_role_binding.yaml,
+# and metrics_reader_role.yaml entries in config/rbac/kustomization.yaml,
+# and drop the [METRICS] patch + metrics_service.yaml from
+# config/default/kustomization.yaml.
+
+apiVersion: kustomize.config.k8s.io/v1alpha1
+kind: Component
+
+patches:
+  - path: manager_watch_namespace_patch.yaml
+    target:
+      kind: Deployment
+      name: controller-manager
+  - patch: |-
+      $patch: delete
+      apiVersion: rbac.authorization.k8s.io/v1
+      kind: ClusterRoleBinding
+      metadata:
+        name: manager-rolebinding
+
+resources:
+  - manager_rolebinding.yaml
diff --git a/charts/superset-operator/templates/clusterrolebinding.yaml b/config/components/watch-namespace/manager_rolebinding.yaml
similarity index 59%
copy from charts/superset-operator/templates/clusterrolebinding.yaml
copy to config/components/watch-namespace/manager_rolebinding.yaml
index f4b56d6..e2ab242 100644
--- a/charts/superset-operator/templates/clusterrolebinding.yaml
+++ b/config/components/watch-namespace/manager_rolebinding.yaml
@@ -13,17 +13,25 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# Namespaced RoleBinding that binds the generated manager ClusterRole to the
+# operator ServiceAccount. Because this is a RoleBinding (not a
+# ClusterRoleBinding), the granted permissions apply only to this namespace
+# — which confines the operator's namespaced resource access to wherever
+# this binding is created.
+#
+# The `namespace: system` placeholder on the subject matches the one used by
+# config/rbac/role_binding.yaml; the parent kustomization's top-level
+# namespace: field rewrites it at build time.
+
 apiVersion: rbac.authorization.k8s.io/v1
-kind: ClusterRoleBinding
+kind: RoleBinding
 metadata:
-  name: {{ include "superset-operator.fullname" . }}-manager
-  labels:
-    {{- include "superset-operator.labels" . | nindent 4 }}
+  name: manager-rolebinding
 roleRef:
   apiGroup: rbac.authorization.k8s.io
   kind: ClusterRole
-  name: {{ include "superset-operator.fullname" . }}-manager
+  name: manager-role
 subjects:
   - kind: ServiceAccount
-    name: {{ include "superset-operator.serviceAccountName" . }}
-    namespace: {{ .Release.Namespace }}
+    name: controller-manager
+    namespace: system
diff --git a/charts/superset-operator/templates/clusterrolebinding.yaml b/config/components/watch-namespace/manager_watch_namespace_patch.yaml
similarity index 62%
copy from charts/superset-operator/templates/clusterrolebinding.yaml
copy to config/components/watch-namespace/manager_watch_namespace_patch.yaml
index f4b56d6..ad6b621 100644
--- a/charts/superset-operator/templates/clusterrolebinding.yaml
+++ b/config/components/watch-namespace/manager_watch_namespace_patch.yaml
@@ -13,17 +13,17 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-apiVersion: rbac.authorization.k8s.io/v1
-kind: ClusterRoleBinding
+apiVersion: apps/v1
+kind: Deployment
 metadata:
-  name: {{ include "superset-operator.fullname" . }}-manager
-  labels:
-    {{- include "superset-operator.labels" . | nindent 4 }}
-roleRef:
-  apiGroup: rbac.authorization.k8s.io
-  kind: ClusterRole
-  name: {{ include "superset-operator.fullname" . }}-manager
-subjects:
-  - kind: ServiceAccount
-    name: {{ include "superset-operator.serviceAccountName" . }}
-    namespace: {{ .Release.Namespace }}
+  name: controller-manager
+spec:
+  template:
+    spec:
+      containers:
+        - name: manager
+          env:
+            - name: WATCH_NAMESPACE
+              valueFrom:
+                fieldRef:
+                  fieldPath: metadata.namespace
diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml
index 0db6f42..6060232 100644
--- a/config/default/kustomization.yaml
+++ b/config/default/kustomization.yaml
@@ -28,6 +28,15 @@ resources:
 # self-signed built-in cert to a cert-manager Certificate.
 #- ../certmanager
 
+# [NAMESPACED] Switch the operator to namespace-scoped mode: the manager
+# watches only its own deployment namespace (Downward API), the manager
+# ClusterRoleBinding is replaced with a namespaced RoleBinding to the same
+# ClusterRole. CRD installation still requires cluster-admin. For multi-
+# namespace watch, fork the component and add one RoleBinding per target
+# namespace (see comment inside component kustomization.yaml).
+#components:
+#- ../components/watch-namespace
+
 patches:
 # [METRICS] The following patch will enable the metrics endpoint using HTTPS and the port :8443.
 # More info: https://book.kubebuilder.io/reference/metrics
diff --git a/docs/index.md b/docs/index.md
index 1aa651e..9a4b0c5 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -36,6 +36,7 @@ The operator manages the full Superset lifecycle: database migrations, configura
 - **Lifecycle automation** — database cloning, schema migrations, secret key rotation, and application init run as sequenced tasks with automatic change detection and checksum-based re-execution
 - **Networking** — Gateway API (HTTPRoute) and Ingress support with per-component routing
 - **Production hardening** — HPA with custom metrics, PodDisruptionBudgets, NetworkPolicies, Prometheus ServiceMonitor
+- **Flexible install scope** — cluster-scoped (default) or namespace-scoped; the namespace-scoped Helm install renders no manager `ClusterRole` at all, so it works on restricted clusters that forbid cluster-scoped RBAC
 
 ## What it looks like
 
diff --git a/docs/reference/security.md b/docs/reference/security.md
index 8480f42..15a4828 100644
--- a/docs/reference/security.md
+++ b/docs/reference/security.md
@@ -267,16 +267,49 @@ The operator does **not** request:
 
 ### Install Scope
 
-The operator currently installs cluster-scoped: the manager ServiceAccount is
-bound to a `ClusterRole` and watches `Superset` CRs across every namespace.
-This is the common operator pattern and fits clusters where the operator is
-administered centrally by cluster admins.
-
-A namespace-scoped install mode (single-namespace watch with
-`Role`/`RoleBinding` instead of `ClusterRole`/`ClusterRoleBinding`) is a
-future consideration for single-tenant deployments that want a tighter blast
-radius. CRD installation would still require cluster-admin privileges; only
-the runtime watch scope and RBAC would narrow.
+The operator supports two install modes, selectable at deploy time:
+
+- **Cluster-scoped (default).** The manager ServiceAccount is bound to a
+  `ClusterRole` via a `ClusterRoleBinding`, and the cache watches every
+  namespace. Appropriate when a cluster admin administers the operator
+  centrally. Helm: `watch.scope: cluster`.
+- **Namespace-scoped.** The manager watches only the namespaces listed in
+  `WATCH_NAMESPACE` (comma-separated). Appropriate for restricted clusters
+  that forbid `ClusterRole` creation, or for single-tenant installs that
+  want a tighter blast radius.
+
+The RBAC shape differs between Helm and Kustomize for namespace-scoped
+installs:
+
+- **Helm (`watch.scope: namespaces`)** renders one `Role` and one
+  `RoleBinding` per watched namespace, and does **not** create a manager
+  `ClusterRole`/`ClusterRoleBinding` at all. With CRDs preinstalled by a
+  cluster admin and `metrics.enabled: false`, this install succeeds on
+  clusters that deny cluster-scoped RBAC to the installer (see the
+  Constraints list below).
+- **Kustomize (`config/components/watch-namespace/`)** retains the
+  controller-gen–generated `ClusterRole` but replaces the
+  `ClusterRoleBinding` with a namespaced `RoleBinding` pointing at that
+  same `ClusterRole`. A `RoleBinding` → `ClusterRole` pairing restricts
+  the granted permissions to the binding's namespace. The Kustomize path
+  therefore still requires cluster-scoped RBAC *at install time* for the
+  `ClusterRole`; its runtime footprint is namespace-scoped.
+
+Constraints common to both paths:
+
+- **CRD installation always needs cluster-admin.** CRDs are cluster-scoped
+  resources; watch-scope does not change that.
+- **Secure metrics auth still needs cluster-scoped RBAC.** The metrics
+  endpoint uses `TokenReview`/`SubjectAccessReview`, which are cluster-level
+  APIs. On clusters that forbid `ClusterRole` entirely, disable metrics
+  (`metrics.enabled: false` in Helm values).
+- **Changing the watched-namespace list requires a manager restart.** The
+  manager cache is built at startup; dynamic reconfiguration is not
+  supported.
+- **Superset CRs in unwatched namespaces are silently ignored.** The
+  operator logs the watched set at startup but does not detect stray CRs
+  elsewhere — confirm by tailing the startup log or listing `Supersets`
+  across namespaces manually if users report missing reconciliation.
 
 ## What Is In Scope
 
diff --git a/docs/user-guide/installation.md b/docs/user-guide/installation.md
index 16ca4f4..e0389f7 100644
--- a/docs/user-guide/installation.md
+++ b/docs/user-guide/installation.md
@@ -58,6 +58,54 @@ helm install superset-operator \
 See `charts/superset-operator/values.yaml` for all available Helm values and
 [Downloads](../reference/downloads.md) for published images and tag conventions.
 
+### Namespace-scoped install
+
+By default the operator installs cluster-scoped (watches all namespaces and
+binds a `ClusterRole`). For restricted clusters that forbid cluster-scoped
+RBAC, or for single-tenant hardening, switch to namespace-scoped mode.
+
+With Helm, set `watch.scope: namespaces` and list the namespaces to watch:
+
+```bash
+helm install superset-operator \
+  oci://ghcr.io/apache/superset-kubernetes-operator/charts/superset-operator \
+  --version <version> \
+  --namespace superset-operator-system \
+  --create-namespace \
+  --set watch.scope=namespaces \
+  --set 'watch.namespaces={team-a,team-b}'
+```
+
+Each namespace in `watch.namespaces` must already exist — Helm renders
+`Role` and `RoleBinding` resources into those namespaces during install and
+will fail if they are absent. Create them up front (e.g.,
+`kubectl create namespace team-a`).
+
+An empty `watch.namespaces` list falls back to watching the release
+namespace only. In namespace-scoped mode the chart renders a `Role` +
+`RoleBinding` per watched namespace and does not create a manager
+`ClusterRole`/`ClusterRoleBinding`.
+
+Kustomize users can opt in via the bundled `watch-namespace` component —
+uncomment the `[NAMESPACED]` block in `config/default/kustomization.yaml`.
+The Kustomize path is single-namespace only (the manager watches its own
+deployment namespace via the Downward API); for multi-namespace watch,
+extend the component.
+
+**Constraints in both modes:**
+
+- CRD installation always requires cluster-admin — CRDs are cluster-scoped.
+- Secure metrics auth (`TokenReview`/`SubjectAccessReview`) needs
+  cluster-scoped RBAC. On clusters that forbid `ClusterRole` entirely, set
+  `metrics.enabled: false`.
+- Changing `watch.namespaces` requires a `helm upgrade` — the manager cache
+  is built at startup, so the pod must restart to pick up a new list.
+- Superset CRs created in namespaces outside `watch.namespaces` are not
+  reconciled (no log, no status).
+
+See [Install Scope](../reference/security.md#install-scope) in the security
+reference for the trust-model context.
+
 ## 2. Create secrets
 
 Superset requires a secret key for session signing. In production, mount it