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

Expose protobufs in public API #1345

Merged
merged 4 commits into from
Dec 2, 2024
Merged

Conversation

cdisselkoen
Copy link
Contributor

Description of changes

To date, the protobuf serialization/deserialization experimental feature is only available to direct consumers of cedar-policy-core and cedar-policy-validator, and callers are required to manually call from() / into() to convert into the appropriate struct in cedar_policy_core::ast::proto or cedar_policy_validator::proto.

This PR introduces a new Protobuf trait, exposed in our public API (guarded by the protobufs feature flag, of course), which allows consumers of the public API to serialize/deserialize various public-API types like Policy and Schema using protobufs. All necessary conversions are performed under-the-hood, and the types in the proto modules are not exposed publicly.

Issue #, if available

Checklist for requesting a review

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

  • A change (breaking or otherwise) that only impacts unreleased or experimental code.

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

  • Does not update the CHANGELOG because my change does not significantly impact released code.

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 <[email protected]>
@@ -1927,6 +2016,11 @@ impl PolicySet {
})
}

/// Build the [`PolicySet`] from just the AST information
pub fn from_ast(ast: ast::PolicySet) -> Result<Self, PolicySetError> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be pub?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, it shouldn't be

@@ -102,8 +102,8 @@ message EntityRecordKind {
}

enum OpenTag {
OpenAttributes = 0;
ClosedAttributes = 1;
OpenAttributes = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

A general note about the protobuf impl. Does this mean that OpenAttributes on records in the schema would become a publicly accessible feature when we stabilize protobuf? What other internal details might be exposed this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Interesting question.

Protobuf is not self-describing. In this PR, public-API users only see a blob of bytes, and if one of those bits indicates open-attributes vs closed-attributes, they would never know. But if anyone actually relies on our .proto files to encode/decode themselves, then yes, they see these attributes.

I believe the Lean protobuf parser errors if it sees OpenAttributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Arguably if we want to stabilize protobufs before OpenAttributes, we should remove OpenAttributes from the protobuf format.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'd agree with that. And also

Signed-off-by: Craig Disselkoen <[email protected]>
@cdisselkoen cdisselkoen merged commit 6144d8f into main Dec 2, 2024
19 checks passed
@cdisselkoen cdisselkoen deleted the cdisselkoen/proto-in-public-api branch December 2, 2024 18:34
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