Repository navigation
perf(policy): bound wildcard matching on adversarial inputs - #9486
Conversation
|
CLA requirements are satisfied for this pull request. |
overtrue
left a comment
There was a problem hiding this comment.
No findings. I compiled the old and new matchers and ran 109,200 differential comparisons in both modes, including empty strings, overlapping stars, question marks and multibyte names. All matched. The exact/single-star fast paths preserve the no-overlap length check; the general row update removes recursive backtracking. The CLA is a separate outstanding check.
Reviewed head 0529273ef40 (PR base f2003af73dc).
|
@qiyuhuating and @kuromiqiyu, please each read the RustFS Contributor License Agreement and post a separate comment on this PR with the exact text below. Both signatures are required for the CLA check to pass.
|
|
|
The bounded matcher landed on |
|
I have read and agree to the CLA. |
1 similar comment
|
I have read and agree to the CLA. |
Related Issues
Fixes #9483.
Summary of Changes
The IAM policy wildcard matcher recursively explores overlapping choices for each
*. A long S3 key that does not match a resource pattern with multiple stars can therefore monopolize request CPU. Replace recursive backtracking with a single-row dynamic program: O(pattern bytes × key bytes) time and O(key bytes) memory, without recursion or a growing call stack.Keep exact and single-
*patterns on allocation-free fast paths so ordinary resource policies do not pay for the dynamic-programming table. Preserve existing matching rules, including?matching one UTF-8 byte (not a Unicode scalar),*matching path separators, and the unusual exhausted-input behavior ofis_simple_match. Onlycrates/policy/src/policy/utils/wildcard.rschanges; no dependencies or policy schema changes.Verification
Tested with Rust 1.100.0 on Ubuntu 24.04 (WSL) against submitted commit
3ac23efb27690458b5f8d10668ef08ee06977117:cargo test -p rustfs-policy --tests --quiet -- --skip test_is_allowed_rejection_log_redacts_sensitive_endpoint: 769 passed, 0 failed, 1 pre-existing ignored, 1 explicitly excluded.*,?, empty inputs, and both matching modes: all decisions identical.cargo fmt --all -- --check: passed.cargo clippy -p rustfs-policy --all-targets -- -D warnings: passed. Cargo reports an unrelated, pre-existing unusedhotpathmanifest dependency warning.Unverified:
cargo-nextestwas unavailable locally. The excluded OPA fixturetest_is_allowed_rejection_log_redacts_sensitive_endpointwaited over 60 seconds on a local HTTP test-server thread and was not completed; it is outside the changed wildcard code path. Initial full-suite invocation was stopped rather than marked successful. Upstream CI has not yet passed.Impact
IAM authorization and S3 policy input/output contracts are unchanged, supported by exhaustive equivalence checks and existing authorization tests. A maliciously chosen object key cannot trigger exponential recursion in this matcher. Memory use is linear in the key length, not in the number of backtracking paths. Rollback is a single-commit revert.
Additional Notes
Security and compatibility: checked allow/deny parity, wildcard boundary cases, and UTF-8 byte semantics. Concurrency/durability: the matcher is pure, with no locks, I/O, or persistence changes. Performance: bounded dynamic programming replaces exponential backtracking, with fast paths for common patterns; no end-to-end server throughput claim is made.
AI assistance: ChatGPT assisted with implementation, differential testing, and code review. Contributor CLA signature, if required, must be completed separately.