fix(standalone): resolve env var references in config pushed via Admin API#13540
Open
AlinsRan wants to merge 1 commit into
Open
fix(standalone): resolve env var references in config pushed via Admin API#13540AlinsRan wants to merge 1 commit into
AlinsRan wants to merge 1 commit into
Conversation
3fa7450 to
dd45c6a
Compare
…n API
In standalone mode, the file-based config path resolves ${{VAR}} / $ENV://
references in config_yaml.parse(), but config pushed through the Admin API
(`PUT /apisix/admin/configs`) is JSON-decoded straight into _update_config
and bypassed that step, so the references were kept literal.
Resolve them in the Admin API update path before applying the config, so
both standalone config sources behave consistently. Adds a test that pushes
a route whose proxy-rewrite uri uses a ${{VAR:=default}} reference and
verifies the gateway resolves it.
Signed-off-by: AlinsRan <alinsran@apache.org>
dd45c6a to
83204eb
Compare
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.
TL;DR
In standalone mode,
${{VAR}}references in config pushed via the Admin API are stored literally (never resolved), so a reference in a pattern-constrained field (e.g.proxy-rewrite.uri) is even rejected with 400.Cause
Standalone has two config sources; only the file path resolves
${{VAR}}:apisix.yaml): resolved incore/config_yaml.luaparse(), before schema validation.admin/standalone.luaupdate()): validates and stores the JSON body without ever callingresolve_conf_var.The divergence was introduced by #13078, which moved resolution into the file-parse path only.
Fix
update()now callsfile.resolve_conf_var(req_body)beforevalidate_configuration, mirroring the file path. Both the schema check and the stored config see resolved, natively-typed values —resolve_conf_varcoerces resolved scalars to their native type (e.g."2"→2), and an unresolvable reference (no env var, no:=default) now fails fast with 400 instead of being stored literally.Scope: this resolves the
${{VAR}}syntax only.$ENV:///$secret://references are a separate, lazily-resolved mechanism and are unaffected.Test
t/admin/standalone.spec.ts,Variable resolution:${{VAR:=default}}inproxy-rewrite.uriresolves and the route returns the hello body (a literal value would not match);${{VAR:=2}}into the integerupstream.retriesreturns 202 (native-type coercion; a literal"2"would fail integer validation);${{VAR}}returns 400 withfailed to resolve variables in config.Checklist