✓ Human-authored analysis; AI used for formatting and proofreading.
Cloud security tools have a dangerous failure mode: silent passes. When a tool can't read a field, or a predicate skips a null check, it reports "no finding". This tells the customer their infrastructure is secure when the tool simply didn't evaluate the configuration. The customer never knows. The misconfiguration stays live.
Stave addresses this with a shadow verification architecture borrowed from AWS Cedar's approach to authorization policy verification. A formal model in Lean 4 runs alongside the production Go/CEL engine. Same inputs, both evaluators, every disagreement is a bug. They are caught in development, not in a customer's account.
The Problem with Testing Alone
Consider a KMS control that checks whether key rotation is enabled. The Go/CEL predicate reads properties.cryptography.key_rotation_enabled and fires a finding when it's false. Straightforward. But what happens when the field is absent?
In Go, an absent field might be a nil pointer, a zero value, or an empty interface depending on how the observation was deserialized. In CEL, it's a null check the author might not write. If nobody writes a test for the absent-field case, the predicate silently returns "pass" and the customer sees a clean bill of health on a key whose rotation status is unknown.
You could catch this with thorough test coverage. But "thorough" means testing every combination of present and absent fields for every control. For a control that reads three fields, each of which can be present-true, present-false, or absent, that's 27 test cases for one control. For 51 KMS controls, the combinatorial space exceeds what manual test authoring covers in practice.
The Shadow Evaluator
Stave maintains two implementations of every control:
Production: Go code evaluating CEL predicates against observation documents. This is what runs in customer environments. It's optimized for performance, integrates with the observation pipeline, and handles the full complexity of real-world AWS API responses.
Shadow: Lean 4 functions evaluating the same logic against the same observation types. This is the formal model. It never runs in production. It exists to catch bugs in the production evaluator.
The two implementations are written independently. The Lean evaluator is coded directly from the control's YAML specification, not from the Go code. This independence is what makes disagreements meaningful. If both implementations have the same bug, it would have to be a bug in the specification itself, not an implementation error.
How Disagreements Surface
The mechanism is differential testing. For each control, Stave maintains fixture documents. JSON snapshots of real AWS resource configurations with known expected verdicts. The test harness runs both evaluators on every fixture:
Fixture: KMS key with rotation disabled
Go/CEL evaluator → VIOLATION (finding fires)
Lean evaluator → VIOLATION (finding fires)
Result: MATCH ✓
Fixture: KMS key with rotation field absent
Go/CEL evaluator → PASS (no finding)
Lean evaluator → VIOLATION (finding fires)
Result: DISAGREEMENT — bug in Go/CEL evaluator
The second case is the silent pass. The CEL predicate didn't check for a missing field, so it defaulted to "no finding." The Lean evaluator, whose type system forces every field to be Option and whose compiler rejects any function that doesn't handle none, correctly identified the missing field and fired the finding.
The disagreement is a bug report. The Go/CEL evaluator needs a null check. The Lean model is authoritative during development, if the two disagree, the Lean model is correct and the Go/CEL code is fixed.
What the Type System Catches at Compile Time
The Lean side doesn't rely solely on tests. Its type system prevents several categories of bugs from being expressible in the first place.
Missing-field handling is mandatory
Every observation field is typed as Option:
structure KMSKey where
kind : Option String
key_rotation_enabled : Option Bool
is_disabled : Option Bool
dependent_resource_count : Option Nat
A control evaluator must pattern-match on the Option:
def evalKMSRotation (obs : KMSKey) : Finding :=
match obs.kind with
| some "key" =>
match obs.key_rotation_enabled with
| some true => Finding.pass
| some false => Finding.fail "CTL.KMS.ROTATION.001"
"key rotation not enabled"
| none => Finding.fail "CTL.KMS.ROTATION.001"
"key rotation status unknown"
| _ => Finding.fail "CTL.KMS.ROTATION.001" "not a KMS key"
The compiler rejects any version of this function that doesn't handle none. You cannot write a Lean evaluator that silently passes on a missing field. The none arm must exist, and it must return a Finding. The type forces you to decide what "missing" means. In Stave, it always means the finding fires.
The observation type is the verification boundary
The Lean structure contains only the fields that the control predicates actually read. For KMS controls, the KMSKey structure includes key_rotation_enabled, is_disabled, and dependent_resource_count because KMS controls read those fields. It does not include tags, description, or creation_date because no KMS control reads those fields.
This is the cone of influence, enforced structurally. A Lean evaluator that takes KMSKey literally cannot access a field that isn't in the type. You can't accidentally widen the verification surface by reading a field that's "right there" on the AWS object, because it isn't there in the Lean type.
When a new control needs a new field, the field is added to the structure, FromJson parsing is updated, and the differential test catches any mismatch. The type change shows up in the diff. It's reviewable and intentional.
Invalid states are unrepresentable
A control evaluation produces a Finding:
inductive Finding where
| pass : Finding
| fail : (controlId : String) → (message : String) → Finding
There is no third option. No null finding, no "error" finding that gets swallowed, no string return value that a caller has to parse. Every function that returns Finding must construct one of these two variants. The type closes the universe of possible results.
The Fail-Closed Theorem
Beyond what the type system prevents at compile time, Stave proves a property that holds across all inputs not just the tested ones:
theorem kms_fail_closed (obs : KMSKey) (controlId : String)
(h : ¬canEvaluateKMS obs controlId) :
(evaluateKMS controlId obs).fires = true
If the evaluator cannot evaluate a control against an observation. Because the asset type is wrong, a required field is missing, or the control ID is unknown. The evaluator is mathematically guaranteed to fire a finding rather than silently pass.
This is the fail-closed property, and it holds for every possible input. Not just the fixtures in the test suite. Not just the AWS configurations that exist today. Every possible combination of present and absent fields, for every control, in every edge case. If the evaluator can't do its job, it says so by firing a finding.
The proof is machine-checked. It cannot be invalidated by a code change. If someone modifies the evaluator in a way that breaks the fail-closed property, the proof stops compiling and the build fails.
Three Bug Categories This Catches
1. Missing-field silent passes
The most dangerous category. A CEL predicate that doesn't check for null silently passes when a field is absent. The customer sees "no finding" and believes their key is correctly configured. The Lean evaluator catches this at compile time (the type system requires handling none) and at test time (the differential test reveals the disagreement).
2. Predicate logic errors
A control that checks >= when it should check >. A compound predicate that uses OR when the YAML specification says AND. An equality check against the wrong string value. These produce wrong verdicts on specific inputs, and they're hard to catch with unit tests because the test author usually has the same mental model as the code author.
The Lean evaluator is written independently from the YAML specification. If the Go/CEL code has a logic error, the Lean evaluator (written from the same spec but implemented independently) is likely to get it right, and the disagreement surfaces the bug.
3. Observation type drift
When a developer adds a field to the Go observation struct and updates some controls but not others. When a field name changes in the API response but the CEL predicate still references the old name. When a FromJson parser is updated for one observation type but not the corresponding Lean parser.
The Lean FromJson instance fails on fixtures that exercise the drifted field. The parse failure is itself a test signal. It means the formal model no longer matches what the production system produces. Unlike a wrong verdict that might slip through testing, a parse failure is loud and unambiguous.
What This Architecture Does Not Do
The shadow evaluator does not run in customer environments. Customers interact only with the Go/CEL engine. The Lean model is a development-time artifact that catches bugs before release.
The shadow evaluator does not catch specification errors. If the YAML specification itself is wrong, the control checks the wrong field, or the business logic is incorrect, both evaluators will implement the wrong logic correctly. Specification correctness is a different problem, addressed by the YAML review process and compliance mapping.
The shadow evaluator does not catch performance bugs. A Go/CEL evaluator that produces correct results but takes 30 seconds per control has no Lean-detectable defect. Performance is tested separately.
The Cedar Precedent
The authorization policy engine used by Amazon Verified Permissions, maintains a Lean 4 formal model alongside its production Rust implementation. Cedar's approach is the same: two independent implementations of the same specification, differential testing to surface disagreements, formal proofs to establish properties that hold across all inputs.
Cedar's results are documented in their published papers. They found real bugs in the Rust implementation through differential testing against the Lean model bugs that their existing test suites had not caught.
Stave adapts the Cedar pattern for cloud security controls rather than authorization policies. The domain is different but the architecture is the same: independent implementations, differential testing, formal proofs for cross-cutting properties, and a type system that prevents structural bugs from being expressible.
What Customers Get
Customers don't see any of this machinery. They see a Go/CEL evaluator that produces correct verdicts for their KMS key configurations. What they're getting is a Go/CEL evaluator that has been tested against an independent formal model, whose fail-closed property has been machine-verified, and whose observation types have been audited against the fields the predicates read.
The shadow evaluator is invisible. Its value shows up as the bugs that don't ship.
Top comments (0)