Skip to content

Conversation

cdisselkoen
Copy link
Contributor

Description of changes

Allow entity attributes and tags to contain Action-typed entities. This was always supported in the evaluator, but is now also supported in policy validation, entity validation, and request validation. Any action UID literals that appear in attribute values or tag values must refer to actions that actually exist in the schema.

Issue #, if available

Fixes #304

Checklist for requesting a review

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

  • A bug fix or other functionality change requiring a patch to cedar-policy.

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 formal model or DRT infrastructure.

I confirm that docs.cedarpolicy.com (choose one, and delete the other options):

  • Does not require updates because my change does not impact the Cedar language specification.

Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
Copy link

github-actions bot commented Jun 6, 2025

Coverage Report

Head Commit: f9835d7f3de899f278bf60ac9020c9a3c759093f

Base Commit: 39700c469730fe354ae6a014d3cd5b92dfeb3d47

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 92.75%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-core/src/entities/conformance.rs 🟢 19/19 100.00%
cedar-policy-core/src/validator/coreschema.rs 🔴 4/9 44.44% 244-248
cedar-policy-core/src/validator/schema.rs 🟢 41/41 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 81.95%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-policy 🔴 3223/4654 69.25% 69.25%
cedar-policy-cli 🔴 571/972 58.74% 58.74%
cedar-policy-core 🟢 21059/24778 84.99% 84.96%
cedar-policy-formatter 🟢 1074/1206 89.05% 89.05%
cedar-wasm 🔴 0/29 0.00% 0.00%

.iter()
.map(|action_def| action_def.entity_type().as_ref().as_ref().clone())
.collect();
for action_type in action_types {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you use for_each instead of the collect + loop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original reason for the .collect() is to avoid mutating-while-iterating. Stated in terms of the borrow checker, the first pass over action_types (lines 613-617) needs an immutable borrow of all_defs, while the second pass (lines 618-620) needs a mutable borrow of all_defs. So, we have to completely finish iterating all_defs in the first pass before the second pass can start; we can't make the mark_as_defined_entity_type() calls in the same iterator chain.

I'm certainly open to a better solution if there's a better pattern to use here.

Copy link
Contributor

@john-h-kastner-aws john-h-kastner-aws Jun 10, 2025

Choose a reason for hiding this comment

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

We could probably obtain the set of defined action types without iterating over all_defs.action_defs since there's only ever one action type defined per name space. Maybe that'd be a little more brittle than basing it off the actual actions, but it could save some time if there are a lot of actions in one namespace

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense. Thank you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there's only ever one action type defined per name space

How I've implemented it in this PR, there are either 0 or 1 action types defined per namespace. I have a test which demonstrates that if there are no actions defined in a namespace, the corresponding action type in that namespace is not defined either. This is important for name resolution to work if you want to refer to unqualified Action from within a namespace block

Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
Copy link

Coverage Report

Head Commit: 308878ef22d4b9365b9866863a86d21eb2a1132a

Base Commit: 0676afcfb7fb7781278c553d0c64972f5a0fefd9

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 92.96%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-core/src/entities/conformance.rs 🟢 19/19 100.00%
cedar-policy-core/src/validator/coreschema.rs 🔴 6/11 54.55% 272-276
cedar-policy-core/src/validator/schema.rs 🟢 41/41 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 81.91%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-policy 🔴 3245/4677 69.38% 69.38%
cedar-policy-cli 🔴 571/972 58.74% 58.74%
cedar-policy-core 🟢 21069/24807 84.93% 84.90%
cedar-policy-formatter 🟢 1074/1206 89.05% 89.05%
cedar-wasm 🔴 0/29 0.00% 0.00%

.iter()
.map(|action_def| action_def.entity_type().as_ref().as_ref().clone())
.collect();
for action_type in action_types {
Copy link
Contributor

@john-h-kastner-aws john-h-kastner-aws Jun 10, 2025

Choose a reason for hiding this comment

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

We could probably obtain the set of defined action types without iterating over all_defs.action_defs since there's only ever one action type defined per name space. Maybe that'd be a little more brittle than basing it off the actual actions, but it could save some time if there are a lot of actions in one namespace

@@ -844,6 +854,13 @@ impl ValidatorSchema {
undeclared_parent_actions: impl IntoIterator<Item = EntityUID>,
common_types: impl IntoIterator<Item = ValidatorType>,
) -> Result<()> {
// For the purposes of this function, the set of declared entity types
// includes the types of all declared actions.
let declared_entity_types: HashSet<&EntityType> = entity_types
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this possibly be pulled from all_defs since you updated that to include that action entity types already?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep; done this in the latest rev of this PR

Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
Copy link

Coverage Report

Head Commit: 9db942fa1575267fcc18c540577cdbf78e4d8ba2

Base Commit: 0676afcfb7fb7781278c553d0c64972f5a0fefd9

Download the full coverage report.

Coverage of Added or Modified Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 90.74%

Status: PASSED ✅

Details
File Status Covered Coverage Missed Lines
cedar-policy-core/src/entities/conformance.rs 🟢 19/19 100.00%
cedar-policy-core/src/validator/coreschema.rs 🔴 6/11 54.55% 272-276
cedar-policy-core/src/validator/schema.rs 🟢 24/24 100.00%

Coverage of All Lines of Rust Code

Required coverage: 80.00%

Actual coverage: 81.90%

Status: PASSED ✅

Details
Package Status Covered Coverage Base Coverage
cedar-policy 🔴 3245/4677 69.38% 69.38%
cedar-policy-cli 🔴 571/972 58.74% 58.74%
cedar-policy-core 🟢 21044/24782 84.92% 84.90%
cedar-policy-formatter 🟢 1074/1206 89.05% 89.05%
cedar-wasm 🔴 0/29 0.00% 0.00%

@cdisselkoen cdisselkoen merged commit b927a23 into main Jun 10, 2025
20 checks passed
@cdisselkoen cdisselkoen deleted the actions-in-attrs branch June 10, 2025 17:20
mishjude pushed a commit to mishjude/cedar that referenced this pull request Jun 17, 2025
cdisselkoen added a commit that referenced this pull request Jun 26, 2025
)

Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
cdisselkoen added a commit that referenced this pull request Jun 27, 2025
)

Signed-off-by: Craig Disselkoen <cdiss@amazon.com>
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.

Schema Validation for Storing Actions in Entities
3 participants