Repository navigation
fix: Reachable and Filter read every custom-role grant a key held on the listed type, and sought every role giving the permission however many there were - #151
Draft
Michael McQuade (giraffesyo) wants to merge 12 commits into
Conversation
…s held on the listed type, and sought each role giving the permission however many did Past heldByScope a key's grants on a type are read a role at a time for the built-in and the tenant's custom roles giving the permission, and only where the key holds heldPerRole grants for each of those roles, so a catalog of many giving roles keeps the read by the scope. broadArgs tests the broad keys' custom roles so too.
…m ones too, and by the scope beside many giving roles
… grown with the roles giving the permission, custom ones included
… a key holds, by key, rather than reading the tenant's custom roles A key's custom roles are found by stepping through rbac_grants_principal_role a role at a time and looked up in rbac_roles by key; the roles giving the permission and the bound they set are read once for each key and type.
…ype to find which custom roles it held Each step of the scan through a key's custom roles is a row comparison in rbac_grants_principal_role's order, which no index leading to the scope after the principal reads in order.
…he run after the one planning its statements
…d on the run after the one planning them
…ted, so planning a statement again reads none of them
…ose giving the permission, whatever they gave and wherever they were granted A key's grants of custom roles on a type are read apart from its grants of built-in roles: by the scope up to 64, and past that a role at a time only where those 64 name 16 roles or fewer and the key holds 16 custom roles or fewer, found by stepping through them by key; otherwise by the scope, as before. The members' grants of 300 custom roles, one on each of 300 clusters, cost a member's Reachable 1,900 pages, where by the scope it read 210.
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.
Summary
ReachableandFilterread every custom-role grant a key held on the listed type, whatever the role gaverbac_grants_custom_principal. Deciding which custom roles the members' and the public's grants name (broadArgs) read them all as well. Beside a tenant's custom viewer (cluster:view) granted to the members on 20,000 clusters, a member'sReachableforcluster:loginread 8,927 pages ofrbac_grants, and a host's query ofFilter's condition read 17,922. Granted to the subject itself, they read 4,474 and 13,377.Authorizeread 14.rbac_grants_custom_principalas before, up to 64. Past that, where those 64 name 16 roles or fewer, it finds the custom roles the key holds: it steps from one to the next inrbac_grants_principal_role, one seek each, looks each up inrbac_rolesby(tenant, id), and keeps those giving the permission on the type. It keeps them with the predicategivingSQLdecides with, in the same statement, so a concurrentSetRoleis seen by both alike. It then seeks the grants of each of those roles alone, or reads by the scope while the key holds fewer than 4 for each. It stops after 16 custom roles, and reads a key holding more by the scope, as before: each step costs about what reading a few grants does, whatever the role gives or wherever it is granted. Past 64,broadOntests each giving custom role for a grant on the type withEXISTS, under the same bounds, instead of reading every custom grant. No migration is needed.cluster:login, a subject in 20 groups each holding 100 grants read 60,775 pages, against about 700 reading by the scope.max(64, 4 × the built-in roles giving the permission)grants on the type (heldPerRole). A key is still read one way, once.Pages of
rbac_grantsread, before → after (plan for the arguments / generic plan):ReachableFilter's conditionReachableFilter's conditionReachableFilterReachableReachableFilter's conditionThe first six rows and the stock catalog's are counted by the round 20 audits' tests, which leave the grants' partial indexes empty; the last two by this branch's tests' harness, which fills them (
filled). Under a plan for the arguments, which is made for every call, part of the stock catalog's 40 more pages is the metapages of those indexes, read in planning (see Testing); under a generic plan it reads whatcanarydoes. Where a key holds 64 grants on the type of more than 16 custom roles, it reads its first 64 by the scope twice, about 10 to 15% more thancanary, a cost that doesn't grow with the grants or the roles. An earlier version of this branch stepped through every custom role a key held, and read 1,912 / 1,902 pages there.As of a time, searches read as before: by the scope, every grant of a key on the type, of any role. The docs now say so.
Testing
TestSearchesReadOnlyTheCustomGrantsOfRolesGivingThePermissioncounts the pagesReachable,Filterand a query ofFilter's condition read beside 500 and 5,000 grants of a custom role giving nothing. It covers grants to the members, to the subject and to a group, underforce_custom_planandforce_generic_plan; under the generic plan it counts the run after the one that builds the plan. Without the fix it fails, for exampleReachable read 322 pages ... the members', and 2310 beside 5000. With onlybroadOnreverted, the members' case still fails (Reachable read 212 ... and 1208).TestSearchesReadByTheScopeBesideManyRolesGivingThePermissioncovers 20 groups each holding 100 grants, with and without 200 more roles giving the permission. Without the fix it fails, for exampleReachable read 780 pages ... and 12780 beside 200 more.TestRvListsAgreeInRandomWorldsandTestAuditListsAgreeInRandomWorlds, 6 seeds each) were run on this branch and oncanary. The branch ran atheldByScope0, 1, 64 and the default, withheldPerRoleat 0 and at the default, so both the role-at-a-time read and the two-step bound are exercised.canaryran at 0, 1, 64 and the default. Onfffaeb5, all six branch runs (heldByScope/heldPerRole0/0, 1/0, 0/default, 1/default, 64 and the default) and canary's 0, 1 and 64 were IDENTICAL to canary's default once grant UUIDs were masked. The audit harness passed at each of those settings on both heads. On988f8d1, the default andheldByScope1 withheldPerRole0 were IDENTICAL to canary's default andheldByScope1. Onbec9812and on21c9082, which mergescanaryata1f1583, both settings were IDENTICAL as well. They weren't run again once the custom grants were read apart; the randomized differential test below covers that head.TestSearchesStepThroughFewOfTheCustomRolesAKeyHoldscovers the members' and the subject's grants: beside 100 grants of a custom viewer on clusters, grants of 100 and of 1,000 roles on another type; and grants of 300 custom roles giving nothing, one on each of 300 clusters, against reading by the scope. Against this branch's earlier head21c9082, which stepped through every custom role a key held, it fails:Reachable read 721 pages beside grants of 100 custom roles elsewhere that are the members', and 8212 beside 1000, andReachable read 1912 pages beside grants of 300 custom roles that are the members', and 188 by the scope. Without the check of how many roles the first 64 grants name, it fails:Reachable read 341 pages ... and 198 by the scope. Oncanaryonly the members' query ofFilter's condition fails (306 → 493).TestCallsReadByKeyUnderAPlanMadeWhileTheTablesWereSmallfailed on a version that read the tenant's custom roles giving the permission by the tenant; this one reads them by key.Reachableand query ofFilter's condition forcluster:loginandcluster:viewwere compared underheldByScope/heldPerRole64/4, 0/0, 1/0, 1/4, 16/4, 64/0 and 3/1, which step through every custom role, through 16, 4, 3 or none, against reading by the scope alone, under both plan modes. All agreed onb6b2c57, and the results matchedcanary's and21c9082's.TestFilterCountsAFewOfItsSubjectsGrantsOfBuiltInRolescaught a first version of that scan, which read and sorted every grant the subject held throughrbac_grants_key. It passes.TestSearchesReadOnlyTheGrantsOfRolesGivingThePermissionand the three new tests count each search on the run after the one that plans it, under the generic plan. They also keep autovacuum offrbac_grantsand put one grant of another tenant in each of its partial indexes (filled).rbac_grants. So onbec9812, planning the broadArgs statement and Filter's count read 25 and 50 pages, against 5 and 30 oncanary.bec9812andcanaryread 0 under a generic plan, and 3 and 68 under a plan for the arguments against canary's 2 and 66.canary.Filter read 169 pages beside 500 grants that are the members', and 1186 beside 5000.rbac_grants, on each plan, and this branch has more references thancanary. Under a plan for the arguments, which is made for every call, the empty indexes cost each call, beside 300 custom roles:Reachable33 to 43 hits (canary2 to 7),Filter55 to 57 (19 to 28), and a query ofFilter's condition 85 to 99 (39 to 46). They don't grow with the grants or roles, and a generic plan, once made, pays none.golangci-lintreports no issues.make tidy-check lint vulncheckandGODEBUG=fips140=only go test -race -shuffle=on -cover -timeout 60m ./...against PostgreSQL 18 on 55432, on a026738 (merged with canary 9872532): RESULT.Checklist
make checkpasses🤖 Generated with pw code