-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistent responses from glob.match under certain conditions #2617
Comments
The problem is inside the rule indexer with how glob.match is handled. Here's a minimal repro:
With this ordering, the indexer only returns the second deny rule. If the order is reversed, both rules are returned (as expected). The problem is related to how the rule index was constructed. Incorrect:
Correct:
When the index is built incorrectly, the value mapper is missing from the trie node. The value mapper is needed to translate the incoming value (which is a string) into a value that the index/trie node can match on. For more details see tsandall@096670b. |
Previously when glob.match statements were indexed, the index trie node would have a mapper function set on it. The problem was that if subsequent rules were added to the index and required a different mapper (or none at all in the case of equality statements), the original mapper would be overwritten. This would result in false-negatives when the index was queried (i.e., the rule that was indexed first would not be returned). This commit fixes the issue by storing multiple mappers on the trie node (one per delimiter in the case of glob.match). If multiple mappers are encountered during traversal, each one will be tested. Fixes open-policy-agent#2617 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
Previously when glob.match statements were indexed, the index trie node would have a mapper function set on it. The problem was that if subsequent rules were added to the index and required a different mapper (or none at all in the case of equality statements), the original mapper would be overwritten. This would result in false-negatives when the index was queried (i.e., the rule that was indexed first would not be returned). This commit fixes the issue by storing multiple mappers on the trie node (one per delimiter in the case of glob.match). If multiple mappers are encountered during traversal, each one will be tested. Fixes #2617 Signed-off-by: Torin Sandall <torinsandall@gmail.com>
I haven't had the chance to dig too deeply into this yet but for certain policies the glob.match function appears to be returning inconsistent responses.
Expected Behavior
Consistent responses from:
Actual Behavior
Steps to Reproduce the Problem
We first observed this on OPA v0.21.0 though I pulled down the latest version to verify it still exists. To reproduce it I put the following two files in the policies directory and ran
for X in {1..20}; do go run main.go test ./policies; done
policy.rego
policy_test.rego
The text was updated successfully, but these errors were encountered: