fix(config): make every sequence field reachable from the environment - #912
Conversation
`proxy.real_ip.trusted_proxies` and `observability.metrics.client_type_rules`
could not be set through `AISIX_*` env vars at all. Neither falls back to its
default when the env var is present — the whole config load fails:
AISIX_PROXY__REAL_IP__TRUSTED_PROXIES=10.0.0.0/8
-> deserialize: invalid type: string "10.0.0.0/8", expected a sequence
The chart and the Dashboard's `docker run` snippet configure the gateway purely
through env vars, so both fields were unreachable in the deployments we ship.
That is most visible on `trusted_proxies`: without it the gateway logs the
immediate TCP peer, so behind an ingress every request — including the caller
address now carried on authentication denials — reads as the load balancer.
Two mechanisms cover the two shapes, and every sequence field needs one of them:
- `Vec<String>` / `Vec<f64>`: a `with_list_parse_key` registration, which
comma-splits the value. Added for `proxy.real_ip.trusted_proxies`.
- `Vec<Struct>`: comma-splitting cannot express it, so the field takes one JSON
array through `deserialize_seq_or_json_string` — until now a `url_rewrites`
private helper, generalized here and applied to `client_type_rules` too.
The existing YAML-scalar tests did not catch this: they exercise the
deserializer, not the `Environment` source's list-parse registration.
`env_only_deployments_can_set_every_sequence_field` loads with no config file at
all and asserts all five sequence fields arrive, which is the shape that was
untested. It fails on both fields before this change.
`config.example.yaml` now shows the env spelling for both.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 59 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
Comment |
There was a problem hiding this comment.
Pull request overview
Makes sequence-valued configuration fields usable through AISIX_* environment variables.
Changes:
- Adds comma parsing for trusted proxy CIDRs.
- Adds JSON-array parsing for structured client-type rules.
- Adds env-only configuration coverage and examples.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
crates/aisix-core/src/config.rs |
Implements sequence parsing and tests env-only loading. |
config.example.yaml |
Documents environment variable formats. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| .list_separator(",") | ||
| .with_list_parse_key("etcd.endpoints") | ||
| .with_list_parse_key("admin.admin_keys") | ||
| .with_list_parse_key("proxy.real_ip.trusted_proxies") |
proxy.real_ip.trusted_proxiesandobservability.metrics.client_type_rulescould not be set throughAISIX_*env vars at all. Neither falls back to its default when the env var is present — the whole config load fails:The chart and the Dashboard's
docker runsnippet configure the gateway purely through env vars, so both fields were unreachable in the deployments we ship. That is most visible ontrusted_proxies: without it the gateway logs the immediate TCP peer, so behind an ingress every request — including the caller address now carried on authentication denials — reads as the load balancer.Implementation
Two mechanisms cover the two shapes, and every sequence field needs one of them:
Vec<String>/Vec<f64>— awith_list_parse_keyregistration, which comma-splits the value. Added forproxy.real_ip.trusted_proxies.Vec<Struct>— comma-splitting cannot express it, so the field takes one JSON array throughdeserialize_seq_or_json_string. That was aurl_rewritesprivate helper; it is generalized here and applied toclient_type_rulestoo.Auditing the whole class, those two were the only sequence fields left uncovered.
Tests
The existing YAML-scalar tests do not reach this: they exercise the deserializer, not the
Environmentsource's list-parse registration, which is the layer that was missing.env_only_deployments_can_set_every_sequence_fieldloads with no config file at all and asserts all five sequence fields arrive, re-executing the test binary as a child process so env mutation stays isolated (the pattern the managed-bootstrap test already uses). It fails on both fields before this change.config.example.yamlnow shows the env spelling for both.🤖 Generated with Claude Code