@@ -39,7 +39,11 @@ def instanceOfBoolType (b : Bool) (bty : BoolType) : Bool :=
3939 | _, .anyBool => true
4040 | _, _ => false
4141
42- def instanceOfEntityType (e : EntityUID) (ety : EntityType ) : Bool := ety == e.ty
42+ def instanceOfEntityType (e : EntityUID) (ety : EntityType ) (eids: EntityType → Option (Set String)) : Bool :=
43+ ety == e.ty &&
44+ match eids ety with
45+ | .some eids => eids.contains e.eid
46+ | _ => true
4347
4448def instanceOfExtType (ext : Ext) (extty: ExtType) : Bool :=
4549match ext, extty with
@@ -52,17 +56,17 @@ match rty.find? k with
5256 | .some qty => if qty.isRequired then r.contains k else true
5357 | _ => true
5458
55- def instanceOfType (v : Value) (ty : CedarType) : Bool :=
59+ def instanceOfType (v : Value) (ty : CedarType) (schema: EntitySchema) : Bool :=
5660 match v, ty with
5761 | .prim (.bool b), .bool bty => instanceOfBoolType b bty
5862 | .prim (.int _), .int => true
5963 | .prim (.string _), .string => true
60- | .prim (.entityUID e), .entity ety => instanceOfEntityType e ety
61- | .set s, .set ty => s.elts.attach.all (λ ⟨v, _⟩ => instanceOfType v ty)
64+ | .prim (.entityUID e), .entity ety => instanceOfEntityType e ety schema.entityTypeMembers?
65+ | .set s, .set ty => s.elts.attach.all (λ ⟨v, _⟩ => instanceOfType v ty schema )
6266 | .record r, .record rty =>
6367 r.kvs.all (λ (k, _) => rty.contains k) &&
6468 (r.kvs.attach₂.all (λ ⟨(k, v), _⟩ => (match rty.find? k with
65- | .some qty => instanceOfType v qty.getType
69+ | .some qty => instanceOfType v qty.getType schema
6670 | _ => true ))) &&
6771 rty.kvs.all (λ (k, _) => requiredAttributePresent r rty k)
6872 | .ext x, .ext xty => instanceOfExtType x xty
@@ -79,11 +83,11 @@ def instanceOfType (v : Value) (ty : CedarType) : Bool :=
7983 simp only [Map.mk.sizeOf_spec]
8084 omega
8185
82- def instanceOfRequestType (request : Request) (reqty : RequestType) : Bool :=
83- instanceOfEntityType request.principal reqty.principal &&
86+ def instanceOfRequestType (request : Request) (reqty : RequestType) (schema: EntitySchema) : Bool :=
87+ instanceOfEntityType request.principal reqty.principal schema.entityTypeMembers? &&
8488 request.action == reqty.action &&
85- instanceOfEntityType request.resource reqty.resource &&
86- instanceOfType request.context (.record reqty.context)
89+ instanceOfEntityType request.resource reqty.resource schema.entityTypeMembers? &&
90+ instanceOfType request.context (.record reqty.context) schema
8791
8892/--
8993For every entity in the store,
@@ -97,14 +101,16 @@ def instanceOfEntitySchema (entities : Entities) (ets : EntitySchema) : EntityVa
97101 entities.toList.forM λ (uid, data) => instanceOfEntityData uid data
98102where
99103 instanceOfEntityTags (data : EntityData) (entry : EntitySchemaEntry) : Bool :=
100- match entry.tags with
101- | .some tty => data.tags.values.all (instanceOfType · tty)
104+ match entry.tags? with
105+ | .some tty => data.tags.values.all (instanceOfType · tty ets )
102106 | .none => data.tags == Map.empty
103107 instanceOfEntityData uid data :=
104108 match ets.find? uid.ty with
105109 | .some entry =>
106- if instanceOfType data.attrs (.record entry.attrs) then
107- if data.ancestors.all (λ ancestor => entry.ancestors.contains ancestor.ty) then
110+ if instanceOfType data.attrs (.record entry.attrs) ets then
111+ if data.ancestors.all (λ ancestor =>
112+ entry.ancestors.contains ancestor.ty &&
113+ instanceOfEntityType ancestor ancestor.ty ets.entityTypeMembers?) then
108114 if instanceOfEntityTags data entry then .ok ()
109115 else .error (.typeError s! "entity tags inconsistent with type store" )
110116 else .error (.typeError s! "entity ancestors inconsistent with type store" )
@@ -125,10 +131,10 @@ where
125131 else .error (.typeError "action ancestors inconsistent with type store information" )
126132 | _ => .error (.typeError s! "action type { uid.eid} not defined in type store" )
127133
128- def requestMatchesEnvironment (env : Environment) (request : Request) : Bool := instanceOfRequestType request env.reqty
134+ def requestMatchesEnvironment (env : Environment) (request : Request) (schema : EntitySchema): Bool := instanceOfRequestType request env.reqty schema
129135
130136def validateRequest (schema : Schema) (request : Request) : RequestValidationResult :=
131- if ((schema.toEnvironments.any (requestMatchesEnvironment · request)))
137+ if ((schema.toEnvironments.any (requestMatchesEnvironment · request schema.ets )))
132138 then .ok ()
133139 else .error (.typeError "request could not be validated in any environment" )
134140
@@ -158,7 +164,7 @@ def updateSchema (schema : Schema) (actionSchemaEntities : Entities) : Schema :=
158164 let entriesWithType := actionSchemaEntities.filter (λ k _ => k.ty == ty)
159165 let allAncestorsForType := List.flatten (entriesWithType.values.map (λ edt =>
160166 edt.ancestors.elts.map (·.ty) ))
161- let ese : EntitySchemaEntry := {
167+ let ese : EntitySchemaEntry := .standard {
162168 ancestors := Set.make allAncestorsForType,
163169 attrs := Map.empty,
164170 tags := Option.none
0 commit comments