Documentation
¶
Overview ¶
Package threatmodel holds the domain model for Continuous Threat Modeling — a live, per-scope threat model that is derived (never drawn) from attacker profiles × exposure chains × applicable ATT&CK techniques, with every threat's status derived from live findings/validation.
See docs/rfcs/RFC-continuous-threat-modeling.md.
Index ¶
- Constants
- Variables
- func CredentialRank(level string) int
- func NetworkRank(level string) int
- type AttackerCapabilities
- type AttackerProfileFact
- type AttackerProfileReader
- type FindingFact
- type FindingReader
- type ModelFilter
- type Repository
- type ScopeType
- type TechniqueApplicability
- type TechniqueMitigation
- type ThreatFilter
- type ThreatModel
- type ThreatModelThreat
- type ThreatStatus
Constants ¶
const ( NetworkExternal = "external" NetworkInternal = "internal" NetworkPhysical = "physical" CredentialNone = "none" CredentialUser = "user" CredentialAdmin = "admin" )
Network-access and credential capability levels, ordered weakest→strongest. An attacker satisfies a technique's minimum requirement when its own level rank is >= the required rank. Empty ("") means "no requirement".
const DefaultDatasetVersion = "attack-16.1"
DefaultDatasetVersion is the ATT&CK dataset version the seeded catalog uses. Models record which version their threats were computed against.
Variables ¶
var ( // ErrNotFound is returned when a threat model does not exist for the tenant. ErrNotFound = shared.NewDomainError("THREAT_MODEL_NOT_FOUND", "threat model not found", shared.ErrNotFound) // ErrInvalidScope is returned when scope_type is not a recognized value. ErrInvalidScope = shared.NewDomainError("THREAT_MODEL_INVALID_SCOPE", "invalid threat model scope type", shared.ErrValidation) // ErrInvalidStatus is returned when a threat status is not a recognized value. ErrInvalidStatus = shared.NewDomainError("THREAT_MODEL_INVALID_STATUS", "invalid threat status", shared.ErrValidation) // ErrEmptyName is returned when a threat model is created without a name. ErrEmptyName = shared.NewDomainError("THREAT_MODEL_EMPTY_NAME", "threat model name is required", shared.ErrValidation) )
Domain errors.
Functions ¶
func CredentialRank ¶
CredentialRank ranks a credential level. Unknown/empty ranks as none (0).
func NetworkRank ¶
NetworkRank ranks a network-access level. Unknown/empty ranks as external (1).
Types ¶
type AttackerCapabilities ¶
type AttackerCapabilities struct {
NetworkAccess string // external|internal|physical ("" treated as external)
CredentialLevel string // none|user|admin ("" treated as none)
Persistence bool
}
AttackerCapabilities is the capability gate an attacker profile brings to the generation pipeline. It mirrors attackerprofile.Capabilities but is a neutral value type so the pure applicability logic has no dependency on that aggregate.
type AttackerProfileFact ¶
type AttackerProfileFact struct {
ID shared.ID
Name string
ProfileType string
Capabilities AttackerCapabilities
IsDefault bool
}
AttackerProfileFact is a neutral projection of an attacker profile used as a generation input (id + capability gate).
type AttackerProfileReader ¶
type AttackerProfileReader interface {
// ListAttackerProfiles returns every attacker profile for the tenant, default
// profiles first. An empty result is valid (the caller falls back to a single
// synthetic external-unauth profile).
ListAttackerProfiles(ctx context.Context, tenantID shared.ID) ([]AttackerProfileFact, error)
}
AttackerProfileReader loads the tenant's attacker profiles (capability gates).
type FindingFact ¶
type FindingFact struct {
ID shared.ID
AssetID shared.ID
TechniqueID string // findings.mitre_technique_id ("" when unmapped)
CWEIDs []string // findings.cwe_ids
Category string // findings.finding_type (vulnerability/secret/…)
Status string // findings.status
AcceptanceExpiresAt *time.Time
}
FindingFact is a neutral projection of a finding used to derive threat status. Only the columns the status rules need are carried.
type FindingReader ¶
type FindingReader interface {
// ListThreatFindings returns the status-relevant findings for the given assets.
// assetIDs is bounded by the generation caps (chain targets + hops). An empty
// assetIDs slice returns no findings without touching the database.
ListThreatFindings(ctx context.Context, tenantID shared.ID, assetIDs []shared.ID) ([]FindingFact, error)
}
FindingReader loads the findings on a bounded set of assets for status derivation. Implementations MUST tenant-scope the query.
type ModelFilter ¶
type ModelFilter struct {
ScopeType ScopeType // "" = any scope type
ScopeRefID *shared.ID // nil = any scope ref
}
ModelFilter narrows the models returned by List. Zero-value fields are ignored.
type Repository ¶
type Repository interface {
// Save creates or replaces a threat model AND its threats in a single
// transaction: the model is upserted on its (tenant, scope) unique key and
// its threats are delete-and-inserted (full regeneration — no drift, no
// stale-row reconciliation). The passed model's rollup counters are persisted
// as-is; call ThreatModel.RecomputeRollups before Save.
Save(ctx context.Context, model *ThreatModel, threats []*ThreatModelThreat) error
// GetByID returns a model by id, tenant-scoped. Returns ErrNotFound if absent.
GetByID(ctx context.Context, tenantID, id shared.ID) (*ThreatModel, error)
// GetByScope returns the model for a (scopeType, scopeRefID) pair, tenant-
// scoped. scopeRefID is nil for a tenant-wide model. Returns ErrNotFound if
// no model has been generated for the scope yet.
GetByScope(ctx context.Context, tenantID shared.ID, scopeType ScopeType, scopeRefID *shared.ID) (*ThreatModel, error)
// ListModels returns models for a tenant, filtered and paginated, plus the
// total count matching the filter (ignoring pagination).
ListModels(ctx context.Context, tenantID shared.ID, filter ModelFilter, page pagination.Pagination) ([]*ThreatModel, int, error)
// ListThreats returns the threats for a model, tenant-scoped and filterable
// by status / attacker / tactic / technique. Ordered by hop_index, score.
ListThreats(ctx context.Context, tenantID, modelID shared.ID, filter ThreatFilter) ([]*ThreatModelThreat, error)
// Delete removes a model and (via ON DELETE CASCADE) its threats. Tenant-scoped.
Delete(ctx context.Context, tenantID, id shared.ID) error
// ListTechniqueMitigations returns the global technique→mitigation catalog for
// a dataset version. Not tenant-scoped (global seed).
ListTechniqueMitigations(ctx context.Context, datasetVersion string) ([]TechniqueMitigation, error)
// ListApplicability returns the global technique-applicability catalog for a
// dataset version. Not tenant-scoped (global seed).
ListApplicability(ctx context.Context, datasetVersion string) ([]TechniqueApplicability, error)
}
Repository persists and reads threat models (tenant-scoped runtime tables) and reads the global ATT&CK catalog (tenant-agnostic seed).
type ScopeType ¶
type ScopeType string
ScopeType identifies what a threat model is keyed to.
const ( ScopeCrownJewel ScopeType = "crown_jewel" ScopeBusinessUnit ScopeType = "business_unit" ScopeAssetGroup ScopeType = "asset_group" ScopeTenant ScopeType = "tenant" )
Recognized scope types (mirror the threat_models.scope_type CHECK).
type TechniqueApplicability ¶
type TechniqueApplicability struct {
TechniqueID string
AssetType string
EdgeType string // "" = any edge (stored NULL)
MinNetwork string // external|internal ("" = none required)
MinCredential string // none|user|admin ("" = none required)
RequiresPersistence bool
DatasetVersion string
}
TechniqueApplicability describes at which asset-type / edge / attacker capability a technique applies. MinNetwork/MinCredential express the minimum attacker capability that unlocks the technique; EdgeType may be empty to mean "any incoming edge".
type TechniqueMitigation ¶
type TechniqueMitigation struct {
TechniqueID string
TechniqueName string
Tactic string
MitigationID string
MitigationName string
MitigationSummary string
DatasetVersion string
}
TechniqueMitigation is one technique → MITRE M-series mitigation mapping.
type ThreatFilter ¶
type ThreatFilter struct {
Status ThreatStatus // "" = any status
AttackerProfileID *shared.ID // nil = any attacker
Tactic string // "" = any tactic
TechniqueID string // "" = any technique
}
ThreatFilter narrows the threats returned for a model. Zero-value fields are ignored (no filter).
type ThreatModel ¶
type ThreatModel struct {
ID shared.ID
TenantID shared.ID
ScopeType ScopeType
ScopeRefID *shared.ID // nil for tenant-wide models
Name string
GeneratedAt time.Time
InputHash string
TechniqueDatasetVersion string
// Cached rollups (recomputed from threats each generation).
ThreatsTotal int
ThreatsOpen int
ThreatsMitigated int
ThreatsCovered int
CoveragePct float64
CreatedAt time.Time
UpdatedAt time.Time
}
ThreatModel is one generated threat model keyed to a scope. It is fully regenerated each CTEM cycle (never edited), so it is modeled as a projection with exported fields plus a validating constructor rather than a rich mutable aggregate. Rollup counters are cached for query/filter and recomputed from the threats via RecomputeRollups.
func NewThreatModel ¶
func NewThreatModel(tenantID shared.ID, scopeType ScopeType, scopeRefID *shared.ID, name string) (*ThreatModel, error)
NewThreatModel builds a threat model for a scope, validating scope_type and name and assigning a fresh id + timestamps. scopeRefID may be nil for a tenant-wide model.
func (*ThreatModel) RecomputeRollups ¶
func (m *ThreatModel) RecomputeRollups(threats []*ThreatModelThreat)
RecomputeRollups recalculates the cached counters and coverage percentage from the supplied threats. "Covered" for the purposes of the coverage percentage is the union of mitigated + covered + accepted threats (i.e. not open and not merely theoretical); theoretical threats count toward the total but are neither open nor covered. This keeps coverage_pct honest: it is (mitigated+covered+accepted) / (open+mitigated+covered+accepted).
type ThreatModelThreat ¶
type ThreatModelThreat struct {
ID shared.ID
TenantID shared.ID
ThreatModelID shared.ID
AttackerProfileID *shared.ID
EntryPointAssetID *shared.ID
TargetAssetID *shared.ID
HopAssetID *shared.ID
HopIndex int
ChainFingerprint string
TechniqueID string
Tactic string
MitigationID string
Status ThreatStatus
StatusReason string
EvidenceFindingID *shared.ID
Score float64
CreatedAt time.Time
}
ThreatModelThreat is one enumerated threat: (attacker × chain-hop × technique). Regenerated wholesale (delete-and-insert) per model — never reconciled.
func NewThreatModelThreat ¶
func NewThreatModelThreat(tenantID, threatModelID shared.ID, status ThreatStatus) (*ThreatModelThreat, error)
NewThreatModelThreat builds an enumerated threat under a model, validating the status enum and assigning a fresh id + timestamp. threatModelID and tenantID tie the threat to its parent model and tenant.
type ThreatStatus ¶
type ThreatStatus string
ThreatStatus is the derived status of an enumerated threat. It is computed at generation time from live findings/validation and cached on the row — never a manually edited field.
const ( // StatusOpen — a matching open finding exists on the hop asset. StatusOpen ThreatStatus = "open" // StatusMitigated — the matching finding is fixed/resolved, or a compensating control covers the hop. StatusMitigated ThreatStatus = "mitigated" // StatusCovered — a validation/BAS record for the technique returned blocked/detected. StatusCovered ThreatStatus = "covered" // StatusAccepted — a finding exception / risk acceptance applies. StatusAccepted ThreatStatus = "accepted" // StatusTheoretical — technique is applicable but no finding/validation exists yet. StatusTheoretical ThreatStatus = "theoretical" )
Recognized threat statuses (mirror the threat_model_threats.status CHECK).
func (ThreatStatus) String ¶
func (s ThreatStatus) String() string
String returns the status as a string.
func (ThreatStatus) Valid ¶
func (s ThreatStatus) Valid() bool
Valid reports whether s is a recognized threat status.