Vault: buildMetadataPath does not strip the mount prefix that buildPath strips, deadlocking PushSecret on pre-existing secrets
Describe the bug
In the Vault provider, buildPath and buildMetadataPath disagree about the mount prefix. buildPath strips a leading <store.path>/ from the remoteKey; buildMetadataPath does not. When a remoteKey includes the mount name, the data and metadata paths diverge:
spec.provider.vault: { path: "mymount", version: v2 }
remoteKey: "mymount/team/app"
buildPath -> mymount/data/team/app # prefix stripped
buildMetadataPath -> mymount/metadata/mymount/team/app # prefix NOT stripped <-- doubledPushSecret writes custom_metadata to the doubled path and later reads it back from the same doubled path, so the inconsistency is normally self-cancelling and goes unnoticed — a metadata-only entry quietly accumulates at the wrong location (current_version: 0, versions: {}).
It becomes an unrecoverable deadlock when the secret already exists
PushSecret only consults the metadata when the data path already exists:
vaultSecret, err := c.readSecret(ctx, path, "")
if err != nil && !errors.Is(err, esv1beta1.NoSecretError{}) {
return err // a MISSING remote secret is tolerated -> "create it"
}
if err == nil { // secret exists -> verify it is ESO-managed
metadata, err := c.readSecretMetadata(ctx, data.GetRemoteKey())
if err != nil {
return err // NoSecretError escapes here, untolerated
}
...
}So if the remote secret was created by anything other than ESO (seeded by an operator, migrated, restored from backup), the doubled metadata path does not exist, readSecretMetadata returns errNotFound, and PushSecret returns before reaching the write that would have created the stamp. It can never recover, and the surfaced error is misleading:
could not write remote ref to target secretstore <store>: secret not foundThat reads as "the remote secret is missing" when the remote secret is present and readable — an ExternalSecret on the same remoteKey syncs fine throughout, because reads go through buildPath. The empty gap in the message is just remoteRef.Property being unset.
To Reproduce
ClusterSecretStorefor Vault/OpenBao KV v2 withprovider.vault.path: mymount.- Create a secret outside ESO:
vault kv put mymount/team/app foo=bar. PushSecretwithupdatePolicy: ReplaceandremoteKey: mymount/team/app.- Push fails permanently with
secret not found, despite the path existing and being readable.
Deleting the remote secret and letting ESO create it makes it work — because readSecret then returns NoSecretError, the metadata check is skipped, and the stamp is written (to the doubled path).
Expected behavior
buildMetadataPath should apply the same prefix handling as buildPath, so data and metadata resolve to the same logical secret.
Note on fixing it — existing installs will break
Anything working today has its custom_metadata at the doubled path. A naive fix moves the read to the correct path, finds no custom_metadata there, and fails with secret not managed by external-secrets — turning healthy installs broken. Worth pairing the fix with a fallback read of the legacy path (and ideally a one-time rewrite to the correct one), or a clear migration note.
Version
- ESO v0.11.0
buildMetadataPathon currentmainis unchanged, so this still applies: https://github.com/external-secrets/external-secrets/blob/main/providers/v1/vault/client_get.go
Additional context
Found on a cluster where the remote entry had been seeded by hand before ESO was pointed at it. Every other PushSecret on the same store was healthy, because ESO had created those itself — which is what makes this hard to diagnose: the failing and working cases differ only in provenance, not in configuration.
Source: external-secrets/external-secrets