Skip to content

rate_limit: reject unknown YAML configuration keys - #13657

Draft
moonchen wants to merge 3 commits into
apache:masterfrom
moonchen:rate-limit-reject-unknown-yaml-keys
Draft

rate_limit: reject unknown YAML configuration keys#13657
moonchen wants to merge 3 commits into
apache:masterfrom
moonchen:rate-limit-reject-unknown-yaml-keys

Conversation

@moonchen

@moonchen moonchen commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

The rate_limit YAML parser silently ignored unknown keys, so a typo such as max-age left aging disabled. Validate each configuration mapping against its accepted keys and reject unknown keys with a diagnostic naming the key, node, and line. Propagate queue and metrics parsing failures so they prevent configuration loading.

Adds 13 AuTest scenarios covering valid settings, unknown keys at every mapping level, and malformed nodes, and documents the configuration compatibility change.

Fixes: #13529

Validation:

  • Built the rate_limit plugin.
  • Passed rate_limit_yaml_keys, rate_limit_iprep, and rate_limit_sni_expiry AuTests.
  • Passed pre-commit formatting checks and git diff --check.

Reject misspelled or stale settings instead of silently using defaults,
and propagate queue and metrics validation failures to the config loader.
Add startup coverage for each mapping and document strict key validation.

Fixes: apache#13529

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

This PR tightens rate_limit YAML configuration parsing by rejecting unknown keys (preventing silent typos) and by failing configuration loads on queue/metrics parsing errors, with diagnostics that identify the offending key/node and line.

Changes:

  • Add a shared YAML-mapping key validator (validate_yaml_keys) and apply it across configuration levels (root, selector, lists, queue/metrics, ip-rep, perma-block).
  • Propagate YAML parsing failures to stop configuration loading instead of continuing with partial defaults.
  • Add AuTests for unknown keys/malformed nodes and document the compatibility change.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/gold_tests/pluginTest/rate_limit/rate_limit_yaml_keys.test.py Adds AuTest scenarios validating unknown-key rejection and malformed-node handling.
plugins/experimental/rate_limit/utilities.h Declares validate_yaml_keys and adds required includes.
plugins/experimental/rate_limit/utilities.cc Implements validate_yaml_keys with diagnostics for malformed mappings/unknown keys.
plugins/experimental/rate_limit/sni_selector.cc Validates top-level YAML keys and selector mapping keys during parse.
plugins/experimental/rate_limit/sni_limiter.cc Propagates base YAML parsing failure instead of ignoring it.
plugins/experimental/rate_limit/lists.cc Rejects unknown YAML keys in lists mappings.
plugins/experimental/rate_limit/limiter.h Rejects unknown YAML keys in queue and metrics mappings.
plugins/experimental/rate_limit/ip_reputation.cc Rejects unknown YAML keys in ip-rep and perma-block mappings.
doc/admin-guide/plugins/rate_limit.en.rst Documents unknown-key failure behavior and max_age compatibility guidance.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread doc/admin-guide/plugins/rate_limit.en.rst Outdated
Comment thread plugins/experimental/rate_limit/sni_selector.cc Outdated
Comment thread tests/gold_tests/pluginTest/rate_limit/rate_limit_yaml_keys.test.py Outdated
Comment thread plugins/experimental/rate_limit/utilities.h Outdated
Comment thread tests/gold_tests/pluginTest/rate_limit/rate_limit_yaml_keys.test.py Outdated
1. A malformed value such as "limit: abc" makes yaml-cpp throw out of
   as<T>().  Nothing caught it, so traffic_server aborted with no
   diagnostic instead of reporting the bad configuration, and a reload
   took down a running server.  Catch YAML::Exception around the parse.

2. The "rate" setting assigned to _limit instead of _rate.  Requests per
   second were never enforced, because _rate stayed 0 and addBucket()
   never ran, and setting "rate" silently overrode "limit".

3. Reject an empty configuration file, and name "selector: []" as the
   way to load the plugin with no rules.

4. The AuTest startup check looked for "Traffic Server is fully
   initialized" in traffic.out.  That message is a Note, and
   proxy.config.diags.output.note defaults to the log file, so the check
   could never fail.  Look in diags.log instead.
On a const YAML node, operator[] returns a zombie node for a missing key,
and IsScalar() throws on it.  A selector entry without an "sni" key
therefore threw instead of reporting the missing name.  Test the node for
definedness first, which is safe, and add a case for it.

Also from review:

* Name the line number when a top level node is not a sequence.
* Correct the spelling of "Successfully" in the load message.
* Declare YAML::Node in utilities.h instead of including yaml-cpp there.
* Record the strict validation in the v11 upgrading notes.
@moonchen moonchen self-assigned this Sep 9, 2026
@moonchen moonchen added this to the 11.0.0 milestone Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rate_limit: reject unknown keys in the YAML configuration

2 participants