ClusterExternalSecret with a name longer than 59 characters stops provisioning ExternalSecrets entirely

Author: tspearconquestCreated Sep 22, 2026Updated Sep 22, 2026
Labelskind/bug

Describe the bug

A ClusterExternalSecret whose .metadata.name is longer than 59 characters is accepted at admission but never functions: it provisions no ExternalSecrets in any targeted namespace, and never recovers.

The per-namespace finalizer introduced in #5154 is built by plain string concatenation with no length validation, truncation or hashing:

go
// pkg/controllers/clusterexternalsecret/clusterexternalsecret_controller.go
func (r *Reconciler) buildCESFinalizer(cesName string) string {
	return "externalsecrets.external-secrets.io/ces-" + cesName
}

metadata.finalizers entries are validated as qualified names, and the part after the / is limited to 63 bytes. That part is ces- + the CES name, so any CES name over 59 characters produces an invalid finalizer and every namespace update is rejected with:

could not add namespace finalizer: Namespace "<namespace>" is invalid: metadata.finalizers:
Invalid value: "externalsecrets.external-secrets.io/ces-<ces-name>":
name part must be no more than 63 bytes

Crucially this is not limited to losing the finalizer. In createOrUpdateExternalSecret the finalizer is added first and its error returns before the ExternalSecret is created or updated, so the CES becomes completely inert: it cannot create ExternalSecrets in newly matching namespaces, and cannot propagate spec.externalSecretSpec changes to existing ones.

metadata.name allows up to 253 characters and the CRD imposes no stricter limit, so such a CES is accepted at admission without complaint and only fails later, at runtime.

To Reproduce

Kubernetes v1.35.8. Reproduced on ESO v2.11.0; by inspection this affects every release from v0.20.0 onward (see Additional context).

  1. Install ESO with the ClusterExternalSecret controller enabled (processClusterExternalSecret: true).

  2. Apply a ClusterExternalSecret whose name is 61 characters — the name below yields a 65-byte finalizer name part:

    yaml
    apiVersion: external-secrets.io/v1
    kind: ClusterExternalSecret
    metadata:
      # 61 characters -> "ces-" + name = 65 bytes -> exceeds the 63-byte limit
      name: registry-pull-credentials-for-shared-artifact-proxy-cache-tok
    spec:
      refreshTime: 1h
      namespaceSelectors:
        - matchLabels:
            needs-registry-credentials: "true"
      externalSecretName: registry-pull-credentials
      externalSecretSpec:
        refreshInterval: 1h
          # This store does not need to exist — see note after step 5.
          name: any-store
          kind: ClusterSecretStore
        target:
          name: registry-pull-credentials
        data:
          - secretKey: token
            remoteRef:
              key: some-remote-key
  3. Label at least one namespace so it is selected:

    bash
    kubectl label namespace my-app needs-registry-credentials=true
  4. Observe that no ExternalSecret is created in that namespace:

    bash
    kubectl get externalsecrets -n my-app
    # No resources found
    
    kubectl get clusterexternalsecret registry-pull-credentials-for-shared-artifact-proxy-cache-tok \
      -o jsonpath='{.status}' | jq

    status.provisionedNamespaces is empty and status.failedNamespaces holds one entry per targeted namespace, each carrying the name part must be no more than 63 bytes error. The controller logs the same error as failed to create or update external secret.

  5. Re-apply the identical manifest with a name of 59 characters or fewer, for example registry-pull-credentials-for-shared-artifact-proxy-cache-x. The ExternalSecret is created immediately and the CES becomes Ready=True.

Note that no working SecretStore or ClusterSecretStore is required to reproduce this. The failure occurs in createOrUpdateExternalSecret before the ExternalSecret is created, so the store is never consulted. The control case in step 5 also does not need one: CES readiness is derived solely from whether each namespace was provisioned (NewClusterExternalSecretCondition(failedNamespaces) in pkg/controllers/clusterexternalsecret/util.go), not from whether the resulting ExternalSecret successfully synced. The ExternalSecret created in step 5 will itself report a store error, which is expected and irrelevant to this bug.

Expected behavior

A ClusterExternalSecret with a name that Kubernetes accepts should either work, or be rejected with a clear, immediate error. Concretely, either:

  • the name length is validated at admission, so the object is refused up front with a message explaining the 59-character limit; or
  • the finalizer is derived in a length-safe way (for example truncate and append a short hash of the full name) so that any valid object name works.

In no case should provisioning of ExternalSecrets be silently disabled as a side effect of the finalizer being unrepresentable.

Screenshots

N/A — relevant log output and status are included above.

Additional context

Affected versions. Introduced in v0.20.0 (#5154 merged 2025-09-05, first released 2025-09-22) and unchanged since — buildCESFinalizer is byte-for-byte identical in every release from v0.20.0 through v2.11.0 and on main today. Confirmed by fetching pkg/controllers/clusterexternalsecret/clusterexternalsecret_controller.go at all 28 release tags in the range v0.19.2 … v2.11.0 inclusive: the method is absent at v0.19.2, present at all 27 subsequent tags, and the extracted method body hashes to a single distinct value across all of them. Line references below are against main @ d735072ef89d4c2e896c9dc78313f127ac0c10aa.

Execution trace.

  1. reconcile (L136) resolves target namespaces and calls gatherProvisionedNamespaces (L196).

  2. For each namespace it calls createOrUpdateExternalSecret (L374).

  3. That function adds the finalizer first and returns on error, before CreateOrUpdate (L381-383):

    go
    // Add namespace finalizer first to prevent deletion race conditions
    if err := r.ensureNamespaceFinalizer(ctx, &namespace, clusterExternalSecret.Name); err != nil {
        return err
    }
  4. ensureNamespaceFinalizer (L424) → addNamespaceFinalizer (L435) issues the namespace Update, which the API server rejects; the error is wrapped at L449.

  5. gatherProvisionedNamespaces logs it as failed to create or update external secret (L238), records the namespace in failedNamespaces and continues, so it is never appended to provisionedNamespaces.

The error is deterministic, so the hourly requeue (RequeueInterval: time.Hour, set in cmd/controller/root.go) retries and fails identically indefinitely.

Why this is easy to miss. The failure is reported only in the CES's own status and in controller logs. Specifically:

  • Not rejected at admission — metadata.name is valid as far as Kubernetes and the CRD are concerned.
  • No Kubernetes Events are emitted. The clusterexternalsecret.Reconciler struct has no event recorder (Client, Log, Scheme, RequeueInterval only) and the package contains no Event() calls — unlike, for example, clusterpushsecret.Reconciler, which is constructed with Recorder: mgr.GetEventRecorderFor(...) in cmd/controller/root.go.
  • Reported via status.conditions (Ready=False, "one or more namespaces failed"), one status.failedNamespaces entry per targeted namespace, and an error-level log line per namespace per reconcile.

What is absent is any workload-visible symptom. ExternalSecrets created before the CES name became over-length are not deleted — deleteOutdatedExternalSecrets (L488) only prunes namespaces that were previously provisioned and are no longer targeted, via getRemovedNamespaces (L507). Those ExternalSecrets continue to be reconciled by the separate ExternalSecret controller, which keeps refreshing their target Secrets from the provider. Applications therefore keep running normally while the CES does nothing, so unless the CES's status is being monitored directly, there is no signal that anything is wrong.

Adding an event recorder to this controller would, on its own, make this class of failure much easier to notice.

This is how it surfaced for us: an upgrade from 0.19.2 (before #5154) straight to 2.11.0 after verifying that all breaking changes in between would not affect us, turned a previously working CES inert, with no visible impact until status.failedNamespaces was inspected. Shortening .metadata.name to 59 characters resolved it completely.

Possible fix. Admission-time validation seems cleanest, since the constraint is statically knowable. This type already uses kubebuilder length validation elsewhere — spec.namespaces items carry +kubebuilder:validation:items:MaxLength:=63 in apis/externalsecrets/v1/clusterexternalsecret_types.go. A CEL rule would express it directly:

go
// +kubebuilder:validation:XValidation:rule="self.metadata.name.size() <= 59",message="ClusterExternalSecret name must be 59 characters or fewer, because it is used to build a namespace finalizer limited to 63 bytes"

If tightening validation on an existing type is considered breaking for users who already have long-named CES objects, making buildCESFinalizer length-safe would be the alternative — though that needs care for upgrade compatibility, since the same string is recomputed on the removal path (removeNamespaceFinalizer, L330) and must still match finalizers written by earlier versions.

Failing fast with an explicit condition on the CES itself, rather than a per-namespace failedNamespaces entry that reads like a transient namespace problem, would also make this considerably easier to diagnose.

Related.

  • #5154 — introduced the namespace finalizer.
  • #6677 — CES namespace finalizer orphaned when a namespace is relabelled out of namespaceSelectors; same feature, different failure.
  • #4052 — analogous length bug for ExternalSecret names (>92 characters), previously fixed.

An honest caveat. The repro is reconstructed, not executed — Claude observed this failure in our cluster on v2.11.0/k8s v1.35.8 and verified the mechanism by reading the source, but I have not run these exact synthetic steps end-to-end. The wording reflects that.

Source: external-secrets/external-secrets