Documentation
¶
Overview ¶
Package converter reads the file a converter writes for Draugr to import: the findings of a tool Draugr has no reader for, with those of Draugr's own result properties a declared converter may set.
A converter is a program a CI step runs on another tool's output. Draugr never runs it. It reads the file the step wrote, as it reads any import, held to a commit, because running a program at scan time would put arbitrary code execution inside the scan.
The file follows a versioned contract, draugr-converter.v1.schema.json, embedded here as the one description of the file's shape. Read holds a file to it key by key, so a converter's author is told which key of which result is wrong, and to a fixed list of the properties a converter may set (Properties). Each of those adds evidence about a finding or raises it. A property that sets a finding aside or lowers it (Never) is refused by name, whatever the descriptor says: a finding moves down only on evidence Draugr can check, and a converter's word is not that evidence.
Index ¶
Constants ¶
const ID = "draugr-converter"
ID is the contract's id, which every converter file states as its `contract`.
const SchemaFile = "draugr-converter.v1.schema.json"
SchemaFile is the name the schema is kept and published under.
const Version = 1
Version is the contract version this build reads. A file stating any other is refused, naming this one, because a reader that guessed at an older or newer shape would read some of its keys and drop the rest without a word.
Variables ¶
var Never = []string{
"suppression", "suppressions", "aside", "nonShipping", "acceptedBy", "origin",
"priority", "priorityCap", "rankedAs", "unreachable",
}
Never are the result properties no converter may set, whatever a descriptor declares: each sets a finding aside, says who accepted it, or ranks it lower. A file naming one is refused by name rather than read without it, so the converter's author learns the property was never going to apply.
var Properties = []Property{PropertyPackage, PropertyCWE, PropertyLabels, PropertyReachable, PropertyRaise}
Properties is the allow-list, fixed here. A descriptor's converter.sets may name fewer of them and never another.
var SchemaJSON []byte
SchemaJSON is the contract's JSON Schema, embedded so the binary reads files against exactly the contract it documents.
Functions ¶
Types ¶
type Document ¶
type Document struct {
Contract string `json:"contract"`
Version int `json:"version"`
Converter Converter `json:"converter"`
Source Source `json:"source"`
Commit string `json:"commit"`
Repository string `json:"repository,omitempty"`
Written string `json:"written,omitempty"`
Results []Result `json:"results"`
}
Document is a converter file.
func Read ¶
Read reads a converter file, held to the contract and to allowed, the properties the descriptor declares the converter sets. Anything else the file sets is an error naming it.
The checks run in the order a converter's author fixes them: whether it is a converter file at all, its version, a property no converter may set, then the contract key by key, and last a property the descriptor did not declare.
type Package ¶
type Package struct {
Name string `json:"name"`
Version string `json:"version,omitempty"`
FixedVersion string `json:"fixedVersion,omitempty"`
PURL string `json:"purl,omitempty"`
Ecosystem string `json:"ecosystem,omitempty"`
}
Package is the dependency a finding is about.
type Property ¶
type Property string
Property is one of Draugr's result properties a converter may set.
const ( // PropertyPackage is the dependency a finding is about, with its version, fixed version and // package URL. PropertyPackage Property = "package" // PropertyCWE is the CWE ids of the flaw. PropertyCWE Property = "cwe" // PropertyLabels is labels on the finding, beside the component's own. PropertyLabels Property = "labels" // PropertyReachable is a verdict that the project's code reaches the vulnerable code. PropertyReachable Property = "reachable" // PropertyRaise is a band the finding is ranked at least at. PropertyRaise Property = "raise" )
The properties a converter may set. Each adds evidence about a finding or raises it.
type Result ¶
type Result struct {
RuleID string `json:"ruleId"`
Message string `json:"message"`
Severity string `json:"severity"`
Score *float64 `json:"score,omitempty"`
Location *Location `json:"location,omitempty"`
Package *Package `json:"package,omitempty"`
CWE []string `json:"cwe,omitempty"`
Labels map[string]string `json:"labels,omitempty"`
Reachable *bool `json:"reachable,omitempty"`
Raise *Raise `json:"raise,omitempty"`
}
Result is one finding.