Repository navigation
fix: a change read the condition of every conditional grant its actor held on the path, of any role, twice - #150
Merged
Conversation
…ed the change, and Grantable listed nothing, rather than return the error
… gives for good, and a failed read returns its error
… into a decision for each beside unread conditional grants ending between theirs
… actor's power alone through them or beside its own
… conditions of the actor's grants ending between theirs in a statement for each
Michael McQuade (giraffesyo)
marked this pull request as ready for review
November 15, 2026 01:28
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
authoritiesInlooked up the condition of every conditional grant the actor held on the scope's path before anything decided which mattered, and the locked phase ran it again and looked them all up again;Grantabledid the same.Authorizereads only those of the roles giving the permission it checks. An actor holding 20,000 conditionalcluster.logingrants on a cluster, beside an unconditionalcluster.admin, had eachApplygranting one role read about 121,200 pages ofrbac_grants(0.4 s), whereAuthorizeread about 600. Through the API anyone's grants could put that on everyone:Importof 250 custom roles × 4 path scopes × 20 conditions to the tenant's members, within every bound, made every member'sApplyon the cluster read 121,370 pages (373 ms), whereAuthorizeread 8. Every caller ofauthoritiesInhad the cost:Apply,Grantable,SetRole,SetDeny,ChangeMembersandSetMembershipsthrough their authority over groups.:grantpower, a permission the change hands on), as a check does (conditionReads). Conditions read in a call are kept by grant id for the rest of it, so the read under the locks takes them from there: a grant's condition never changes in place, asApplyandImportreplace a grant only under an equal condition and a grant made again has a new id. A grant whose condition wasn't read never changes a decision: its role gives nothing the change asks, or a grant read already gives it for good. Grants made until a time are decided together where the actor's grants can't tell their ends apart (decidedAs), so under a condition, the unread grants of roles giving what deciding the role can ask about (what it and the roles it lists give) that end at or after the grant are read first. Standing in unread by their ends instead, 64 grants of a role giving nothing asked, ending between those of a change's 64 grants, split it into 64 decisions, each walking every role the role lists: 211 ms where canary 371f67f, reading their conditions, took 30 ms. Those are read for all of a change's grants at once, for each role until the soonest it is granted until: read for each grant in turn, a change granting 64, each until a time before the one before it, beside 64 grants of a role giving a permission it asks ending between theirs, read their conditions in 64 statements, 44 ms where canary took 26 ms. The cheapest-first order applies to the grants whose conditions were read. A read that fails leaves those grants met by nothing and returns its error: where that left the actor no power to change grants there,Applyreturns it rather than a refusal, andGrantablerather than no roles.No migration, exported name or stored value changes.
Testing
rbac_grantsread by the measuredApply(the run after its plans are built), the actor holding n conditional grants ofcluster.loginand 1, 50 or 0 ofcluster.admingiving the power:AuthorizeImportof 20,000 to the membersConditions read per
Applywent from 2n to 1, 50 or 0.TestAChangeReadsTheConditionsOfOnlyTheGrantsItDecidesBy(new), underforce_custom_planandforce_generic_plan. Without the fix:under force_custom_plan, Apply read 12259 pages of grants and 4000 conditions(generic: 12228 and 4000).TestAChangeReadsNoConditionOfTheMembersGrantsGivingNothingItAsks(new). Without the fix:under force_custom_plan, Apply read 12157 pages of grants and 4000 conditions(generic: 12142 and 4000).TestAChangeReadsTheConditionsItDecidesByOnce(new). Without the fix:under force_custom_plan, Apply read 12204 pages of grants, Authorize 6072, and the two 6000 conditions(generic: 12159).TestAChangeDecidesARoleOnceBesideUnreadGrantsEndingBetweenItsGrants(new): an actor holding the power under a condition and 16 unread conditional grants of a role giving nothing asked, ending between those of a change granting a role listing 8 others to 16 under that condition. Without reading them first:granting 16, each until its own time, checked 288 roles, where granting one checked 18. Measured with 64 grants of a role listing 63 that list each other: 64 such grants, 28 ms, 128 role checks (before 211 ms, 8,064; canary 30 ms, 128); 20,000, 298 ms and 3,747 pages (before 403 ms; canary 452 ms and 123,753); where those grants give a permission the decision reads, 20,000 are read once, 326 ms and 63,750 pages (canary 478 ms and 123,751, read twice).TestAChangeReadsTheConditionsOfGrantsEndingBetweenItsGrantsAtOnce(new): an actor holding the power under a condition and 16 unread conditional grants of a role givingcluster:view, ending between those of a change grantingcluster.loginto 16 under that condition, each until a time before the one before it. Without reading them for all grants at once:granting 16, each until a time before the one before it, read conditions in 16 statements, where granting one read them in 2. Measured with 64 such grants: 26 ms (before 44 ms; canary 26 ms); with 2,000, ending four minutes apart: 48 ms (before 72 ms; canary 55 ms).TestAChangeWhoseConditionsCantBeReadReturnsWhy(new): the actor holdingcluster.adminonly under a condition, its context canceled once its grants are read. Without the check:Apply: rbac: cluster:grant deniedandGrantable: <nil>, 0 roles; canary 371f67f returnedcontext canceledfor both.TestEveryChangeWhoseConditionsCantBeReadReturnsWhy(new):DeleteRole,SetDeny,SetGroupandChangeMembersby an actor holding the power only through conditions, andApplyandGrantableby one with power of its own beside a conditionalcluster.admin, its context canceled once its grants are read, returncontext canceled, andOnRefusedisn't told. Without the checks:rbac: tenant:define-roles denied,cluster:deny denied,tenant:groups denied,group:members denied, each told toOnRefused; andcluster:grant denied, andGrantablereturning no error.:grantpowers, listing roles and roles handed on, to users and groups, some expiring, a group membership ending; randomApplywith conditions, ends and revokes,SetRolewithGrantableRoles,SetEligibilityandActivatewith approvers,SetDenywith exemptions and conditions,ChangeMembersunder a conditionalGroupMembersgrant,DeleteDenyandDeleteRole, andGrantableof four actors on a cluster and a workspace after every step: 300 seeds × 80 steps on this branch and on canary 371f67f, 24,000 steps (4,051 accepted, 17,223 refused, 2,471 invalid) and 192,000Grantableanswers alike, but for the order of two refusals oneChangeMembersjoins, which varies from run to run on canary too; and 150 more seeds × 80 steps once the unread grants ending at or after a grant are read first, 12,000 steps and 96,000 answers, alike. Run under-racetoo, with eight goroutines callingApplyandGrantableon oneAuthorizerand onWithTxcopies at once, and eight granting 16 each, until times before the one before, on oneAuthorizer.:grantpowers, roles listing others, custom roles listing custom roles redefined between steps), some through groups whose memberships end, under a deny exempting a group, each step anApplyof 2 to 11 grants under one condition, each until a time at, a microsecond either side of, or five minutes either side of the end of one of the actor's grants: 100 seeds × 120 steps on this branch and on canary 371f67f, about 19,000 grants decided alike, about 5,000 of them allowed.Applywith grants, expiring grants and revokes by ID in five spellings,SetRole,DeleteRole,SetEligibility,Activate,Deactivate,SetDenyandDeleteExpiredby four actors under random denies, a constraint and a listing role), 80 seeds × 120 steps on this branch and on canary 371f67f: all 9,600 steps decided alike, 3,187 accepted and 6,413 refused with the same errors, and every refused change left no rows, history or events; and again on 332fa6c, 9,600 steps alike.make tidy-check lint vulncheckandGODEBUG=fips140=only go test -race -shuffle=on -cover -timeout 60m ./...against PostgreSQL 18 on 55432, on 332fa6c: passed (2469.646s, coverage: 94.9% of statements).Checklist
make checkpasses🤖 Generated with pw code