Summary
External Secrets Operator introduced a getSecretKey template function that could read Kubernetes Secrets across namespaces using the controller's roleBinding.
If an attacker can define or modify ExternalSecret resources, they may bypass namespace isolation controls and retrieve secrets from other namespaces, leading to data exposure and privilege escalation.
Affected context
This vulnerability affects Kubernetes clusters running External Secrets Operator versions starting from 0.20.2 and prior to 1.2.0 where:
- The senhasegura Devops Secrets Management (DSM) provider is enabled or templating capabilities are available.
- The controller has a roleBinding that allows it to read Secrets across multiple namespaces.
- Users or automation are allowed to create or modify ExternalSecret resources with templating.
Under these conditions, the getSecretKey function can be abused to access Secrets outside the intended namespace scope, bypassing ESO's normal security safeguards.
Exploit preconditions
- Attack surface: Kubernetes API server via ExternalSecret custom resources.
- Required access: Ability to create, modify, or control ExternalSecret objects in any namespace where External Secrets Operator is active.
- Trigger point: Rendering of templates that invoke the
getSecretKeyfunction by the ESO controller. - Why exploitation is possible: The
getSecretKeyfunction executes in the security context and RBAC scope of the external-secrets controller, not the namespace-scoped identity of the ExternalSecret resource. This breaks intended namespace isolation and fails to enforce authorization checks aligned with ESO's security model.
Why this happens
The root cause lies in an authorization design flaw where a helper function (getSecretKey) is allowed to perform secret retrieval using the elevated privileges of the External Secrets Operator controller.
Instead of enforcing namespace and policy constraints associated with the requesting ExternalSecret resource, the function uses the controller's roleBinding permissions, enabling cross-namespace secret fetches.
This maps to CWE-863: Incorrect Authorization, where the system authorizes access based on an overly privileged principal (the controller) rather than enforcing least privilege and resource-scoped policies for each request.
Potential impact
- Unauthorized reading of Kubernetes Secrets from other namespaces.
- Leakage of credentials, API keys, tokens, and certificates intended for isolated workloads.
- Lateral movement by using stolen credentials to access additional services or clusters.
- Escalation of privileges if Secrets include higher-privileged service account tokens or administrative credentials.
- Breach of multi-tenant isolation guarantees within a shared cluster environment.
General mitigation guidance
Effective mitigation focuses on tightening authorization boundaries and removing dangerous helper abstractions:
- Avoid using template functions that perform privileged operations on behalf of user-defined resources, especially when they can cross namespace boundaries.
- Enforce strict namespace isolation for any component that accesses Secrets; the controller should only read Secrets in namespaces explicitly required by design.
- Apply least-privilege RBAC for the External Secrets Operator, limiting its roleBinding to only the namespaces and Secret types it must manage.
- Use admission control or policy engines (e.g., Kyverno, Kubewarden, OPA/Gatekeeper) to deny ExternalSecret specs that reference disallowed template functions or patterns capable of bypassing safeguards.
- Prefer explicit, declarative mappings from external secret stores to Kubernetes Secrets instead of flexible templating that can trigger privileged operations.
How teams detect issues like this
Detection typically relies on a combination of configuration review and runtime policy enforcement:
- Scan ExternalSecret manifests (in Git repos or via the Kubernetes API) for usage of the
getSecretKeyfunction and similar high-privilege template helpers. - Use admission controllers or policy engines to log (and optionally block) ExternalSecret resources that contain suspicious templating constructs or cross-namespace references.
- Review RBAC bindings for the External Secrets Operator to identify controllers with cluster-wide or broad namespace-wide Secret read permissions.
- Employ configuration and policy-as-code scanning in CI/CD to flag ESO configurations that break namespace isolation or grant excessive privileges to the controller.

