soma.cell

Image promotion — nothing unscanned, unsigned, or vulnerable ships

The SolarWinds breach (disclosed December 2020) worked because the build pipeline itself was the attack surface: malicious code was injected during the build, then SIGNED and shipped to ~18,000 organizations as a legitimate update. Defense afterward converged on one idea — provenance gates: an artifact reaches production only by passing every gate, in order, with no side door. This registry encodes the gates as topology: built -> scanned -> signed -> promoted, and `soma verify` proves there is no edge that skips a gate. An image whose scan finds critical CVEs lands in `quarantined` — TERMINAL, because you rebuild from a patched base, you never "un-quarantine". The promoted registry's CVE ledger has a memory invariant pinned at zero: recording a critical vulnerability against a production image is a write the memory itself refuses.

A Soma program from the devops part of the verified corpus: 105 lines, cells ImageRegistry, ProvenanceTests. It passes soma check with soma 3.2.4.

How it is built

The cell ImageRegistry declares 5 signals in its face: scan_pass(img: String) -> Map, scan_quarantine(img: String) -> Map, sign_image(img: String) -> Map, promote_to_prod(img: String) -> Map and image_state(img: String) -> String; keeps 1 memory slot: prod_critical_cves (Map<String, Int>, persistent and consistent) under the invariant prod_critical_cves >= 0 && prod_critical_cves <= 0. Its state machine image starts in built and allows 5 transitions: built -> scanned, scanned -> signed, signed -> promoted, built -> quarantined and scanned -> quarantined. promoted and quarantined are terminal. Handlers: scan_pass (line 49), scan_quarantine (line 55), sign_image (line 61), promote_to_prod (line 67) and image_state (line 74).

The file also holds 1 test cell (ProvenanceTests) with 13 assertions, run by soma test.

Generated from soma describe on this file.

The source

image_promotion.cell

// ============================================================================
// IMAGE PROMOTION — nothing unscanned, unsigned, or vulnerable ships
// ============================================================================
//
// The SolarWinds breach (disclosed December 2020) worked because the
// build pipeline itself was the attack surface: malicious code was
// injected during the build, then SIGNED and shipped to ~18,000
// organizations as a legitimate update. Defense afterward converged on
// one idea — provenance gates: an artifact reaches production only by
// passing every gate, in order, with no side door.
//
// This registry encodes the gates as topology: built -> scanned ->
// signed -> promoted, and `soma verify` proves there is no edge that
// skips a gate. An image whose scan finds critical CVEs lands in
// `quarantined` — TERMINAL, because you rebuild from a patched base,
// you never "un-quarantine". The promoted registry's CVE ledger has a
// memory invariant pinned at zero: recording a critical vulnerability
// against a production image is a write the memory itself refuses.
// ============================================================================

cell ImageRegistry {
    face {
        signal scan_pass(img: String) -> Map
        signal scan_quarantine(img: String) -> Map
        signal sign_image(img: String) -> Map
        signal promote_to_prod(img: String) -> Map
        signal image_state(img: String) -> String
    }

    memory {
        // critical CVEs recorded against PROMOTED images. The only
        // value this ledger accepts is 0 — by invariant.
        prod_critical_cves: Map<String, Int> [persistent, consistent]
        invariant prod_critical_cves >= 0 && prod_critical_cves <= 0
    }

    // Every path to `promoted` crosses `scanned` and `signed`.
    // `quarantined` and `promoted` are both terminal: tainted images
    // never return, shipped digests never mutate.
    state image {
        initial: built
        built -> scanned
        scanned -> signed
        signed -> promoted
        built -> quarantined
        scanned -> quarantined
    }

    on scan_pass(img: String) {
        let r = try { transition(img, "scanned") }
        if r.error != () { return map("ok", false, "reason", "{r.error}") }
        return map("ok", true, "state", "scanned")
    }

    on scan_quarantine(img: String) {
        let r = try { transition(img, "quarantined") }
        if r.error != () { return map("ok", false, "reason", "{r.error}") }
        return map("ok", true, "state", "quarantined")
    }

    on sign_image(img: String) {
        let r = try { transition(img, "signed") }
        if r.error != () { return map("ok", false, "reason", "{r.error}") }
        return map("ok", true, "state", "signed")
    }

    on promote_to_prod(img: String) {
        let r = try { transition(img, "promoted") }
        if r.error != () { return map("ok", false, "reason", "{r.error}") }
        prod_critical_cves.set(img, 0)
        return map("ok", true, "state", "promoted")
    }

    on image_state(img: String) {
        return get_status(img)
    }
}

cell test ProvenanceTests {
    rules {
        // THE SIDE DOOR: sign or ship an unscanned build. Not an edge.
        assert_fails transition("app:9f3c", "signed")
        assert_fails transition("app:9f3c", "promoted")

        // the only road runs through every gate, in order
        assert scan_pass("app:9f3c").ok == true
        assert_fails transition("app:9f3c", "promoted")   // unsigned: no
        assert sign_image("app:9f3c").ok == true
        assert promote_to_prod("app:9f3c").ok == true

        // a shipped digest is immutable history
        assert_fails transition("app:9f3c", "built")
        assert_fails transition("app:9f3c", "scanned")

        // a tainted image is buried, not paroled
        assert scan_quarantine("app:bad1").ok == true
        assert_fails transition("app:bad1", "scanned")
        assert_fails transition("app:bad1", "signed")

        // the prod CVE ledger accepts exactly one number: zero
        assert prod_critical_cves.set("app:9f3c", 0) == ()
        assert_fails prod_critical_cves.set("app:9f3c", 1)
    }
}

What the toolchain says

Run on a fresh copy of the program at build time; the outputs are pasted unedited.

$ soma check image_promotion.cell
✓ All checks passed.
$ soma test image_promotion.cell
test ProvenanceTests ...
  ✓ assert_fails transition("app:9f3c", "signed") — raised invalid transition: built → signed. Current state: 'built'. Valid targets: [scanned, quarantined]
  ✓ assert_fails transition("app:9f3c", "promoted") — raised invalid transition: built → promoted. Current state: 'built'. Valid targets: [scanned, quarantined]
  ✓ assert scan_pass("app:9f3c").ok == true
  ✓ assert_fails transition("app:9f3c", "promoted") — raised invalid transition: scanned → promoted. Current state: 'scanned'. Valid targets: [signed, quarantined]
  ✓ assert sign_image("app:9f3c").ok == true
  ✓ assert promote_to_prod("app:9f3c").ok == true
  ✓ assert_fails transition("app:9f3c", "built") — raised invalid transition: promoted → built. Current state: 'promoted'. Valid targets: []
  ✓ assert_fails transition("app:9f3c", "scanned") — raised invalid transition: promoted → scanned. Current state: 'promoted'. Valid targets: []
  ✓ assert scan_quarantine("app:bad1").ok == true
  ✓ assert_fails transition("app:bad1", "scanned") — raised invalid transition: quarantined → scanned. Current state: 'quarantined'. Valid targets: []
  ✓ assert_fails transition("app:bad1", "signed") — raised invalid transition: quarantined → signed. Current state: 'quarantined'. Valid targets: []
  ✓ assert prod_critical_cves.set("app:9f3c", 0) == ()
  ✓ assert_fails prod_critical_cves.set("app:9f3c", 1) — raised memory invariant violated on 'prod_critical_cves': prod_critical_cves >= 0 && prod_critical_cves <= 0 — rejected write of 1 (key "app:9f3c"); the slot is unchanged

13 tests: 13 passed, 0 failed
$ soma verify image_promotion.cell
Verifying image_promotion.cell...

State machine 'image': 5 states, initial 'built'
  States: [built, promoted, quarantined, scanned, signed]

  ✓ 5 states, 5 transitions
  ✓ all states reachable from 'built'
  ✓ terminal states: [promoted, quarantined]
  ✓ no deadlocks
  ✓ liveness: every state can eventually reach a terminal state
  ✓ think-isolated: CTL safety properties hold regardless of LLM output (4 handlers, 4 literal transitions, 0 dynamic)
  ✓ termination: all 5 handlers structurally terminate
  ✓ refinement: handler `scan_pass` ⟶ {scanned}
  ✓ refinement: handler `scan_quarantine` ⟶ {quarantined}
  ✓ refinement: handler `sign_image` ⟶ {signed}
  ✓ refinement: handler `promote_to_prod` ⟶ {promoted}
  · transition sources: `scan_pass`, `scan_quarantine`, `sign_image`, `promote_to_prod` call transition(id, target) without declaring the source — the runtime refuses a move the graph forbids, but the proof does not see where the handler starts; `transition(id, from, to)` names the edge (checked by `soma check`, refused at run time from any other state)

ImageRegistry/invariants:

  ✓ invariant prod_critical_cves >= 0 && prod_critical_cves <= 0 — writer 'promote_to_prod' proven (writes 0)

12 passed, 0 warnings, 0 failures

  Temporal properties for 'image':
  ✓ deadlock_free — no deadlocks in any reachable state
Temporal: 1 passed, 0 failed
VERIFY OK

Builtins used

get_status, map, transition

Source file: /corpus/devops/image_promotion.cell · examples/corpus/devops/image_promotion.cell