Documentation
¶
Overview ¶
Package tools describes the external command-line scanners Draugr orchestrates and detects whether they are installed. It backs `draugr doctor` — an explicit preflight so a missing tool is reported up front with an install hint, instead of surfacing as a buried "executable file not found" error mid-scan.
Detection only ever reads the environment (looks on PATH, runs a version probe). It never downloads or installs anything — provisioning is a separate, opt-in step.
Index ¶
- Constants
- func BinDir() (string, error)
- func Catalog() map[string]Tool
- func DataDirFor(name string) string
- func DataRoot() (string, error)
- func Installable() []string
- func NucleiTemplatesOK(out []byte) (bool, string)
- func PlatformKey() string
- func SemgrepPipxCommand() string
- func SemgrepVersion() string
- type Asset
- type Attestation
- type CosignSpec
- type InstallSpec
- type Installed
- type Level
- type LookPathFunc
- type RunFunc
- type Status
- type Tool
Constants ¶
const ( CategoryScanner = "scanner" CategoryUtility = "utility" )
Tool categories.
Variables ¶
This section is empty.
Functions ¶
func Catalog ¶
Catalog returns the external tools Draugr's built-in scanners use, keyed by binary name. Several scanners share one binary (trivy backs images, sca, and iac), so the catalog is keyed by the binary rather than the scanner.
func DataDirFor ¶ added in v0.55.0
DataDirFor returns where a tool's supporting files live, or "" when it has none.
func DataRoot ¶ added in v0.55.0
DataRoot is where tools that need more than a binary keep it, one directory per tool.
Beside bin/ rather than inside it: a directory of YAML on PATH is confusing, and a tool's data has a different lifetime from its binary — reinstalling one should not silently orphan the other somewhere a reader has to guess at.
func Installable ¶ added in v0.8.0
func Installable() []string
Installable returns the names of the tools `tools install` can provision, sorted.
func NucleiTemplatesOK ¶ added in v0.52.0
NucleiTemplatesOK reports whether Nuclei has a template set, and which. Exported because the scanner checks the same thing after asking Nuclei to download one — the tool exits 0 either way, so the answer has to come from the same place `doctor` gets it.
func PlatformKey ¶ added in v0.63.0
func PlatformKey() string
PlatformKey is the key into InstallSpec.Assets for the machine Draugr is running on.
func SemgrepPipxCommand ¶ added in v0.8.0
func SemgrepPipxCommand() string
SemgrepPipxCommand returns the recommended pinned install command for Semgrep, which is a Python package rather than a standalone binary.
func SemgrepVersion ¶ added in v0.8.0
func SemgrepVersion() string
SemgrepVersion is the pinned Semgrep version.
Types ¶
type Asset ¶ added in v0.8.0
type Asset struct {
URL string
// URLTemplate renders the download URL for a version other than the pinned one, with
// {version} substituted (no leading "v"). Empty means Draugr cannot fetch another version of
// this platform's build, and will say so rather than guessing at a URL shape.
URLTemplate string
SHA256 string
BinaryInArchive string // name of the binary within the .tar.gz; "" = the download is the binary
// DataInArchive is a directory prefix inside the archive to extract alongside the binary,
// e.g. "cfg/" for kube-bench's benchmark definitions.
//
// Some tools are not one file. kube-bench without its cfg/ tree exits complaining about a
// missing "target_mapping" section, which names an internal structure rather than the 276
// files nobody copied — so installing the binary alone is a half-install that looks whole.
DataInArchive string
}
Asset is one platform's download for an installable tool. When BinaryInArchive is empty the downloaded file is the binary itself (a bare release binary, e.g. cosign), not an archive.
type Attestation ¶ added in v0.63.0
type Attestation struct {
// Tool is the executable's name, e.g. "trivy".
Tool string
// Path is where it was found. Empty when it was not.
Path string
// Version is what the tool reports, when Draugr can read it.
Version string
// Level is how strongly Draugr can vouch for this binary.
Level Level
// Reason says why the level is what it is, when it is not the strongest.
Reason string
}
Attestation is what Draugr can say about the build of a tool a scan used.
A scan runs whatever is on PATH, which is right: an operator may have an experimental build, a fork, or a distribution package with a vendor suffix, and each is a case where they know something Draugr does not. But a report that cannot say *which* build produced its findings cannot be reproduced, so the answer is to record it rather than to refuse it.
func Attest ¶ added in v0.63.0
func Attest(tool, path, version, binDir string) Attestation
Attest reports what Draugr knows about the build of a tool.
Attested means all three: the binary sits in Draugr's own directory, the install manifest has a record for it, and the file's hash still matches what was recorded. Anything else is used and labelled — a binary somewhere else on PATH, one Draugr never installed, or one that has changed since it did.
The hash check is the one that earns its place. Without it "attested" would mean "in the right directory", which is a claim about a path rather than about a file.
func AttestFound ¶ added in v0.63.0
func AttestFound(tool, version string) Attestation
AttestFound looks a tool up on PATH and attests to what it finds.
type CosignSpec ¶ added in v0.13.0
type CosignSpec struct {
// ChecksumsURL is the upstream's signed checksums file, listing each asset's SHA-256.
ChecksumsURL string
// ChecksumsURLTemplate and BundleURLTemplate render those URLs for another version.
ChecksumsURLTemplate string
BundleURLTemplate string
// BundleURL is the Sigstore bundle (.sigstore.json) signing ChecksumsURL.
BundleURL string
// IdentityRegexp is the required signing certificate identity (--certificate-identity-regexp).
IdentityRegexp string
// OIDCIssuer is the required OIDC issuer (--certificate-oidc-issuer).
OIDCIssuer string
}
CosignSpec describes how to verify a tool release's provenance with cosign, for upstreams that publish a keyless signature over their checksums file. It is optional and additive: the SHA-256 pin remains the mandatory integrity floor; cosign proves the checksums file was signed by the upstream's expected release identity. Verification uses the cosign CLI (no Go sigstore dependency) and the new Sigstore bundle format.
type InstallSpec ¶ added in v0.8.0
type InstallSpec struct {
Binary string
Version string
// ChecksumsURLTemplate is an *unsigned* checksums file for an arbitrary version, for an
// upstream that publishes one but signs nothing. Weaker than Cosign and much better than
// nothing: it catches a corrupted or truncated download.
ChecksumsURLTemplate string
Assets map[string]Asset
// Cosign, when set, verifies the release's provenance in addition to the SHA-256 pin.
// Nil for upstreams that publish no signature (e.g. gitleaks) — those stay SHA-256-only.
Cosign *CosignSpec
// DataDir is where Asset.DataInArchive is written, relative to Draugr's own directory.
// Namespaced by tool so a second tool with data files does not collide with the first.
DataDir string
}
InstallSpec pins an installable tool to a version and its per-platform assets, keyed by "GOOS/GOARCH" (e.g. "linux/amd64").
func Spec ¶ added in v0.8.0
func Spec(name string) (InstallSpec, bool)
Spec returns the pinned install spec for a tool.
func SpecFor ¶ added in v0.63.0
func SpecFor(name, version string) (InstallSpec, error)
SpecFor returns the install spec for a requested version.
An empty version, or the one Draugr ships, returns the pinned spec unchanged — recorded SHAs, no network needed to know what to expect. Any other version returns a spec with URLs rendered from the templates and **no recorded SHA**, which is what tells Install to verify differently.
Draugr does not refuse a version it cannot vouch for. Refusing would be blocking somebody who knows something Draugr does not — an experimental build, a fork, a version newer than this release. It installs what was asked for and records how well it could check it, and that record travels into every report the tool goes on to produce.
type Installed ¶ added in v0.8.0
type Installed struct {
Name string
Version string
Path string
// SignatureVerified is true when an upstream cosign signature was verified (in addition
// to the always-checked SHA-256 pin).
SignatureVerified bool
// ProvenanceNote summarizes the signature outcome for reporting (e.g. why it was skipped);
// empty when the tool has no cosign provenance configured.
ProvenanceNote string
// AlreadyPresent is true when the pinned build was already installed and left untouched.
AlreadyPresent bool
}
Installed describes a successfully provisioned tool.
func Install ¶ added in v0.8.0
func Install(ctx context.Context, name, destDir string, client *http.Client, force bool) (Installed, error)
Install downloads the pinned build of name, verifies its SHA-256, extracts the binary, and installs it into destDir with an executable bit. client may be nil (a default is used). The download is verified before anything is written, and the binary is placed atomically. Install provisions a pinned tool into destDir. A tool already present at exactly the pinned build is left alone unless force is set — see the install manifest below.
func InstallVersion ¶ added in v0.63.0
func InstallVersion(ctx context.Context, name, version, destDir string, client *http.Client, force bool) (Installed, error)
InstallVersion installs a specific version, or the pinned one when version is empty.
would hide the order, and the order is the security property.
type Level ¶ added in v0.63.0
type Level string
Level is how strongly Draugr can vouch for a binary, strongest first.
Not a boolean, because the claims are genuinely different. An unsigned checksums file proves a download was not corrupted or truncated and that the host served consistent content; it does not prove the upstream published it. That is weaker than a signature and much stronger than nothing, and collapsing the two throws away a difference a reader may care about.
const ( // LevelPinned: installed at the version Draugr ships, matching a SHA-256 recorded in this // binary. The only level that needs no network to verify. LevelPinned Level = "pinned" // LevelSigned: installed at another version, matching checksums signed by the upstream's // Sigstore identity. LevelSigned Level = "signed" // LevelChecksum: installed, matching an unsigned checksums file fetched from the upstream. LevelChecksum Level = "checksum" // LevelUnverified: installed with nothing published to check it against. LevelUnverified Level = "unverified" // LevelExternal: not installed by Draugr. Found on PATH, and used — the operator brought it, // and they know something Draugr does not. LevelExternal Level = "external" )
The levels, strongest first.
type LookPathFunc ¶
LookPathFunc resolves a binary name to a path (defaults to exec.LookPath).
type Status ¶
type Status struct {
Tool Tool
Found bool
Path string
Version string
// Err is set when the tool was found but the version probe failed (non-fatal).
Err error
// DataFound reports whether the tool's supporting data is present. Meaningless unless the
// tool declares DataArgs; DataChecked says whether it was asked.
DataChecked bool
DataFound bool
// DataDetail describes what was found, e.g. a template-set version.
DataDetail string
}
Status is the outcome of detecting a Tool.
type Tool ¶
type Tool struct {
// Binary is the executable name looked up on PATH, e.g. "trivy".
Binary string
// VersionArgs prints the tool's version, e.g. ["--version"]. Empty skips the probe.
VersionArgs []string
// InstallHint tells the user how or where to install the tool when it's missing.
InstallHint string
// Category groups the tool: "scanner" (backs a control) or "utility" (supporting tool
// like git or cosign). Shown in `tools list`.
Category string
// Optional marks a tool whose absence should not fail `doctor` — a nice-to-have that
// enhances behavior (e.g. cosign for signature verification) rather than a requirement.
Optional bool
// DataArgs probes for data the tool needs beyond its own binary — Nuclei's template set,
// for instance. Empty means the binary is all there is.
//
// Being on PATH is not the same as being able to run. A tool whose data is missing fails at
// scan time with a message about a symptom, and `doctor` exists to answer "is this going to
// fail" before the scan rather than after it.
DataArgs []string
// DataFiles are paths that must exist for the tool to work, tried in order. Used where the
// tool cannot be asked cheaply: kube-bench only reveals a missing `cfg/` by attempting a
// benchmark, and doctor must not run a scan to find out whether a scan would work.
DataFiles []string
// DataOK reads DataArgs' output and reports whether the data is there, plus a short
// description for the report. Required when DataArgs is set.
DataOK func(out []byte) (ok bool, detail string)
// DataHint tells the user how to obtain the data when it is missing.
DataHint string
}
Tool describes an external executable a scanner shells out to.