Skip to content

Andrewmwells/protobufs #1277

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

Merged
merged 45 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4f47ccd
Protobuffer representation of AST and (de-)serializers
Brandon-Rozek Jun 24, 2024
65a318c
Proto Namespace changes and converting using references
Brandon-Rozek Jun 28, 2024
2895b23
Merge branch 'main' into protobuffers
Brandon-Rozek Jun 28, 2024
7375c1c
Merge branch 'main' into protobuffers
Brandon-Rozek Jun 28, 2024
394a4cb
Refactored prost build call
Brandon-Rozek Jul 1, 2024
f3abb81
Reserve space in advance in glue code
Brandon-Rozek Jul 2, 2024
9aababe
Simplified expression message
Brandon-Rozek Aug 19, 2024
41edf03
Validation Protobuf Schema and Glue Code
Brandon-Rozek Aug 19, 2024
e7bfafb
Quick fix: Took out removed sum type from PatternElem
Brandon-Rozek Aug 19, 2024
6dd3c90
Schema file renames
Brandon-Rozek Aug 19, 2024
ebd15ae
Updated build to reflect proto schema name change
Brandon-Rozek Aug 19, 2024
2dbd127
Added glue code for ValidationMode
Brandon-Rozek Aug 19, 2024
23dcdd8
Cleaner protobuf type representation
Brandon-Rozek Aug 19, 2024
cdf6469
Another attempt at sum types
Brandon-Rozek Aug 20, 2024
80d3acd
Removed EntityLUB from schema
Brandon-Rozek Aug 20, 2024
7e3add1
Removed unknown entityuid from proto interface
Brandon-Rozek Aug 21, 2024
370a901
Sum type refactor
Brandon-Rozek Aug 21, 2024
0305693
Sum type refactor for ActionConstraint proto
Brandon-Rozek Aug 22, 2024
3eb06db
Sum type refactor for expressions
Brandon-Rozek Aug 26, 2024
ad6b740
Minor style changes
Brandon-Rozek Aug 26, 2024
748b274
[Minor] Changed record field number
Brandon-Rozek Aug 26, 2024
e55291c
Protobuffers behind feature flag
Brandon-Rozek Aug 26, 2024
4c1bcaf
Renumbering AST fields
Brandon-Rozek Aug 26, 2024
18af7dc
Formatting
Brandon-Rozek Aug 26, 2024
6eccf53
Fixed spacing
Brandon-Rozek Aug 26, 2024
7234b9d
Update to 4.0
Brandon-Rozek Aug 29, 2024
d590111
Removed stray comment
Brandon-Rozek Aug 29, 2024
776a7db
Merge branch 'main' into andrewmwells/protobufs
andrewmwells-amazon Oct 16, 2024
02ebfd4
Resolve merge conflicts
andrewmwells-amazon Oct 16, 2024
ba51d0f
Handle entity tags
andrewmwells-amazon Oct 16, 2024
1d01dda
cleanup
andrewmwells-amazon Oct 16, 2024
133674c
Add tests for forbid policies
andrewmwells-amazon Oct 18, 2024
d6be518
Address review comments
andrewmwells-amazon Oct 18, 2024
773a902
fix build when protobufs is enabled with partial-eval or partial-vali…
andrewmwells-amazon Oct 18, 2024
f74abab
fixes for clippy
andrewmwells-amazon Oct 19, 2024
fe32702
upgrade prost and fix clippy lints
andrewmwells-amazon Oct 21, 2024
772e68a
add protoc installation to CI
andrewmwells-amazon Oct 21, 2024
c758de7
add protoc installation to CI
andrewmwells-amazon Oct 21, 2024
d5b9ea1
add protoc installation to CI semver check
andrewmwells-amazon Oct 21, 2024
73d7bb5
update changelog
andrewmwells-amazon Oct 22, 2024
1890235
Add license to .proto files
andrewmwells-amazon Oct 22, 2024
e450548
Move protobuf schemas to protobuf_schema folders to avoid confusion w…
andrewmwells-amazon Oct 22, 2024
5de706e
More detail for changelog.
andrewmwells-amazon Oct 22, 2024
e35c341
More detail for changelog.
andrewmwells-amazon Oct 22, 2024
737feda
Address review comments
andrewmwells-amazon Oct 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cedar-policy-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ stacker = "0.1.15"
arbitrary = { version = "1", features = ["derive"], optional = true }
miette = { version = "7.1.0", features = ["serde"] }
nonempty = "0.10.0"
prost = "0.12"

# decimal extension requires regex
regex = { version = "1.8", features = ["unicode"], optional = true }
Expand All @@ -39,7 +40,7 @@ wasm-bindgen = { version = "0.2.82", optional = true }

[features]
# by default, enable all Cedar extensions
default = ["ipaddr", "decimal"]
default = ["ipaddr", "decimal", "protobufs"]
ipaddr = []
decimal = ["dep:regex"]

Expand All @@ -52,9 +53,11 @@ test-util = []
# Experimental features.
partial-eval = []
wasm = ["serde-wasm-bindgen", "tsify", "wasm-bindgen"]
protobufs = []

[build-dependencies]
lalrpop = "0.22.0"
prost-build = "0.5"

[dev-dependencies]
cool_asserts = "2.0"
Expand Down
9 changes: 9 additions & 0 deletions cedar-policy-core/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

fn main() {
generate_parsers();
#[cfg(feature = "protobufs")]
generate_schemas();
}

/// Reads parser grammar files (.lalrpop) and generates Rust modules
Expand All @@ -26,3 +28,10 @@ fn generate_parsers() {
.process_dir("src/parser/")
.expect("parser synth");
}

#[cfg(feature = "protobufs")]
/// Reads protobuf schema files (.proto) and generates Rust modules
fn generate_schemas() {
prost_build::compile_protos(&["./schema/AST.proto"], &["./schema"])
.expect("Prost protobuf compilation error;");
}
317 changes: 317 additions & 0 deletions cedar-policy-core/schema/AST.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,317 @@
syntax = "proto3";
package cedar_policy_core;

message Request {
EntityUidEntry principal = 1;
EntityUidEntry action = 2;
EntityUidEntry resource = 3;
Context context = 4;
}

message LiteralPolicySet {
// Key is PolicyID as a string
map<string, TemplateBody> templates = 1;
map<string, LiteralPolicy> links = 2;
}

enum Mode {
Concrete = 0;
Partial = 1;
}

message Entities {
repeated Entity entities = 1;
Mode mode = 2;
}

message Context {
Expr context = 1;
}

// BEGIN REQUEST MESSAGES

message EntityUidEntry {
EntityUid euid = 1;
Loc loc = 2;
}

message EntityUid {
EntityType ty = 1;
string eid = 2;
Loc loc = 3;
}

message EntityType {
Name name = 1;
}

// alias Id = string
message Name {
string id = 1;
repeated string path = 2;
Loc loc = 3;
}

message Loc {
uint32 offset = 1;
uint32 length = 2;
string src = 3;
}


// END REQUEST MESSAGES


// BEGIN POLICYSET MESSAGES

message LiteralPolicy {
string template_id = 1;
string link_id = 2;
bool link_id_specified = 3;
// map<SlotId, EntityUid> is not allowed since keys in map
// fields cannot be enum types
// map<SlotId, EntityUid> values = 4;
EntityUid principal_euid = 4;
EntityUid resource_euid = 5;
}

message Annotation {
string val = 1;
Loc loc = 2;
}

enum Effect {
Forbid = 0;
Permit = 1;
}

message TemplateBody {
string id = 1;
Loc loc = 2;
// alias AnyId = string
// alias Annotations = map<AnyId, Annotation>
map<string, Annotation> annotations = 3;
Effect effect = 4;
PrincipalConstraint principal_constraint = 5;
ActionConstraint action_constraint = 6;
ResourceConstraint resource_constraint = 7;
Expr non_scope_constraints = 8;
}

message PrincipalConstraint {
PrincipalOrResourceConstraint constraint = 1;
}

message ResourceConstraint {
PrincipalOrResourceConstraint constraint = 1;
}

message EntityReference {
oneof data {
Ty ty = 1;
EntityUid euid = 2;
}

// Zero-Arity constructors
enum Ty {
Slot = 0;
}
}

message PrincipalOrResourceConstraint {
oneof data {
Ty ty = 1;
InMessage in = 2;
EqMessage eq = 3;
IsMessage is = 4;
IsInMessage isIn = 5;
}

// Zero-arity constructors
enum Ty {
Any = 0;
}

message InMessage {
EntityReference er = 1;
}
message EqMessage {
EntityReference er = 1;
}
message IsMessage {
EntityType et = 1;
}
message IsInMessage {
EntityReference er = 1;
EntityType et = 2;
}
}

enum SlotId {
Principal = 0;
Resource = 1;
}

message ActionConstraint {
oneof data {
Ty ty = 1;
InMessage in = 2;
EqMessage eq = 3;
}

enum Ty {
Any = 0;
}
message InMessage {
repeated EntityUid euids = 1;
}
message EqMessage {
EntityUid euid = 1;
}
}

message Expr {
ExprKind expr_kind = 1;
Loc source_loc = 2;

message ExprKind {
oneof data {
Literal lit = 1;
Var var = 2;
SlotId slot = 3;
If if = 4;
And and = 5;
Or or = 6;
UnaryApp uApp = 7;
BinaryApp bApp = 8;
ExtensionFunctionApp extApp = 9;
GetAttr getAttr = 10;
HasAttr hasAttr = 11;
Like like = 12;
Is is = 13;
Set set = 14;
Record record = 15;
}
}
message Literal {
oneof lit {
bool b = 1;
int64 i = 2;
string s = 3;
EntityUid euid = 4;
}
}

enum Var {
Principal = 0;
Action = 1;
Resource = 2;
CONTEXT = 3;
}

message If {
Expr test_expr = 1;
Expr then_expr = 2;
Expr else_expr = 3;
}

message And {
Expr left = 1;
Expr right = 2;
}

message Or {
Expr left = 1;
Expr right = 2;
}

message UnaryApp {
Op op = 1;
Expr expr = 2;

enum Op {
Not = 0;
Neg = 1;
}
}

message BinaryApp {
Op op = 1;
Expr left = 2;
Expr right = 3;

enum Op {
Eq = 0;
Less = 1;
LessEq = 2;
Add = 3;
Sub = 4;
Mul = 5;
In = 6;
Contains = 7;
ContainsAll = 8;
ContainsAny = 9;
GetTag = 10;
HasTag = 11;
}
}

message ExtensionFunctionApp {
Name fn_name = 1;
repeated Expr args = 2;
}

message GetAttr {
Expr expr = 1;
string attr = 2;
}

message HasAttr {
Expr expr = 1;
string attr = 2;
}

message Like {
Expr expr = 1;
repeated PatternElem pattern = 2;

message PatternElem {
oneof data {
Ty ty = 1;
string c = 2;
}

// Zero-arity constructors
enum Ty {
Wildcard = 0;
}
}
}

message Is {
Expr expr = 1;
EntityType entity_type = 2;
}

message Set {
repeated Expr elements = 1;
}

message Record {
map<string, Expr> items = 1;
}
}

// END POLICYSET MESSAGES


// ENTER ENTITITES MESSAGES

message Entity {
EntityUid uid = 1;
map<string, Expr> attrs = 2;
repeated EntityUid ancestors = 3;
map<string, Expr> tags = 4;
}

// END ENTITITES MESSAGES
6 changes: 6 additions & 0 deletions cedar-policy-core/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@

//! This module contains the AST datatypes.

#[cfg(feature = "protobufs")]
pub mod proto {
#![allow(missing_docs)]
include!(concat!(env!("OUT_DIR"), "/cedar_policy_core.rs"));
}

mod expr;
pub use expr::*;
mod entity;
Expand Down
Loading
Loading