Allow reauthorization with also initially undiscovered unknowns in the Expr #1466
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 of changes
Fixes: #1465
Please read the issue description first for context.
There might be "undiscovered" unknowns in a partially evaluated
Expr
residual. In my example in #1465, that would beresource.newlabels
that is during the first partial evaluation call omitted and thus unknown, but not yet evaluated by Cedar into aunknown("resource.newlabels")
, as the LHS of the&&
didn't proceed to evaluate the RHS (#1445).In the issue I described three quick potential solutions, of which this one probably is the most realistic to actually implement.
This PR solves the described issue by moving the reauthorization substitution logic from
expr.substitute
topartial_interpret
, where unknowns can be looked up any number of times needed, also while proceeding to the RHS of an&&
(of course, given the LHS evaluated to true). The code isn't super neat, having to pass themappings
around everywhere, I'm definitely open to discuss neater solutions.Note:
Expr.substitute
is now almost unused; the only place I saw it used is inContext.substitute
, which indeed is used.Longer-term, indeed RFC 95 is the better solution, addressing this bug and probably a whole class of others in one go. However, I wanted to open this PR to show the approach, as at the end of the day, the fix wasn't very complicated (and hopefully I didn't break anything else).
If this becomes an accepted approach to go forward in the short term, I'll make tests, etc. so this PR becomes ready to merge.
Checklist for requesting a review
The change in this PR is (choose one, and delete the other options):
cedar-policy-core
,cedar-validator
, etc.). Also this only touches experimental code.I confirm that this PR (choose one, and delete the other options):
I confirm that
cedar-spec
(choose one, and delete the other options):I confirm that
docs.cedarpolicy.com
(choose one, and delete the other options):