Repository navigation
Conversation
Every ACL check that misses the exact rules matches the path against each
segment wildcard ("+") rule. tryMatchWildcardPath split every rule with
strings.Split and filled a segments slice that nothing read, so each check
allocated two slices per "+" rule, and AllowOperation runs it for both
slash forms of the path. Walk the rule's segments with strings.Cut instead
and drop the unused slice.
The bare mount loop in CheckAllowedFromNonExactPaths, which
sys/internal/ui/mounts runs for each mount, gets the same walk, and only
allocates its segments once a rule's first segment matches.
BenchmarkACL_SegmentWildcardRules measures both.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
When a request path misses the exact rules,
AllowOperationmatches it against every segment wildcard (+) rule of the token's policies, and it does that for both slash forms of the path. For each rule,tryMatchWildcardPathsplit the rule withstrings.Splitand filled asegmentsslice that nothing reads, so every check allocated two slices per+rule. With many+rules, as in the policies from #24289 (38 policies with paths such asTEST/+/SUB/*), that is most of the time of the check (see below), and the check runs on every request, once per path insys/capabilities*, and once per mount insys/internal/ui/mounts.This walks the rule's segments with
strings.Cutand drops the unused slice. The bare mount loop inCheckAllowedFromNonExactPaths(used bysys/internal/ui/mounts) needs its segments, so it keeps them, but it gets the same walk and only allocates them once a rule's first segment matches. Matching results don't change.Benchmarks: I ran 6 rounds of each build, alternating base and patched, on an i7-9700 with Windows 11 and Go 1.27.4. Times are medians, with the range in brackets.
BenchmarkACL_SegmentWildcardRules(added invault/acl_test.go): one ACL with N rules likeengine3/+/team7/*, checking a path that matches one of them (-benchtime 1s):Through
Core.HandleRequest(a local benchmark I didn't include): 10 KV v1 mounts and a token with 38 policies of 25+rules each (950 rules),-benchtime 2s:sys/capabilities-self, 100 pathssys/internal/ui/mountsWith 10 policies of 10 rules (100 rules), the same requests got 6.6%, 6.7% and 25% faster.
Tests: the existing
TestACL_*(includingTestACL_SegmentWildcardPriority,TestACL_SegmentWildcardPriority_BareMountandTestACL_ListTrailingSlashDeny),TestCapabilities*,TestSystemBackend_Capabilities*,TestSystemBackend_PathCapabilities,TestSystemBackend_InternalUIMount(s)andTestPolicyStore_*pass before and after. I also compared the old and new loops on 5 million random rule and path pairs each, and they gave the same results.Changelog:
changelog/32211.txt: