Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

increase validator precision for some Unspecified cases #603

Closed
wants to merge 4 commits into from

Conversation

cdisselkoen
Copy link
Contributor

Description of changes

Increases validator precision (typing False instead of Bool) in some edge cases involving Unspecified. Also, change from TypecheckFail to TypecheckSuccess in one of these edge cases in particular.

This is a backwards-incompatible change unless/until ImpossiblePolicy is moved from an error to a warning. We should probably not merge this until we've decided whether that will happen.

The change in this PR is (choose one, and delete the other options):

Breaking, unless we wait to merge this until ImpossiblePolicy is moved from an error to a warning, in which case non-breaking. I also only observed the impact of this change in Permissive validation mode, which is an experimental feature in 3.x. I'm not sure (not qualified to determine) whether this change has any impact in Strict validation mode, ie, on the stable 3.x validator.

I confirm that this PR (choose one, and delete the other options):

  • Updates the "Unreleased" section of the CHANGELOG with a description of my change (required for major/minor version bumps).

I confirm that cedar-spec (choose one, and delete the other options):

  • I'm not sure how my change impacts cedar-spec. (Post your PR anyways, and we'll discuss in the comments.)

I'm not sure whether this behavior matches the Lean validator, which doesn't yet fully match the Rust validator anyway. I believe that neither before nor after this PR will the behavior exactly match the Dafny validator, but I propose that this is the correct/ideal behavior, which we want Dafny to match? (That's a point for discussion below)

Disclaimer

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@cdisselkoen cdisselkoen marked this pull request as ready for review January 26, 2024 14:19
@cdisselkoen
Copy link
Contributor Author

The current version of this PR is wrong, because unspecified in unspecified and unspecified in [X, Y, ...] when at least one of X, Y, ... is unspecified, need to be typed Bool. (That's because two unspecified entities are still equal if their Eids are equal.) I will revise

@cdisselkoen
Copy link
Contributor Author

Revised, hopefully the new code is the correct/ideal behavior. Looking for review.

To answer one of the questions from the PR description, this (should be) a backwards-compatible change, because the only edge cases it changes behavior for involve [] (the empty set), and the empty set is only valid under Permissive validation, which is an experimental feature in 3.x. This (should) have no effect on the stable 3.x validator -- hoping a reviewer can confirm.

Copy link
Contributor

@khieta khieta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Motivated by this PR, I spent some time looking through the Rust code vs. the spec and I think the fix is actually simpler than what you have here: the Dafny function tryGetEUIDs returns None for an empty list while the corresponding Rust function euids_from_euid_literals_or_action returns Some([]). I think you can fix the behavior difference by just adjusting one of these functions to match the other.

Copy link
Contributor

@john-h-kastner-aws john-h-kastner-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely confident this doesn't affect strict validation. As noted, that could be fine if we make the ImpossiblePolicy change.

Kesha's suggestion seems worth looking into.

@@ -1916,7 +1916,10 @@ impl<'a> Typechecker<'a> {

// Given an expression, if that expression is a literal or the `action`
// variable, return it as an EntityUID. Return `None` otherwise.
fn euid_from_euid_literal_or_action(request_env: &RequestEnv, e: &Expr) -> Option<EntityUID> {
fn euid_from_euid_literal_or_action<T: Clone>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem with this generalization, but I don't see where it's necessary.

)
} else {
// nothing on the RHS can be unspecified, so `unspecified in RHS` is always false
TypecheckAnswer::success(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might change strict validation for something like principal in [resource.owner] when principal is unspecified and resource.owner is some entity type.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right. That doesn't mean this precision increase is invalid, just that it's currently breaking (unless/until we change ImpossiblePolicy from error to warning)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I'm not sure if you're correct. I believe principal in [resource.owner] when principal is unspecified and resource.owner is some entity type, might short-circuit out here and never reach this function at all.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed that earlier handling handles this case. But I'm not sure this new definition matches the spec -- the Dafny code will always return AnyBool in the case where the RHS cannot be converted to a list of Entity UIDs.

@cdisselkoen
Copy link
Contributor Author

Closing this in favor of #615 and #620. See comments on those.

@cdisselkoen cdisselkoen closed this Feb 2, 2024
@cdisselkoen cdisselkoen deleted the cdisselkoen/unspecified-in-precision branch February 2, 2024 14:54
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.

3 participants