Skip to content

Bugfix/aaronjeline/358#365

Merged
aaronjeline merged 9 commits intomainfrom
bugfix/aaronjeline/358
Oct 17, 2023
Merged

Bugfix/aaronjeline/358#365
aaronjeline merged 9 commits intomainfrom
bugfix/aaronjeline/358

Conversation

@aaronjeline
Copy link
Contributor

@aaronjeline aaronjeline commented Oct 16, 2023

Description of changes

Moves our parsers to reject duplicate keys, instead of having last-write-wins semantics.
Adds a new dependency on serde-with

Issue #, if available

#358 and #352

Checklist for requesting a review

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

  • A breaking change requiring a major version bump to cedar-policy (e.g., changes to the signature of an existing API).

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):

  • Does not require updates because my change does not impact the Cedar Dafny model or DRT infrastructure.

Disclaimer

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

})
}

fn load_actions_from_schema(entities: Entities, schema: &Option<Schema>) -> Result<Entities> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing this function has it will be incorporated into the main cedar library, and we want a very specific error semantics for it

Copy link
Contributor

Choose a reason for hiding this comment

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

This overlaps with my #360

Copy link
Contributor

Choose a reason for hiding this comment

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

but I think it's the same change, so we should be able to accept both in either order

#[should_panic(
expected = "error occurred while evaluating policy `policy0`: entity `Action::\\\"view\\\"` does not exist"
)]
#[should_panic(expected = "Action::\\\"view\\\"` does not have the attribute `readOnly`")]
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 having the entity specifies changes the error message.

Copy link
Contributor

Choose a reason for hiding this comment

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

This overlaps with my #360

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not surprising. We'll want to make sure yours wins.

Copy link
Contributor

Choose a reason for hiding this comment

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

but I think it's the same change, so we should be able to accept both in either order

EntityJsonParser::new(None, Extensions::all_available(), TCComputation::ComputeNow);
let e = eparser.from_json_value(json).err().unwrap();
let bad_euid: EntityUID = r#"User::"alice""#.parse().unwrap();
match e {
Copy link
Contributor

Choose a reason for hiding this comment

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

You can do something nice like

assert_matches(e, Err(EntitiesError::Duplicate(euid)) => {
  assert_eq!(bad_euid, euid, r#"Returned euid should be User::"alice""#);
});

for this sort of assertion


let context = Context::from_json_value(self.context, schema.as_ref().map(|s| (s, &action)))
let context = serde_json::to_value(self.context)
.map_err(|e| [format!("Error encoding the context as JSON: {e}")])?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This change should be made to the Context constructor.

Copy link
Contributor Author

@aaronjeline aaronjeline Oct 17, 2023

Choose a reason for hiding this comment

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

Has to happen here as well, once we deserialize to json the duplicates will already be lost.

Copy link
Contributor

Choose a reason for hiding this comment

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

are we serializing here or deserializing here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

De-serialized to a map so that we can use an annotation to fail on duplicates. Before we pass back to Context constructor we have to serialize back to a json-value. If we want to forbid duplicates in the context contructor itself, than this api can't just take a json value.

- The `Response::new()` constructor now expects a `Vec<AuthorizationError>` as its third argument.
- Implements RFC #19, making validation slightly more strict, but more explainable.
- Improved formatting for error messages.
- Standardized on duplicates being errors instead of last-write-wins for parsers.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should be slightly more specific -- maybe list the affected APIs?


let context = Context::from_json_value(self.context, schema.as_ref().map(|s| (s, &action)))
let context = serde_json::to_value(self.context)
.map_err(|e| [format!("Error encoding the context as JSON: {e}")])?;
Copy link
Contributor

Choose a reason for hiding this comment

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

are we serializing here or deserializing here?

@aaronjeline
Copy link
Contributor Author

aaronjeline commented Oct 17, 2023

Blocked on: cedar-policy/cedar-java#53
Fixed

@aaronjeline aaronjeline force-pushed the bugfix/aaronjeline/358 branch from 72a9843 to f3c3457 Compare October 17, 2023 15:41
@aaronjeline aaronjeline merged commit b9a9dd7 into main Oct 17, 2023
@aaronjeline aaronjeline deleted the bugfix/aaronjeline/358 branch October 17, 2023 20:04
@sarahcec sarahcec added the 3.0 label Nov 27, 2023
shaobo-he-aws pushed a commit that referenced this pull request May 20, 2025
Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
benelser pushed a commit to benelser/cedar that referenced this pull request Jan 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants