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/09/04 22:03:45 UTC

(superset-kubernetes-operator) branch main updated: fix(controller): enforce environment gates controller-side (#327)

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 f8bdeb4  fix(controller): enforce environment gates controller-side (#327)
f8bdeb4 is described below

commit f8bdeb4c24f88aba8ab866fb808fecb7a3b9814b
Author: Ville Brofeldt <33...@users.noreply.github.com>
AuthorDate: Fri Sep 4 15:03:39 2026 -0700

    fix(controller): enforce environment gates controller-side (#327)
    
    * fix(controller): enforce environment gates controller-side
    
    A Claude security scan noted that environment-dependent guarantees were
    enforced only at CEL admission, once, with no controller-side re-check —
    unlike createDatabaseEnabled, which already re-verifies defensively. This
    change closes three related gaps.
    
    - No transition rules: environment was freely mutable, so one update could
      flip Production to Staging (re-arming the destructive seed against the
      unchanged production metastore references) or to Development (re-admitting
      inline secrets on a live instance). A new CEL transition rule rejects any
      in-place change of environment out of Production (the defaulted-absent form
      counts as Production); the opt-out is delete-and-recreate.
    
    - Inline-secret literals lacked the Development re-check that secretKey and
      valkey.password already have. The metastore URI/password, seed source and
      target passwords, and the create-database password literal branches are now
      gated on a shared isDevEnvironment helper: outside Development the inline
      value is dropped and only the *From secret reference is honored. This is
      pure defense in depth — it only matters if CEL is ever absent or skewed
      (older CRD, direct etcd write, apiserver without CEL).
    
    - The destructive seed (its default script opens with DROP DATABASE) had no
      controller-side environment guard. reconcileLifecycle now runs
      gateOnSeedEnvironment alongside gateOnInvalidSeedSchedule: when seed is
      present and not disabled but environment is not Development/Staging, the
      pipeline is blocked with a SeedEnvironmentNotAllowed condition, Blocked
      phase, and a Warning event — the seed Job is never created.
    
    Release note: a Production Superset CR can no longer be downgraded in place to
    Development or Staging; delete and recreate the instance to change environment
    out of Production. Upgrades toward Production and non-Production transitions
    are unaffected.
    
    Generated-by: Claude
    
    * docs: note environment transition guard
---
 api/v1alpha1/superset_types.go                     |  1 +
 .../crds/superset.apache.org_supersets.yaml        |  7 ++
 .../crd/bases/superset.apache.org_supersets.yaml   |  7 ++
 docs/reference/releases.md                         |  1 +
 internal/controller/cel_validation_test.go         | 40 +++++++++++
 internal/controller/config_builder.go              | 17 ++++-
 internal/controller/config_test.go                 | 43 ++++++++++-
 internal/controller/lifecycle.go                   | 36 ++++++++++
 internal/controller/lifecycle_create_db.go         |  6 +-
 internal/controller/lifecycle_create_db_test.go    |  2 +
 internal/controller/lifecycle_seed.go              |  5 +-
 internal/controller/seed_test.go                   | 83 ++++++++++++++++++++++
 12 files changed, 239 insertions(+), 9 deletions(-)

diff --git a/api/v1alpha1/superset_types.go b/api/v1alpha1/superset_types.go
index d5967e5..15bed79 100644
--- a/api/v1alpha1/superset_types.go
+++ b/api/v1alpha1/superset_types.go
@@ -967,6 +967,7 @@ type ComponentResourceStatus struct {
 // +kubebuilder:validation:XValidation:rule="!has(self.spec.lifecycle) || !has(self.spec.lifecycle.rotate) || size(self.metadata.name) <= 49",message="metadata.name must be at most 49 characters when lifecycle.rotate is enabled (task name '{parent}-rotate' + ConfigMap suffix '-config' must fit within 63 chars)"
 // +kubebuilder:validation:XValidation:rule="(has(self.spec.lifecycle) && has(self.spec.lifecycle.disabled) && self.spec.lifecycle.disabled == true) || size(self.metadata.name) <= 48",message="metadata.name must be at most 48 characters when lifecycle is enabled (task name '{parent}-migrate' + ConfigMap suffix '-config' must fit within 63 chars)"
 // +kubebuilder:validation:XValidation:rule="!has(self.spec.serviceAccount) || (has(self.spec.serviceAccount.create) && self.spec.serviceAccount.create == false) || !has(self.spec.serviceAccount.name) || self.spec.serviceAccount.name == self.metadata.name",message="serviceAccount.name must equal metadata.name when the operator creates the ServiceAccount (serviceAccount.create is true or unset); set serviceAccount.create=false to reference a pre-existing ServiceAccount with a different name"
+// +kubebuilder:validation:XValidation:rule="!((!has(oldSelf.spec.environment) || oldSelf.spec.environment == 'Production') && (has(self.spec.environment) && self.spec.environment != 'Production'))",message="environment cannot be changed from Production to Development or Staging in place (it would re-arm inline secrets and the destructive seed against production references); delete and recreate the Superset to change environment out of Production"
 
 // Superset is the top-level resource representing a complete Superset deployment.
 type Superset struct {
diff --git a/charts/superset-operator/crds/superset.apache.org_supersets.yaml b/charts/superset-operator/crds/superset.apache.org_supersets.yaml
index b6c2401..6d1fdd9 100644
--- a/charts/superset-operator/crds/superset.apache.org_supersets.yaml
+++ b/charts/superset-operator/crds/superset.apache.org_supersets.yaml
@@ -40134,6 +40134,13 @@ spec:
           rule: '!has(self.spec.serviceAccount) || (has(self.spec.serviceAccount.create)
             && self.spec.serviceAccount.create == false) || !has(self.spec.serviceAccount.name)
             || self.spec.serviceAccount.name == self.metadata.name'
+        - message: environment cannot be changed from Production to Development or
+            Staging in place (it would re-arm inline secrets and the destructive seed
+            against production references); delete and recreate the Superset to change
+            environment out of Production
+          rule: '!((!has(oldSelf.spec.environment) || oldSelf.spec.environment ==
+            ''Production'') && (has(self.spec.environment) && self.spec.environment
+            != ''Production''))'
     served: true
     storage: true
     subresources:
diff --git a/config/crd/bases/superset.apache.org_supersets.yaml b/config/crd/bases/superset.apache.org_supersets.yaml
index b6c2401..6d1fdd9 100644
--- a/config/crd/bases/superset.apache.org_supersets.yaml
+++ b/config/crd/bases/superset.apache.org_supersets.yaml
@@ -40134,6 +40134,13 @@ spec:
           rule: '!has(self.spec.serviceAccount) || (has(self.spec.serviceAccount.create)
             && self.spec.serviceAccount.create == false) || !has(self.spec.serviceAccount.name)
             || self.spec.serviceAccount.name == self.metadata.name'
+        - message: environment cannot be changed from Production to Development or
+            Staging in place (it would re-arm inline secrets and the destructive seed
+            against production references); delete and recreate the Superset to change
+            environment out of Production
+          rule: '!((!has(oldSelf.spec.environment) || oldSelf.spec.environment ==
+            ''Production'') && (has(self.spec.environment) && self.spec.environment
+            != ''Production''))'
     served: true
     storage: true
     subresources:
diff --git a/docs/reference/releases.md b/docs/reference/releases.md
index d200616..d5aa49e 100644
--- a/docs/reference/releases.md
+++ b/docs/reference/releases.md
@@ -33,6 +33,7 @@ This page tracks notable changes in Apache Superset Kubernetes Operator releases
 - **Breaking:** Valkey cache and results-backend `keyPrefix` values are now constrained to `^[A-Za-z0-9._:-]*$` (max 128 characters); values containing spaces, slashes, or other characters outside that set are rejected. The safer rendering also causes a one-time config-checksum change and pod roll on upgrade ([#325](https://github.com/apache/superset-kubernetes-operator/pull/325), [@villebro](https://github.com/villebro)).
 - Seed `excludeTables`, `excludeTableData`, and `postSeedSQL` values are now passed literally to generated seed scripts; values that previously relied on shell expansion no longer expand ([#325](https://github.com/apache/superset-kubernetes-operator/pull/325), [@villebro](https://github.com/villebro)).
 - **Breaking:** Celery Flower is no longer published on the Ingress/Gateway surface in `Production` by default. Flower's default command ships without authentication and its dashboard discloses task names and arguments — for Superset, other users' async SQL Lab statements and alert/report payloads. In `Production` (the default) Flower is fanned out onto the end-user host — and its port opened in the built-in NetworkPolicy — only when you explicitly set `celeryFlower.service.gatewayPath`; [...]
+- **Breaking:** A `Production` Superset CR can no longer be changed in place to `Development` or `Staging`; delete and recreate the instance to change environment out of `Production`. Upgrades toward `Production` and non-Production transitions are unaffected ([#327](https://github.com/apache/superset-kubernetes-operator/pull/327), [@villebro](https://github.com/villebro)).
 
 ## 0.2.0 - 2026-08-11
 
diff --git a/internal/controller/cel_validation_test.go b/internal/controller/cel_validation_test.go
index ac5281a..16a3db1 100644
--- a/internal/controller/cel_validation_test.go
+++ b/internal/controller/cel_validation_test.go
@@ -31,6 +31,7 @@ import (
 	"k8s.io/apimachinery/pkg/api/errors"
 	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
 	"k8s.io/apimachinery/pkg/util/intstr"
+	"sigs.k8s.io/controller-runtime/pkg/client"
 	gatewayv1 "sigs.k8s.io/gateway-api/apis/v1"
 
 	supersetv1alpha1 "github.com/apache/superset-kubernetes-operator/api/v1alpha1"
@@ -585,6 +586,45 @@ var _ = Describe("CEL Validation", Ordered, func() {
 		})
 	})
 
+	// --- Environment transitions (no in-place downgrade out of Production) ---
+
+	Describe("Environment transitions", func() {
+		It("rejects in-place downgrade from Production to Development", func() {
+			cr := validProdSuperset("env-downgrade-dev")
+			Expect(k8sClient.Create(ctx, cr)).To(Succeed())
+
+			// A live controller reconciles this CR and patches its status, bumping
+			// the resourceVersion; retry the read-modify-update so it lands on a
+			// current version and the CEL transition rule (not an optimistic-lock
+			// conflict) is what rejects the change.
+			Eventually(func(g Gomega) {
+				fetched := &supersetv1alpha1.Superset{}
+				g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(cr), fetched)).To(Succeed())
+				dev := common.EnvironmentDev
+				fetched.Spec.Environment = &dev
+				err := k8sClient.Update(ctx, fetched)
+				g.Expect(err).To(HaveOccurred())
+				g.Expect(err.Error()).To(ContainSubstring("environment cannot be changed from Production"))
+			}).Should(Succeed())
+		})
+
+		It("allows upgrade from Staging to Production", func() {
+			cr := validProdSuperset("env-upgrade-prod")
+			staging := common.EnvironmentStaging
+			cr.Spec.Environment = &staging
+			Expect(k8sClient.Create(ctx, cr)).To(Succeed())
+
+			// Retry read-modify-update around controller-driven status churn.
+			Eventually(func(g Gomega) {
+				fetched := &supersetv1alpha1.Superset{}
+				g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(cr), fetched)).To(Succeed())
+				prod := common.EnvironmentProd
+				fetched.Spec.Environment = &prod
+				g.Expect(k8sClient.Update(ctx, fetched)).To(Succeed())
+			}).Should(Succeed())
+		})
+	})
+
 	// --- Websocket server (experimental; config carries a JWT secret) ---
 
 	Describe("Websocket", func() {
diff --git a/internal/controller/config_builder.go b/internal/controller/config_builder.go
index aecc5ad..caa057e 100644
--- a/internal/controller/config_builder.go
+++ b/internal/controller/config_builder.go
@@ -237,11 +237,22 @@ func resolveValkeyResults(spec *supersetv1alpha1.ValkeyResultsBackendSpec, defau
 // collectSecretEnvVars gathers env vars for SECRET_KEY, metastore fields, valkey, and the
 // instance name. The instance name is exposed so admins can compute instance-scoped values
 // (e.g. Celery queue names) from raw Python in spec.config.
+
+// isDevEnvironment reports whether the CR is in Development mode. Inline secret
+// literals are only honored in Development. Re-checking here (not only via CEL)
+// keeps the controller defensive against a CR that slips past admission —
+// upgrades from older CRD versions, direct etcd writes, or an apiserver without
+// CEL — so such a CR can never materialize an inline secret into a pod spec.
+// Mirrors the defensive createDatabaseEnabled precedent.
+func isDevEnvironment(spec *supersetv1alpha1.SupersetSpec) bool {
+	return spec.Environment != nil && *spec.Environment == naming.EnvironmentDev
+}
+
 func collectSecretEnvVars(spec *supersetv1alpha1.SupersetSpec, parentName string) []corev1.EnvVar {
 	envs := []corev1.EnvVar{
 		{Name: naming.EnvInstanceName, Value: parentName},
 	}
-	isDev := spec.Environment != nil && *spec.Environment == naming.EnvironmentDev
+	isDev := isDevEnvironment(spec)
 
 	// SUPERSET_OPERATOR__SECRET_KEY — rendered into superset_config.py as SECRET_KEY.
 	if isDev && spec.SecretKey != nil {
@@ -271,7 +282,7 @@ func collectSecretEnvVars(spec *supersetv1alpha1.SupersetSpec, parentName string
 
 	// Metastore env vars.
 	if spec.Metastore != nil {
-		if spec.Metastore.URI != nil {
+		if isDev && spec.Metastore.URI != nil {
 			envs = append(envs, corev1.EnvVar{
 				Name:  naming.EnvDatabaseURI,
 				Value: *spec.Metastore.URI,
@@ -294,7 +305,7 @@ func collectSecretEnvVars(spec *supersetv1alpha1.SupersetSpec, parentName string
 			if spec.Metastore.Username != nil {
 				envs = append(envs, corev1.EnvVar{Name: naming.EnvDBUser, Value: *spec.Metastore.Username})
 			}
-			if spec.Metastore.Password != nil {
+			if isDev && spec.Metastore.Password != nil {
 				envs = append(envs, corev1.EnvVar{Name: naming.EnvDBPass, Value: *spec.Metastore.Password})
 			} else if spec.Metastore.PasswordFrom != nil {
 				envs = append(envs, corev1.EnvVar{
diff --git a/internal/controller/config_test.go b/internal/controller/config_test.go
index 74a746d..4c34931 100644
--- a/internal/controller/config_test.go
+++ b/internal/controller/config_test.go
@@ -229,9 +229,11 @@ func TestCollectSecretEnvVars_SecretKey(t *testing.T) {
 }
 
 func TestCollectSecretEnvVars_Metastore(t *testing.T) {
+	dev := common.EnvironmentDev
 	t.Run("passthrough", func(t *testing.T) {
 		spec := &supersetv1alpha1.SupersetSpec{
-			Metastore: &supersetv1alpha1.MetastoreSpec{URI: common.Ptr("postgresql://user:pass@host/db")},
+			Environment: &dev,
+			Metastore:   &supersetv1alpha1.MetastoreSpec{URI: common.Ptr("postgresql://user:pass@host/db")},
 		}
 		envs := collectSecretEnvVars(spec, "test")
 		envMap := envSliceToMap(envs)
@@ -242,6 +244,7 @@ func TestCollectSecretEnvVars_Metastore(t *testing.T) {
 
 	t.Run("structured with all fields", func(t *testing.T) {
 		spec := &supersetv1alpha1.SupersetSpec{
+			Environment: &dev,
 			Metastore: &supersetv1alpha1.MetastoreSpec{
 				Host: common.Ptr("db.example.com"), Port: common.Ptr(int32(5433)),
 				Database: common.Ptr("superset"), Username: common.Ptr("admin"), Password: common.Ptr("secret"),
@@ -285,6 +288,44 @@ func TestCollectSecretEnvVars_Metastore(t *testing.T) {
 			t.Errorf("expected default MySQL port 3306, got %s", envMap["SUPERSET_OPERATOR__DB_PORT"])
 		}
 	})
+
+	// Defense in depth: outside Development the inline metastore URI/password
+	// literals must be dropped even if a CR slips past CEL. The *From reference
+	// is honored instead when present.
+	t.Run("production drops inline uri literal", func(t *testing.T) {
+		prod := common.EnvironmentProd
+		spec := &supersetv1alpha1.SupersetSpec{
+			Environment: &prod,
+			Metastore:   &supersetv1alpha1.MetastoreSpec{URI: common.Ptr("postgresql://user:pass@host/db")},
+		}
+		envMap := envSliceToMap(collectSecretEnvVars(spec, "test"))
+		if _, ok := envMap["SUPERSET_OPERATOR__DB_URI"]; ok {
+			t.Errorf("inline metastore.uri must be dropped outside Development, got %v", envMap)
+		}
+	})
+
+	t.Run("production drops inline password literal but honors passwordFrom", func(t *testing.T) {
+		prod := common.EnvironmentProd
+		spec := &supersetv1alpha1.SupersetSpec{
+			Environment: &prod,
+			Metastore: &supersetv1alpha1.MetastoreSpec{
+				Host: common.Ptr("db.example.com"), Database: common.Ptr("superset"), Username: common.Ptr("admin"),
+				Password:     common.Ptr("secret"),
+				PasswordFrom: &corev1.SecretKeySelector{LocalObjectReference: corev1.LocalObjectReference{Name: "db"}, Key: "password"},
+			},
+		}
+		envs := collectSecretEnvVars(spec, "test")
+		for _, e := range envs {
+			if e.Name == "SUPERSET_OPERATOR__DB_PASS" {
+				if e.Value != "" {
+					t.Errorf("inline metastore.password must not be emitted as a literal outside Development, got %q", e.Value)
+				}
+				if e.ValueFrom == nil || e.ValueFrom.SecretKeyRef == nil {
+					t.Errorf("expected DB_PASS to fall back to passwordFrom secret reference, got %+v", e)
+				}
+			}
+		}
+	})
 }
 
 func TestBuildOperatorInjected(t *testing.T) {
diff --git a/internal/controller/lifecycle.go b/internal/controller/lifecycle.go
index 895455c..78d29f4 100644
--- a/internal/controller/lifecycle.go
+++ b/internal/controller/lifecycle.go
@@ -172,6 +172,15 @@ func (r *SupersetReconciler) reconcileLifecycle(
 		return blockResult, nil
 	}
 
+	// Block the pipeline when seed is configured outside Development/Staging.
+	// CEL already forbids this, but the default seed script begins with a
+	// destructive DROP DATABASE, so the controller re-checks defensively against
+	// a CR that slips past admission (older CRD, direct etcd write, apiserver
+	// without CEL), mirroring createDatabaseEnabled.
+	if blockResult, blocked := r.gateOnSeedEnvironment(superset); blocked {
+		return blockResult, nil
+	}
+
 	// Resolve the current lifecycle image.
 	var imageOverride *supersetv1alpha1.ImageOverrideSpec
 	if superset.Spec.Lifecycle != nil {
@@ -335,6 +344,33 @@ func (r *SupersetReconciler) gateOnInvalidSeedSchedule(superset *supersetv1alpha
 	return lifecycleTerminal(), true
 }
 
+// gateOnSeedEnvironment blocks the pipeline when seed is configured but the
+// environment is not Development or Staging. The CRD CEL rule already forbids
+// this, but the default seed script opens with a destructive DROP DATABASE, so
+// the controller re-checks defensively against a CR that slips past admission
+// (older CRD version, direct etcd write, apiserver without CEL). Mirrors the
+// createDatabaseEnabled precedent.
+func (r *SupersetReconciler) gateOnSeedEnvironment(superset *supersetv1alpha1.Superset) (lifecycleResult, bool) {
+	if superset.Spec.Lifecycle == nil || superset.Spec.Lifecycle.Seed == nil {
+		return lifecycleResult{}, false
+	}
+	if isDisabled(superset.Spec.Lifecycle.Seed.Disabled) {
+		return lifecycleResult{}, false
+	}
+	env := superset.Spec.Environment
+	if env != nil && (*env == naming.EnvironmentDev || *env == naming.EnvironmentStaging) {
+		return lifecycleResult{}, false
+	}
+	message := "seed is only allowed when environment is Development or Staging; refusing to run the destructive seed"
+	superset.Status.Lifecycle.Phase = lifecyclePhaseBlocked
+	superset.Status.Phase = phaseBlocked
+	setCondition(&superset.Status.Conditions, supersetv1alpha1.ConditionTypeLifecycleComplete,
+		metav1.ConditionFalse, "SeedEnvironmentNotAllowed", message, superset.Generation)
+	r.Recorder.Eventf(superset, nil, corev1.EventTypeWarning, "SeedEnvironmentNotAllowed", "Lifecycle",
+		"Lifecycle blocked: %s", message)
+	return lifecycleTerminal(), true
+}
+
 // finalizeLifecycle updates status after all lifecycle tasks complete.
 // Maintenance teardown is handled separately in reconcileMaintenanceReturn(),
 // gated on web-server readiness. The upgrade approval annotation is cleared by
diff --git a/internal/controller/lifecycle_create_db.go b/internal/controller/lifecycle_create_db.go
index dbef815..44e8053 100644
--- a/internal/controller/lifecycle_create_db.go
+++ b/internal/controller/lifecycle_create_db.go
@@ -112,7 +112,7 @@ func buildCreateDatabaseInitContainer(superset *supersetv1alpha1.Superset, lifec
 		Image:           fmt.Sprintf("%s:%s", image.Repository, image.Tag),
 		ImagePullPolicy: image.PullPolicy,
 		Command:         []string{bootstrapShell, "-c", script},
-		Env:             createDatabaseEnvVars(superset.Spec.Metastore),
+		Env:             createDatabaseEnvVars(superset.Spec.Metastore, isDevEnvironment(&superset.Spec)),
 	}
 	var containerSC *corev1.SecurityContext
 	var podSC *corev1.PodSecurityContext
@@ -206,7 +206,7 @@ func resolveCreateDatabaseImage(dbType string) supersetv1alpha1.ImageSpec {
 // the init container's psql/mysql invocation. Mirrors the structured-mode
 // branch of collectSecretEnvVars; the init container does not need URI/Valkey
 // vars, and CEL prevents URI mode + createDatabase.
-func createDatabaseEnvVars(metastore *supersetv1alpha1.MetastoreSpec) []corev1.EnvVar {
+func createDatabaseEnvVars(metastore *supersetv1alpha1.MetastoreSpec, isDev bool) []corev1.EnvVar {
 	envs := []corev1.EnvVar{
 		{Name: naming.EnvDBHost, Value: *metastore.Host},
 	}
@@ -221,7 +221,7 @@ func createDatabaseEnvVars(metastore *supersetv1alpha1.MetastoreSpec) []corev1.E
 	if metastore.Username != nil {
 		envs = append(envs, corev1.EnvVar{Name: naming.EnvDBUser, Value: *metastore.Username})
 	}
-	if metastore.Password != nil {
+	if isDev && metastore.Password != nil {
 		envs = append(envs, corev1.EnvVar{Name: naming.EnvDBPass, Value: *metastore.Password})
 	} else if metastore.PasswordFrom != nil {
 		envs = append(envs, corev1.EnvVar{
diff --git a/internal/controller/lifecycle_create_db_test.go b/internal/controller/lifecycle_create_db_test.go
index a93f6f2..f408ae9 100644
--- a/internal/controller/lifecycle_create_db_test.go
+++ b/internal/controller/lifecycle_create_db_test.go
@@ -55,6 +55,7 @@ func TestBuildCreateDatabaseInitContainer(t *testing.T) {
 		pw := "p@$$"
 		superset := &supersetv1alpha1.Superset{
 			Spec: supersetv1alpha1.SupersetSpec{
+				Environment: common.Ptr(common.EnvironmentDev),
 				Metastore: &supersetv1alpha1.MetastoreSpec{
 					Host:           common.Ptr("pg.svc"),
 					Database:       common.Ptr("superset"),
@@ -202,6 +203,7 @@ func TestBuildCreateDatabaseInitContainer(t *testing.T) {
 		weirdName := `it's"weird` + "`db`"
 		superset := &supersetv1alpha1.Superset{
 			Spec: supersetv1alpha1.SupersetSpec{
+				Environment: common.Ptr(common.EnvironmentDev),
 				Metastore: &supersetv1alpha1.MetastoreSpec{
 					Host:           common.Ptr("pg.svc"),
 					Database:       &weirdName,
diff --git a/internal/controller/lifecycle_seed.go b/internal/controller/lifecycle_seed.go
index eac1dfb..fee9a6d 100644
--- a/internal/controller/lifecycle_seed.go
+++ b/internal/controller/lifecycle_seed.go
@@ -161,6 +161,7 @@ func collectSeedEnvVars(superset *supersetv1alpha1.Superset) []corev1.EnvVar {
 	var envs []corev1.EnvVar
 	seed := superset.Spec.Lifecycle.Seed
 	spec := &superset.Spec
+	isDev := isDevEnvironment(spec)
 
 	// Source env vars.
 	envs = append(envs, corev1.EnvVar{Name: naming.EnvSeedSrcHost, Value: seed.Source.Host})
@@ -173,7 +174,7 @@ func collectSeedEnvVars(superset *supersetv1alpha1.Superset) []corev1.EnvVar {
 	envs = append(envs, corev1.EnvVar{Name: naming.EnvSeedSrcDB, Value: seed.Source.Database})
 	envs = append(envs, corev1.EnvVar{Name: naming.EnvSeedSrcUser, Value: seed.Source.Username})
 
-	if seed.Source.Password != nil {
+	if isDev && seed.Source.Password != nil {
 		envs = append(envs, corev1.EnvVar{Name: naming.EnvSeedSrcPass, Value: *seed.Source.Password})
 	} else if seed.Source.PasswordFrom != nil {
 		envs = append(envs, corev1.EnvVar{
@@ -196,7 +197,7 @@ func collectSeedEnvVars(superset *supersetv1alpha1.Superset) []corev1.EnvVar {
 		if spec.Metastore.Username != nil {
 			envs = append(envs, corev1.EnvVar{Name: naming.EnvDBUser, Value: *spec.Metastore.Username})
 		}
-		if spec.Metastore.Password != nil {
+		if isDev && spec.Metastore.Password != nil {
 			envs = append(envs, corev1.EnvVar{Name: naming.EnvDBPass, Value: *spec.Metastore.Password})
 		} else if spec.Metastore.PasswordFrom != nil {
 			envs = append(envs, corev1.EnvVar{
diff --git a/internal/controller/seed_test.go b/internal/controller/seed_test.go
index 1c619ac..35d85bc 100644
--- a/internal/controller/seed_test.go
+++ b/internal/controller/seed_test.go
@@ -487,6 +487,7 @@ func TestCollectSeedEnvVars(t *testing.T) {
 	port := int32(5432)
 
 	superset := &supersetv1alpha1.Superset{}
+	superset.Spec.Environment = common.Ptr(common.EnvironmentDev)
 	superset.Spec.Lifecycle = &supersetv1alpha1.LifecycleSpec{
 		Seed: &supersetv1alpha1.SeedTaskSpec{
 			Source: supersetv1alpha1.SeedSourceSpec{
@@ -1773,3 +1774,85 @@ func TestIsTaskEnabled_InvalidCronScheduleGatesSeed(t *testing.T) {
 		t.Fatal("expected seed to be enabled when no CronSchedule is set")
 	}
 }
+
+// TestCollectSeedEnvVars_ProductionDropsInlinePasswords verifies the inline
+// seed source and target password literals are dropped outside Development
+// (defense in depth behind CEL), falling back to the *From reference.
+func TestCollectSeedEnvVars_ProductionDropsInlinePasswords(t *testing.T) {
+	superset := &supersetv1alpha1.Superset{}
+	superset.Spec.Environment = common.Ptr(common.EnvironmentProd)
+	superset.Spec.Lifecycle = &supersetv1alpha1.LifecycleSpec{
+		Seed: &supersetv1alpha1.SeedTaskSpec{
+			Source: supersetv1alpha1.SeedSourceSpec{
+				Host: "pg-prod.svc", Database: "d", Username: "u",
+				Password: common.Ptr("inline-src"),
+			},
+		},
+	}
+	superset.Spec.Metastore = &supersetv1alpha1.MetastoreSpec{
+		Host: common.Ptr("pg-staging.svc"), Database: common.Ptr("d"), Username: common.Ptr("u"),
+		Password: common.Ptr("inline-target"),
+	}
+
+	for _, e := range collectSeedEnvVars(superset) {
+		if e.Name == common.EnvSeedSrcPass && e.Value != "" {
+			t.Errorf("inline seed source password must be dropped outside Development, got %q", e.Value)
+		}
+		if e.Name == common.EnvDBPass && e.Value != "" {
+			t.Errorf("inline seed target password must be dropped outside Development, got %q", e.Value)
+		}
+	}
+}
+
+func TestGateOnSeedEnvironment(t *testing.T) {
+	newSuperset := func(env string, seedDisabled *bool) *supersetv1alpha1.Superset {
+		s := &supersetv1alpha1.Superset{
+			ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "default"},
+			Spec: supersetv1alpha1.SupersetSpec{
+				Lifecycle: &supersetv1alpha1.LifecycleSpec{
+					Seed: &supersetv1alpha1.SeedTaskSpec{
+						Disabled: seedDisabled,
+						Source:   supersetv1alpha1.SeedSourceSpec{Host: "src"},
+					},
+				},
+			},
+		}
+		if env != "" {
+			s.Spec.Environment = common.Ptr(env)
+		}
+		s.Status.Lifecycle = &supersetv1alpha1.LifecycleStatus{}
+		return s
+	}
+	r := &SupersetReconciler{Recorder: events.NewFakeRecorder(10)}
+
+	t.Run("blocks in production", func(t *testing.T) {
+		s := newSuperset(common.EnvironmentProd, nil)
+		res, blocked := r.gateOnSeedEnvironment(s)
+		if !blocked || !res.TerminalFailure {
+			t.Fatalf("expected block+terminal in Production, got blocked=%v res=%#v", blocked, res)
+		}
+		if !hasLifecycleConditionReason(s, "SeedEnvironmentNotAllowed") {
+			t.Fatal("expected SeedEnvironmentNotAllowed condition")
+		}
+	})
+	t.Run("blocks when environment unset (defaults to Production)", func(t *testing.T) {
+		if _, blocked := r.gateOnSeedEnvironment(newSuperset("", nil)); !blocked {
+			t.Fatal("expected block when environment unset")
+		}
+	})
+	t.Run("allows in staging", func(t *testing.T) {
+		if _, blocked := r.gateOnSeedEnvironment(newSuperset(common.EnvironmentStaging, nil)); blocked {
+			t.Fatal("expected no block in Staging")
+		}
+	})
+	t.Run("allows in development", func(t *testing.T) {
+		if _, blocked := r.gateOnSeedEnvironment(newSuperset(common.EnvironmentDev, nil)); blocked {
+			t.Fatal("expected no block in Development")
+		}
+	})
+	t.Run("no-op when seed disabled", func(t *testing.T) {
+		if _, blocked := r.gateOnSeedEnvironment(newSuperset(common.EnvironmentProd, common.Ptr(true))); blocked {
+			t.Fatal("expected no block when seed disabled")
+		}
+	})
+}