Resolve bao:/kv: secret refs embedded in header/env values - #13
Merged
Conversation
Header and env injection values only resolved a secret ref when the
*entire* value was the ref. A value like "Authorization: Bearer
bao:upstreams/x#token" — exactly what the admin UI placeholder suggests —
was sent to the upstream verbatim, so the upstream received the literal
"bao:..." string instead of the secret.
resolveInjectionValue now resolves refs (and ${VAR}) embedded anywhere in
the value, in a single left-to-right pass so resolved secret contents are
never re-scanned. Whole-value refs keep the previous behaviour: the secret
is returned verbatim and a malformed whole-value ref still errors.
Ref tokens use a conservative path/field charset (A-Za-z0-9_./-) so a ref
ends cleanly at surrounding punctuation.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Upstream header/env injection resolved a secret ref only when the entire value was the ref (
isSecretRefchecksvalue.startsWith("bao:")). A value like:— exactly what the admin UI placeholder suggests (
Authorization: Bearer bao:upstreams/itglue#token) — starts withBearer, so it was sent to the upstream verbatim. The upstream received the literal stringbao:upstreams/publora#tokenas the credential instead of the resolved secret.This surfaced when adding an HTTP upstream (Publora) via the manual "Add server" form: the server rejected the key as malformed because it got the ref text, not the token. Presets work only because their
Bearer {{token}}markers are expanded at install time.Fix
resolveInjectionValuenow resolves refs (and${VAR}) embedded anywhere in the value, in a single left-to-right pass so resolved secret contents are never re-scanned (a secret that happens to contain${...}orbao:...is not re-processed).bao:missing-hash) still throws.A-Za-z0-9_./-) so a ref ends cleanly at surrounding punctuation (…#token; more).${VAR}substitution and the no-store / scheme-mismatch errors are unchanged.Now
Authorization: Bearer bao:upstreams/publora#tokenresolves toAuthorization: Bearer <secret>, matching the UI placeholder's promise — and the token stays in OpenBao (noBearerprefix baked into the stored secret).Tests
Added cases for: embedded ref, multiple embedded tokens (ref +
${VAR}), embedded ref with no store configured, and whole-value secret returned verbatim without re-scanning. Full suite: 201 passed,tscbuild clean.🤖 Generated with Claude Code