Repository navigation
fix: a check allowed, and Permissions, Holding and Filter gave, what no moment did where a costly conditional grant was replaced as it ran at the budget's edge - #166
Merged
Conversation
…t did where a costly conditional grant was replaced as it ran at the budget's edge
… a condition can cost
…t replaced at the budget's edge frees
…s a conflict where every moment allowed A grant found gone was charged what 2 KiB of condition can cost, whatever the grant evaluated after it, so a dozen on a cluster, or a few on the tenant, used up the budget at every read. Before each condition, a check now spends what a gone grant sorted before it can have cost: no more than compiling that condition's bytes and maxCost.
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
Permissionslisted, what no moment allowed where a costly conditional grant was replaced as it ran at the budget's edge.false, and a decision the grants found allow stands.falseis 5 bytes, so it sorted first and cost 41, where the grant's own condition (still stored under a new id when it was replaced) costs its compile and evaluation. With conditions stored past the bounds, as pre-bound data, a CEL upgrade or a restore can leave them, the budget its own condition would have spent went to the grants after it. A grant past the budget at every committed moment was then evaluated, and its allow stood:Authorizereturned nil andPermissionslisted the permission, while the state before the replacement and the state after both denied, andExplaindenied too. Every other budget-edge difference fails closed. This one failed open.budget.owe). A grant sorted before it is no longer than it, so the charge is compiling the condition's own bytes plusmaxCostfor evaluating it. A gone grant sorted after it has cost nothing yet.Authorizecharges its budget.Permissionsand everything built onpermissionsOfcharge the budget of each permission the gone grant carried. A found grant can then allow only if the first statement's moment, with the gone grant at its real cost anywhere in the order, would have reached it too. Charging more than the real cost can only deny, and a denial beside a gone grant already reads the grants again (reread), so the result fails closed.ErrConflictthough every moment allowed. Reading the replacement's condition by key reads another grant, whose condition need not match the one that was stored at the first statement's moment. This charge needs neither an extra read nor the grant's text. An earlier version of this PR charged a flat 75,536 for each gone grant, the cost of 2,048 characters of 4 bytes plusmaxCost. That brought back fix: a check denied, and Permissions and Holding left out, what every moment allowed where a conditional grant was replaced as it ran, as extending one does #160's conflict: with about a dozen cheap grants on a cluster, or a few on the tenant, replaced at every read beside one that held,Authorize,PermissionsandHoldingreturnedErrConflictthough every moment allowed. Bounding the charge by the condition being evaluated keeps it near the gone grants' real cost for short conditions. Some of this remains, and it fails closed: the charge is the found grant's compile cost plusmaxCostfor each grant gone, wherever the gone ones sort, so a check within that of the budget's edge rereads, and isErrConflictif a change replaces the grants at every read. Within the bounds, one grant replaced at a time allowed in every shape measured. Many replaced together at every read can: with a 470-byte condition holding, 12 replaced together on the tenant (Holding) or 52 across a cluster's path (Authorize,Permissions); with a 49-byte one, 16 on the tenant. Canary allows these.Authorize(decideBy) is fixed.Permissions,Holding/holdingRead,Filter's holding, a labeled check's values (byLabel→holdingFor),Grantable's labels and a change's label values (decidedBy) all go throughpermissionsOf, which is fixed.Reachablereads its label values in one snapshot throughvaluesOn→conditionsOf, which refuses any gone grant, so it never finds one gone; a probe at the edge kept it closed with and without the fix.Explainreads conditions in the statement that reads the grants, so it never finds one gone; underWithTxits labels go throughpermissionsOf. Deny conditions are read with the grants, in one statement, and spend a budget of their own, so a deny can't be found gone and can't free a grant's budget.Holding,Permissionson the tenant andFiltergave, a label value no moment held.permissionsOftoo, so a costly one replaced mid-read freed the budget for a later one that holds. With the label values' grants stored past the bounds,Authorizeof a resource labeled with the value,Holding.Satisfies,Permissionson the tenant andFilterall gave the value during the race, and refused it before and after.permissionsOfapplies on the budget of each label value the gone grant carried.SetDeny, andSetGroupand the other group changes).readAtsets every condition in the batch tofalse.denyAllowedandmanagesGroupsreturn that read's error only wheremayrefuses. A cheapfalsecould free budget only for a grant whose condition was read in an earlier batch of the same authority. Each of these authorities is new (authoritiesInmakes one for each use and shares only grant positions, never conditions) and makes onemaycall. That call reads every unread grant giving the permission in one batch, so after a failed read none of their conditions allow, and only an unconditional grant can, which held at the moment the grants were read.DefineRolesandmayChangeByhave aconstrained, which keeps the error. A probe at the budget edge with SetDeny and SetGroup returnedErrConflictwith and without the fix when a costly grant was replaced at the change's first read of its grants. That is the only read the hook reached: at the edge, each change is refused before its locked phase. A change to always refuse there would have had no test that fails without it, so this PR makes none.ErrConflict, as fix: a check denied, and Permissions and Holding left out, what every moment allowed where a conditional grant was replaced as it ran, as extending one does #160 documents for a change, where it denied before.Testing
TestACostlyGrantReplacedAsACheckReadsItSpendsWhatItsConditionCould(rbac_test.go): conditions stored past the bounds by SQL, one holding grant sorted last, and costly grants added until a check can't reach it. The first costly grant is replaced between the read of the grants and the read of their conditions, throughSetReadingRoles. Without the fix,Authorizereturns nil andPermissionsreturns[cluster:login cluster:view]; with it, both deny. Reverting onlydecideBy's charge fails theAuthorizeassertion, and reverting onlypermissionsOf's fails thePermissionsone. The test also checks fix: a check denied, and Permissions and Holding left out, what every moment allowed where a conditional grant was replaced as it ran, as extending one does #160's steady state: a cheaper grant that allows still allows, inAuthorizeandPermissions, as the costly one is replaced at every read.TestAConditionalGrantBesideManyReplacedEachTimeTheyAreReadAllows(rbac_test.go): within the bounds, stored through the package. One grant that holds sits beside 12 cheap conditional grants ofcluster.loginon a cluster and 4 oflevel.highon the tenant, all replaced at every read. With the flat charge,Authorize,PermissionsandHoldingeach returnedErrConflictafter 3 reads. Withbudget.owe, and on canary, all three allow. Without themaxCostterm,TestACostlyGrantReplacedAsACheckReadsItSpendsWhatItsConditionCouldfails open again.TestALabelValuesCostlyGrantReplacedAsItIsReadSpendsWhatItsConditionCould(labels_test.go): the same setup for a label value. Without the fix,Holdinggiveslevel:high,Authorizeof a resource labeled with it returns nil,Permissionson the tenant returns[level:high]andFilterkeeps the labeled row; with it, all four refuse.Authorize,Holding.SatisfiesandPermissionson the tenant are true only during the race; with it, false before, during and after, and n=6 allows throughout.TestAConditionalGrantReplacedAsACheckReadsItIsReadAsItsReplacement,TestAConditionalGrantBesideOneReplacedEachTimeItIsReadAllows,TestALabelValuesConditionalGrantReplacedAsACheckReadsItIsReadAsItsReplacement,TestAChangeWhoseActorsConditionalGrantIsReplacedAsItReadsItIsAConflict) pass.MaxExpression, two gone together, and one beside a holding condition ofMaxExpressionbytes. Before, during and after a replacement,AuthorizeandPermissionsagree with the fix. On canary, the gone grant sorted before the one that holds, whether the same length or shorter, allows only during the race.make tidy-check lint vulncheckandgo test -race -shuffle=on -cover ./...) withGODEBUG=fips140=onlyagainst PostgreSQL 18, on 8ace13c: passed (2438.790s, coverage: 94.9% of statements).Checklist
make checkpasses🤖 Generated with pw code