-
Notifications
You must be signed in to change notification settings - Fork 376
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
String matching: match long strings #1806
Conversation
✅ Deploy Preview for tetragon ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
a8361d4
to
2d96730
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, the code changes look good to me, but can you also add some tests for these specific cases?
Also, I believe we need to backport this to 1.0. I've added a label. |
Prefix matching is done by looking up the provided string in the LPM TRIE string prefix map (for strings and file paths). Currently, we don't look up strings that are longer than the prefix map can hold. This is a bug, because we could still look up the beginning substring (to the max the map allows) and if it matches, then the full string would also match (if the map size permitted it). This commit detects strings that are longer than the map allows and instead of not matching, it looks up the longest beginning substring that the map allows instead. This will allow prefix matching to be used on all strings and not just the ones short enough to fit into the prefix map. Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
Postfix matching is done by reversing all the postfixes and storing them in a LPM TRIE map, and then reversing the string to match on and looking it up in the map. If the string to match is longer than the postfix max length then the string would not be matched, leading to long strings not being subject to the match logic. This commit modifies the look up to handle strings longer than the postfix max length. It fixes the length to copy to the postfix max length and supplies an offset from where to start copying. The offset is calculated as the difference between the original length and the capped length. Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
Add tests for very long (>256 chars) paths for prefix and postfix selectors. Signed-off-by: Kevin Sheldrake <kevin.sheldrake@isovalent.com>
2d96730
to
71604ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
The current implementation ignore prefix and postfix matching on strings that are longer than the prefix max or postfix max (accordingly).
These patches modify the logic to handle strings that are longer than these maximums by restricting the string to the maximum permitted by the LPM TRIE maps – from the beginning for prefix and from the end for postfix.