Skip to content

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
Michael McQuade (giraffesyo) merged 5 commits into
canaryfrom
fix/gone-grant-budget
Nov 25, 2026

Conversation

@giraffesyo

@giraffesyo Michael McQuade (giraffesyo) commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • A check allowed, and Permissions listed, what no moment allowed where a costly conditional grant was replaced as it ran at the budget's edge.
    • The problem: A check on a pool reads a subject's grants in one statement and their conditions in another. Since 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, a grant gone between the two (revoked, or replaced as extending a conditional grant replaces it) is read as false, and a decision the grants found allow stands. false is 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: Authorize returned nil and Permissions listed the permission, while the state before the replacement and the state after both denied, and Explain denied too. Every other budget-edge difference fails closed. This one failed open.
    • The fix: Before a check evaluates each condition, it now charges for every grant found gone. The charge is the most a gone grant sorted before that condition could have cost (budget.owe). A grant sorted before it is no longer than it, so the charge is compiling the condition's own bytes plus maxCost for evaluating it. A gone grant sorted after it has cost nothing yet. Authorize charges its budget. Permissions and everything built on permissionsOf charge 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.
    • Why this option: The other options in the audit need to know where the gone grant sorts. Letting an allow stand only when the budget was never exhausted isn't enough: in the reproduction the budget was not exhausted during the race, because the gone grant freed it. Refusing every allow beside a gone grant brings back what 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 review fixed: a check beside a grant a change keeps replacing ends as ErrConflict though 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 plus maxCost. 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, Permissions and Holding returned ErrConflict though 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 plus maxCost for each grant gone, wherever the gone ones sort, so a check within that of the budget's edge rereads, and is ErrConflict if 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.
    • Paths checked: 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 through permissionsOf, which is fixed. Reachable reads its label values in one snapshot through valuesOn → 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. Explain reads conditions in the statement that reads the grants, so it never finds one gone; under WithTx its labels go through permissionsOf. 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.
  • The same race on label values: a check of a labeled resource allowed, and Holding, Permissions on the tenant and Filter gave, a label value no moment held.
    • The problem: Label-value grants on the tenant are decided by permissionsOf too, 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, Authorize of a resource labeled with the value, Holding.Satisfies, Permissions on the tenant and Filter all gave the value during the race, and refused it before and after.
    • The fix: The same charge, which permissionsOf applies on the budget of each label value the gone grant carried.
  • No change needed: changes whose actor's power is decided without constraints (SetDeny, and SetGroup and the other group changes).
    • What was checked: After a failed read of conditions, readAt sets every condition in the batch to false. denyAllowed and managesGroups return that read's error only where may refuses. A cheap false could free budget only for a grant whose condition was read in an earlier batch of the same authority. Each of these authorities is new (authoritiesIn makes one for each use and shares only grant positions, never conditions) and makes one may call. 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. DefineRoles and mayChangeBy have a constrained, which keeps the error. A probe at the budget edge with SetDeny and SetGroup returned ErrConflict with 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.
  • A change's own power on a labeled resource was never let through: the change decides again under its locks. With the fix, its first phase refuses as 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.
  • README.md and docs/architecture.md describe the charge where they describe the budget's edge and 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 reread.

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, through SetReadingRoles. Without the fix, Authorize returns nil and Permissions returns [cluster:login cluster:view]; with it, both deny. Reverting only decideBy's charge fails the Authorize assertion, and reverting only permissionsOf's fails the Permissions one. 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, in Authorize and Permissions, 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 of cluster.login on a cluster and 4 of level.high on the tenant, all replaced at every read. With the flat charge, Authorize, Permissions and Holding each returned ErrConflict after 3 reads. With budget.owe, and on canary, all three allow. Without the maxCost term, TestACostlyGrantReplacedAsACheckReadsItSpendsWhatItsConditionCould fails open again.
  • TestALabelValuesCostlyGrantReplacedAsItIsReadSpendsWhatItsConditionCould (labels_test.go): the same setup for a label value. Without the fix, Holding gives level:high, Authorize of a resource labeled with it returns nil, Permissions on the tenant returns [level:high] and Filter keeps the labeled row; with it, all four refuse.
  • The audit's label reproduction (comp.alpha grants on the tenant, n=7): without the fix, Authorize, Holding.Satisfies and Permissions on the tenant are true only during the race; with it, false before, during and after, and n=6 allows throughout.
  • 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 tests (TestAConditionalGrantReplacedAsACheckReadsItIsReadAsItsReplacement, TestAConditionalGrantBesideOneReplacedEachTimeItIsReadAllows, TestALabelValuesConditionalGrantReplacedAsACheckReadsItIsReadAsItsReplacement, TestAChangeWhoseActorsConditionalGrantIsReplacedAsItReadsItIsAConflict) pass.
  • At the budget's edge, tuned to within one byte of condition, conditions stored past the bounds by SQL: a gone grant of the same length as the one that holds, sorted before it and after it, a shorter one, a longer one, one longer than MaxExpression, two gone together, and one beside a holding condition of MaxExpression bytes. Before, during and after a replacement, Authorize and Permissions agree 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.
  • The audit's reproduction at n=26, 27 and 28: during the race the result now matches the moments before and after (allowed at 26, denied at 27 and 28).
  • Full suite (make tidy-check lint vulncheck and go test -race -shuffle=on -cover ./...) with GODEBUG=fips140=only against PostgreSQL 18, on 8ace13c: passed (2438.790s, coverage: 94.9% of statements).

Checklist

  • make check passes
  • No exported name, stored value or table was renamed (they are contract once released)

🤖 Generated with pw code

…t did where a costly conditional grant was replaced as it ran at the budget's edge
…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.
@giraffesyo
Michael McQuade (giraffesyo) marked this pull request as ready for review November 25, 2026 12:45
@giraffesyo
Michael McQuade (giraffesyo) merged commit 5efe310 into canary Nov 25, 2026
10 checks passed
@giraffesyo
Michael McQuade (giraffesyo) deleted the fix/gone-grant-budget branch November 25, 2026 13:22
@github-actions github-actions Bot mentioned this pull request Nov 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant