Skip to content

fix(secret): log an error when a secret reference cannot be resolved#13737

Open
shreemaan-abhishek wants to merge 1 commit into
apache:masterfrom
shreemaan-abhishek:fix/secret-ref-silent-failure
Open

fix(secret): log an error when a secret reference cannot be resolved#13737
shreemaan-abhishek wants to merge 1 commit into
apache:masterfrom
shreemaan-abhishek:fix/secret-ref-silent-failure

Conversation

@shreemaan-abhishek

Copy link
Copy Markdown
Contributor

Description

An unresolvable $secret:// or $env:// reference silently falls back to the literal reference string:

refs[k] = fetch(v, use_cache) or v

The literal is then used verbatim as whatever the field is: a password, an API key, an AWS access key ID. Nothing tells the operator that resolution failed. On the cached path (use_cache = true, which is what plugin conf resolution in plugin.filter() uses) the error returned by the secret manager was swallowed entirely, so a missing /apisix/secrets/<manager>/<id> resource or an unset environment variable produced no log line at all.

The failure mode this surfaces in practice: the raw reference goes upstream as a credential, and the operator only sees the provider's rejection. A user hit exactly this with ai-proxy + Bedrock, where the unresolved reference ended up inside the SigV4 credential scope:

{"message":"Credential must have exactly 5 slash-delimited elements, e.g. keyid/date/region/service/term, got '$secret://aws/xxxx/secret-name/access-key-id/20260723/us-east-1/bedrock/aws4_request'"}

with no corresponding error in APISIX's log.

This PR keeps the existing fallback behaviour (documented, and changing it would break existing deployments) but makes the failure visible:

failed to resolve secret reference: $secret://vault/1/foo/bar, field: password, err: no secret conf, secret_uri: ...

It covers both failure shapes: a manager error (no secret conf, backend failure) and a reference that simply resolves to nothing (unset environment variable), which previously returned nil without an error on either path.

The now-duplicated log in the uncached branch is dropped, since the caller logs with more context (the field name).

Which issue(s) this PR fixes

N/A

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Jul 23, 2026
An unresolvable $secret:// or $env:// reference silently falls back to
the literal reference string, which is then used verbatim as a password,
key or token. On the cached path (used by plugin conf resolution) the
underlying error was swallowed entirely, so a missing secret manager or
an unset environment variable produced no diagnostic at all.

Report the failure with the field name and the underlying error, and
drop the now-duplicated log in the uncached branch.
@shreemaan-abhishek
shreemaan-abhishek force-pushed the fix/secret-ref-silent-failure branch from 50dd841 to 14fc0f1 Compare July 24, 2026 04:48
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant