Skip to content

Commit b7698ba

Browse files
authored
add proofs for implies?, equivalent?, disjoint?, alwaysAllows?, and alwaysDenies? (#796)
Signed-off-by: Craig Disselkoen <[email protected]>
1 parent 9af9455 commit b7698ba

File tree

11 files changed

+557
-26
lines changed

11 files changed

+557
-26
lines changed

cedar-lean/Cedar/Spec/Policy.lean

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,16 @@ def Scope.bound : Scope → Option EntityUID
136136
| .isMem _ uid => .some uid
137137
| _ => .none
138138

139+
/-- The trivial allow-all policy -/
140+
def Policy.allowAll : Policy := {
141+
id := "allowAll",
142+
effect := .permit,
143+
principalScope := .principalScope .any,
144+
actionScope := .actionScope .any,
145+
resourceScope := .resourceScope .any,
146+
condition := []
147+
}
148+
139149
----- Derivations -----
140150

141151
deriving instance Repr, DecidableEq, Inhabited for Effect

cedar-lean/Cedar/SymCC/Enforcer.lean

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ where
130130
Returns the ground acyclicity and transitivity assumptions for xs and env.
131131
-/
132132
def enforce (xs : List Expr) (εnv : SymEnv) : Set Term :=
133-
let (Set.mk ts) := footprints xs εnv
134-
let ac := ts.map (acyclicity · εnv.entities)
135-
let tr := ts.mapUnion (λ t => ts.map (transitivity t · εnv.entities))
133+
let ts := footprints xs εnv
134+
let ac := ts.elts.map (acyclicity · εnv.entities)
135+
let tr := ts.elts.mapUnion (λ t => ts.elts.map (transitivity t · εnv.entities))
136136
Set.make (ac ∪ tr)
137137

138138
namespace Cedar.SymCC

cedar-lean/Cedar/SymCC/Verifier.lean

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,24 @@ Returns asserts that are unsatisfiable iff `ps` allows all inputs in `εnv`.
7575
def verifyAlwaysAllows (ps : Policies) (εnv : SymEnv) : Result Asserts := do
7676
verifyImplies [allowAll] ps εnv
7777
where
78+
-- This policy chosen not because it's readable or optimized, but because it
79+
-- is the policy produced by `wellTypedPolicy Policy.allowAll Γ`
7880
allowAll : Policy := {
7981
id := "allowAll",
8082
effect := .permit,
8183
principalScope := .principalScope .any,
8284
actionScope := .actionScope .any,
8385
resourceScope := .resourceScope .any,
84-
condition := []
86+
condition := [{
87+
kind := .when,
88+
body := Expr.and
89+
(.lit (.bool true))
90+
(Expr.and
91+
(.lit (.bool true))
92+
(Expr.and
93+
(.lit (.bool true))
94+
(.lit (.bool true))))
95+
}]
8596
}
8697

8798
/--

cedar-lean/Cedar/SymCCOpt/CompiledPolicies.lean

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,11 @@ A `CompiledPolicies` that represents the policyset that allows all requests in
101101
the `εnv`.
102102
-/
103103
def CompiledPolicies.allowAll (εnv : SymEnv) : CompiledPolicies :=
104-
let allowAll : Policy := {
105-
id := "allowAll",
106-
effect := .permit,
107-
principalScope := .principalScope .any,
108-
actionScope := .actionScope .any,
109-
resourceScope := .resourceScope .any,
110-
condition := [],
111-
}
112-
let footprint := SymCC.footprint allowAll.toExpr εnv
104+
let footprint := SymCC.footprint verifyAlwaysAllows.allowAll.toExpr εnv
113105
{
114106
term := .bool true
115107
εnv
116-
policies := [allowAll]
108+
policies := [verifyAlwaysAllows.allowAll]
117109
footprint
118110
acyclicity := footprint.map (SymCC.acyclicity · εnv.entities)
119111
}

cedar-lean/Cedar/Thm/Data/MapUnion.lean

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,37 @@ theorem mapUnion_wf {α β} [LT α] [StrictLT α] [DecidableLT α] {f : β → S
9292
simp only [List.foldl_cons]
9393
exact ih _ (Set.union_wf _ _)
9494

95+
theorem mapUnion_empty {α β} [LT α] [StrictLT α] [DecidableLT α] {f : β → Set α} :
96+
[].mapUnion f = ∅
97+
:= by
98+
simp only [List.mapUnion, EmptyCollection.emptyCollection, List.foldl_nil]
99+
100+
private theorem foldl_union_init {α β} [LT α] [StrictLT α] [DecidableLT α] {f : β → Set α} {xs : List β} {a b : Set α} :
101+
List.foldl (λ acc x => acc ∪ f x) (a ∪ b) xs = a ∪ List.foldl (λ acc x => acc ∪ f x) b xs
102+
:= by
103+
induction xs generalizing a b
104+
case nil =>
105+
simp only [List.foldl_nil]
106+
case cons hd tl ih =>
107+
simp only [List.foldl_cons]
108+
rw [Set.union_assoc]
109+
rw [ih (a := a) (b := b ∪ f hd)]
110+
111+
theorem mapUnion_cons {α β} [LT α] [StrictLT α] [DecidableLT α] {f : β → Set α} {hd : β} {tl : List β} :
112+
(∀ b, (f b).WellFormed) →
113+
(hd :: tl).mapUnion f = f hd ∪ tl.mapUnion f
114+
:= by
115+
intro hwf
116+
simp only [List.mapUnion, EmptyCollection.emptyCollection, List.foldl_cons]
117+
rw [Set.union_empty_left (hwf hd)]
118+
rw [← Set.union_empty_left (hwf hd)]
119+
rw [foldl_union_init (a := Set.empty) (b := f hd)]
120+
rw [← foldl_union_init (a := Set.empty ∪ f hd) (b := Set.empty)]
121+
have h : Set.empty ∪ f hd ∪ Set.empty = Set.empty ∪ f hd := by
122+
rw [Set.union_empty_right (Set.union_wf _ _)]
123+
rw [h]
124+
rw [foldl_union_init (a := Set.empty) (b := f hd)]
125+
95126
private theorem mem_foldl_union_iff_mem_or_exists {α β} [LT α] [StrictLT α] [DecidableLT α] {f : β → Set α} {xs : List β} {init : Set α} {a : α} :
96127
a ∈ List.foldl (λ as b => as ∪ f b) init xs ↔ (a ∈ init ∨ ∃ s ∈ xs, a ∈ f s)
97128
:= by
@@ -192,6 +223,35 @@ theorem mapUnion_eq_mapUnion_id_map {α β} [LT α] [StrictLT α] [DecidableLT
192223
simp only [List.foldl_cons, id_eq, List.map_cons]
193224
apply ih
194225

226+
private theorem foldl_union_append {α β} [LT α] [StrictLT α] [DecidableLT α] [DecidableEq α] {g : β → Set α} {xs ys : List β} {a : Set α} :
227+
List.foldl (λ acc b => acc ∪ g b) a (xs.append ys) = List.foldl (λ acc b => acc ∪ g b) (List.foldl (λ acc b => acc ∪ g b) a xs) ys
228+
:= by
229+
induction xs generalizing a
230+
case nil =>
231+
simp only [List.foldl_nil]
232+
rfl
233+
case cons xhd xtl ih =>
234+
simp only [List.append, List.foldl_cons]
235+
rw [ih]
236+
237+
theorem mapUnion_append {α β} [LT α] [StrictLT α] [DecidableLT α] {f : β → Set α} {xs ys : List β} :
238+
(∀ b, (f b).WellFormed) →
239+
(xs ++ ys).mapUnion f = xs.mapUnion f ++ ys.mapUnion f
240+
:= by
241+
intro hwf
242+
induction xs
243+
case nil =>
244+
simp only [List.nil_append, mapUnion_empty]
245+
change _ = Set.empty ∪ ys.mapUnion f
246+
rw [Set.union_empty_left]
247+
exact mapUnion_wf
248+
case cons hd tl ih =>
249+
simp only [List.cons_append]
250+
rw [mapUnion_cons hwf, mapUnion_cons hwf, ih]
251+
change _ ∪ (_ ∪ _) = (_ ∪ _) ∪ _
252+
symm
253+
apply Set.union_assoc
254+
195255
private theorem foldl_union_swap_front {α} [LT α] [StrictLT α] [DecidableLT α] [DecidableEq α] (x₁ x₂ : Set α) {xs : List (Set α)} {a : Set α}:
196256
(x₁ :: x₂ :: xs).foldl (· ∪ ·) a = (x₂ :: x₁ :: xs).foldl (· ∪ ·) a
197257
:= by

cedar-lean/Cedar/Thm/SymCC/Enforcer/Footprint.lean

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
-/
1616

1717
import Cedar.SymCC.Enforcer
18+
import Cedar.Thm.Data.LT
1819
import Cedar.Thm.Data.MapUnion
1920
import Cedar.Thm.SymCC.Env.SWF
2021
import Cedar.Thm.SymCC.Enforcer.Asserts
@@ -28,6 +29,29 @@ namespace Cedar.SymCC
2829

2930
open Data Spec SymCC Factory
3031

32+
def footprint_ofEntity_wf :
33+
(footprint.ofEntity x εnv).WellFormed
34+
:= by
35+
simp [footprint.ofEntity]
36+
split
37+
· split <;> simp [Set.singleton_wf, Set.empty_wf]
38+
· exact Set.empty_wf
39+
40+
def footprint_ofBranch_wf :
41+
ft₂.WellFormed →
42+
ft₃.WellFormed →
43+
(footprint.ofBranch εnv x ft₁ ft₂ ft₃).WellFormed
44+
:= by
45+
intro h₂ h₃
46+
simp [footprint.ofBranch]
47+
split <;> simp [h₂, h₃, Set.empty_wf, Set.union_wf]
48+
49+
def footprint_wf (x : Expr) (εnv : SymEnv) :
50+
(footprint x εnv).WellFormed
51+
:= by
52+
cases x
53+
all_goals simp [footprint, footprint_ofEntity_wf, footprint_ofBranch_wf, footprint_wf, Set.empty_wf, Set.mapUnion_wf, Set.union_wf]
54+
3155
def SymEntities.SameOn (εs : SymEntities) (ft : Set Term) (I₁ I₂ : Interpretation) : Prop :=
3256
∀ ety δ,
3357
εs.find? ety = some δ →
@@ -274,6 +298,24 @@ theorem mem_footprints_wf {xs : List Expr} {t : Term} {εnv : SymEnv}
274298
replace ⟨x, hinₓ, hin⟩ := hin
275299
exact mem_footprint_wf (And.intro hwε (hvr x hinₓ)) hin
276300

301+
theorem footprints_empty {εnv : SymEnv} :
302+
footprints [] εnv = ∅
303+
:= by
304+
simp [footprints, Set.mapUnion_empty]
305+
306+
theorem footprints_singleton {x : Expr} {εnv : SymEnv} :
307+
footprints [x] εnv = footprint x εnv
308+
:= by
309+
simp [SymCC.footprints, List.mapUnion, EmptyCollection.emptyCollection]
310+
rw [Data.Set.union_empty_left (footprint_wf x εnv)]
311+
312+
theorem footprints_append {xs₁ xs₂ : List Expr} {εnv : SymEnv} :
313+
footprints (xs₁ ++ xs₂) εnv = footprints xs₁ εnv ++ footprints xs₂ εnv
314+
:= by
315+
simp [footprints]
316+
apply Data.Set.mapUnion_append
317+
intro x ; apply footprint_wf
318+
277319
theorem footprint_subset_footprints {x : Expr} {xs : List Expr} {εnv : SymEnv} :
278320
x ∈ xs → footprint x εnv ⊆ footprints xs εnv
279321
:= by

0 commit comments

Comments
 (0)