Skip to content

feat(tpe): add type-aware partial evaluation entity model and validation - #370

Merged
muditchaudhary merged 2 commits into
cedar-policy:mainfrom
muditchaudhary:tpe-step1-foundation
Sep 21, 2026
Merged

muditchaudhary merged 2 commits into
cedar-policy:mainfrom
muditchaudhary:tpe-step1-foundation

Conversation

@muditchaudhary

Copy link
Copy Markdown
Contributor

Summary

Adds the entity model for Cedar's type-aware partial evaluation (TPE) to CedarJava: entities whose attributes, parents, and tags may each be independently unknown. Everything is @Experimental and purely additive — no existing API changes.

This is the entity half of the foundation. The TPE request/response types and the authorization call itself follow in a separate PR.

What

CedarJava

  • PartialEntity — EUID always known; attrs, parents, and tags each either absent (unknown) or present and complete.
  • PartialEntities — the collection, carrying the two checks that only make sense over the whole set: no duplicate UIDs, and no in-collection parent whose own parents are unknown.
  • PartialEntityUID — partial counterpart to EntityUID, reusing EntityTypeName and EntityIdentifier. The type is always known, since TPE needs it to type check a request.
  • Constructors take a Schema and validate eagerly, so a value in hand has already been checked.

CedarJavaFFI

  • New tpe Cargo feature and src/tpe.rs with two validators, accepting a schema in either Cedar or JSON format.

Why

TPE evaluates policies against incomplete data, which needs a way to say "this entity exists but I don't know its attributes" — distinct from "I don't know whether this entity exists at all," which is expressed by leaving it out of the collection.

Validation happens at construction rather than at authorize time so that a bad entity fails where the mistake was made, with a message naming the offending attribute, instead of surfacing later as an opaque error from a call that looks unrelated.

Issue: #364

Introduces the entity-side foundation for Cedar's type-aware partial
evaluation (TPE), where an entity's attributes, parents, and tags may
each be independently unknown.

Signed-off-by: Mudit Chaudhary <chmudit@amazon.com>
@muditchaudhary
muditchaudhary marked this pull request as ready for review September 16, 2026 22:55
Comment thread CedarJava/src/test/java/com/cedarpolicy/PartialEntitiesTests.java
Comment thread CedarJava/src/main/java/com/cedarpolicy/model/entity/PartialEntities.java Outdated
Comment thread CedarJava/src/test/java/com/cedarpolicy/PartialEntitiesTests.java
Signed-off-by: Mudit Chaudhary <chmudit@amazon.com>
Comment on lines +76 to +77
* @throws MissingExperimentalFeatureException If the native library was built without the {@code tpe} feature.
* @throws NullPointerException If the schema is null.

@mark-creamer-amazon mark-creamer-amazon Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are these applicable any more?

Same with below

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Still applicable. validate(...) uses Objects.requireNonNull(schema, ...) which can throw NullPointerException and ends by routing any native error to MissingExperimentalFeatureException. MissingExperimentalFeatureException is a subclass of InternalException.

/** Tests for {@link PartialEntities}, a collection of partially known entities. */
public class PartialEntitiesTests {
/** See {@link PartialEntityTests} for what this schema is shaped to catch. */
private static final Schema TPE_SCHEMA = TestUtil.loadSchemaResource("/tpe_schema.json");

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe this matches the existing pattern, but should this be TPE_SCHEMA_JSON?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it matches the existing pattern in other test suites where we use *_SCHEMA for JSON schemas as *_SCHEMA_CEDAR for Cedar schemas

Comment thread CedarJavaFFI/src/tests.rs
"#;

fn schema_json() -> String {
json!(SCHEMA).to_string()

@mark-creamer-amazon mark-creamer-amazon Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Could be worth being consistent with interface.rs above which uses serde_json::json!(SCHEMA).to_string(). Or perhaps the SCHEMA could be shared in both

* rules that span the collection. In practice that means {@link PartialEntities}, on both the JSON and the concrete
* path.
*/
PartialEntity(EntityUID euid, Optional<Map<String, Value>> attrs, Optional<Set<EntityUID>> parents,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: should we add the explicit public here?

@muditchaudhary muditchaudhary Sep 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I deliberately did not make it public here as it is used to create non-Schema validated PartialEntity which should not happen (for consumers). This method exists merely to be used by PartialEntities constructors to avoid duplicate validations. So, keeping it package-private

@muditchaudhary
muditchaudhary merged commit 845bb37 into cedar-policy:main Sep 21, 2026
4 checks passed
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