Choreo.Lab.DSL.ThreatModel (Choreo v0.12.0)

Copy Markdown View Source

Experimental Livebook-friendly DSL for sketching STRIDE threat models.

This Lab DSL compiles to the stable, pipe-first Choreo.ThreatModel builders and returns an ordinary %Choreo.ThreatModel{}. It is intentionally small: use it to sketch external entities, processes, data stores, trust boundaries, and data flows quickly, then use Choreo.ThreatModel.Analysis explicitly for the real security review.

Examples

iex> import Choreo.Lab.DSL.ThreatModel
...> model = threat_model do
...>   internet = boundary("Internet", level: 0)
...>   app = boundary("Application", level: 2)
...>   data = boundary("Data", level: 3)
...>
...>   user = external_entity("User", boundary: internet)
...>   api = process("API Gateway", boundary: app, privilege: :user)
...>   db = data_store("Tenant DB", boundary: data, sensitivity: :confidential)
...>
...>   user ~> api |> encrypted("HTTPS request", protocol: :https)
...>   api ~> db |> flow("Reads tenant config", protocol: :sql)
...> end
iex> Enum.sort(Choreo.ThreatModel.elements(model))
[:api, :db, :user]
iex> Choreo.ThreatModel.boundary_of(model, :api)
"app"
iex> edges = Choreo.ThreatModel.edges_with_meta(model)
iex> Enum.any?(edges, fn {from, to, _, meta} -> from == :api and to == :db and meta.protocol == :sql end)
true
iex> Enum.any?(edges, fn {from, to, _, meta} -> from == :user and to == :api and meta.encrypted end)
true

Edges can use generic, typed, or pipe-modified forms:

user ~> api
user ~> api |> encrypted("HTTPS request", protocol: :https)
flow api ~> db, "SQL query", protocol: :sql
unencrypted worker ~> queue, "plain queue message"

Summary

Functions

Returns the vocabulary supported by the threat-model DSL.

Builds a %Choreo.ThreatModel{} from a compact Lab DSL block.

Compatibility alias for taxonomy/0.

Functions

actor(arg1 \\ nil, arg2 \\ nil, opts \\ [])

api(arg1 \\ nil, arg2 \\ nil, opts \\ [])

boundary(arg1 \\ nil, arg2 \\ nil, opts \\ [])

bucket(arg1 \\ nil, arg2 \\ nil, opts \\ [])

cache(arg1 \\ nil, arg2 \\ nil, opts \\ [])

client(arg1 \\ nil, arg2 \\ nil, opts \\ [])

data_flow(arg1 \\ nil, arg2 \\ nil, opts \\ [])

data_store(arg1 \\ nil, arg2 \\ nil, opts \\ [])

database(arg1 \\ nil, arg2 \\ nil, opts \\ [])

db(arg1 \\ nil, arg2 \\ nil, opts \\ [])

encrypted(arg1 \\ nil, arg2 \\ nil, opts \\ [])

external(arg1 \\ nil, arg2 \\ nil, opts \\ [])

external_entity(arg1 \\ nil, arg2 \\ nil, opts \\ [])

flow(arg1 \\ nil, arg2 \\ nil, opts \\ [])

function(arg1 \\ nil, arg2 \\ nil, opts \\ [])

process(arg1 \\ nil, arg2 \\ nil, opts \\ [])

queue(arg1 \\ nil, arg2 \\ nil, opts \\ [])

reads(arg1 \\ nil, arg2 \\ nil, opts \\ [])

sends(arg1 \\ nil, arg2 \\ nil, opts \\ [])

service(arg1 \\ nil, arg2 \\ nil, opts \\ [])

store(arg1 \\ nil, arg2 \\ nil, opts \\ [])

taxonomy()

@spec taxonomy() :: %{
  boundaries: [atom()],
  nodes: [atom()],
  edges: [atom()],
  modifiers: [atom()],
  options: [atom()]
}

Returns the vocabulary supported by the threat-model DSL.

iex> taxonomy = Choreo.Lab.DSL.ThreatModel.taxonomy()
iex> :boundary in taxonomy.boundaries
true
iex> :process in taxonomy.nodes
true
iex> :encrypted in taxonomy.modifiers
true

third_party(arg1 \\ nil, arg2 \\ nil, opts \\ [])

threat_model(list)

(macro)

Builds a %Choreo.ThreatModel{} from a compact Lab DSL block.

threat_model(opts, list)

(macro)

trust_boundary(arg1 \\ nil, arg2 \\ nil, opts \\ [])

unencrypted(arg1 \\ nil, arg2 \\ nil, opts \\ [])

user(arg1 \\ nil, arg2 \\ nil, opts \\ [])

verbs()

@spec verbs() :: map()

Compatibility alias for taxonomy/0.

worker(arg1 \\ nil, arg2 \\ nil, opts \\ [])

writes(arg1 \\ nil, arg2 \\ nil, opts \\ [])

zone(arg1 \\ nil, arg2 \\ nil, opts \\ [])