edge-router.example.toml can't be run directly: ${...} expansion runs over comments #15
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Background
Found during the Network Access Control feature work. Pre-existing, not introduced by that feature.
Problem
ROUTES_CONFIG=edge-router.example.toml cargo runfails at startup withEnvironment variable 'ER_VAR_NAME' is not set.Root cause:
expand_env_refsinsrc/routes_config.rsdoes raw-text${...}substitution over the entire file content, including comments, beforetoml::from_strever parses it. The example file's TLS-section documentation comments contain literal${VAR_NAME}/${CF_TOKEN}tokens (as illustrative syntax), so expansion tries to resolve them as real env vars and aborts.Consequence: the shipped example file can't be run verbatim, only after a user copies and customizes it — which is the intended workflow, but the failure mode is a confusing hard error rather than anything pointing at "this is a template".
Proposed fix
Make
${...}expansion comment-aware (skip#-comment regions), or perform expansion after TOML parse on string values only rather than raw file text. Either keeps the documented${...}syntax in comments intact while still expanding real values.Severity
Minor — the example is a template meant to be copied first; no runtime/security impact on a real deployment. Filed so the example is runnable-as-shipped for anyone who tries it directly. (A one-paragraph networking note was already added to the example in commit
b728117; this expansion issue is separate.)Fixed on
mainby346bcdf, using the second option proposed above — expansion now runs after the TOML parse, walking string values of the parsed document, so comments and keys are untouched by construction.The comment-aware alternative was rejected for the reason that
#is legal inside a value:dir = "/srv/a#b"would be mangled by any comment-stripping pass short of tokenising TOML, at which point you may as well parse it. There's a regression test for that case alongside the comment one, andshipped_example_config_parsesnow loads the realedge-router.example.tomlso it can't drift back into being unloadable.The example has its
${CF_TOKEN}documentation back as a result.Housekeeping: I filed #31 for this in September without checking the existing issues, so that was a duplicate of this one. #31 carries the fix detail and is closed; closing this as the original.