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
- Variables
- func BinDir() (string, error)
- func Catalog() map[string]Tool
- func Current(destDir, name, version string) (string, bool)
- func DataDirFor(name string) string
- func DataRoot() (string, error)
- func DescribeFor(l Level, _ string) string
- func GoToolchain(name string) string
- func GoToolchainBehind(name, buildGo string) bool
- func GoVersion(name string) string
- func GovulncheckVersion(out []byte) string
- func GrypeDBOK(out []byte) (bool, string)
- func Installable() []string
- func InstalledCopy(destDir, name, path string) bool
- func Latest(ctx context.Context, client *http.Client, name string) (string, error)
- func LatestGo(ctx context.Context, client *http.Client) (string, error)
- func ManagedVersion(name string) string
- func NodeVersion(name string) string
- func NucleiTemplatesOK(out []byte) (bool, string)
- func PinnedVersion(name string) string
- func PlannedCheck(name, version string) string
- func PlannedVersion(name, version string) (string, bool)
- func PlatformKey() string
- func PointToolWritesUnderDraugrHome() error
- func Provisionable(tool string) bool
- func PullCommand(t Tool) string
- func PythonVersion(name string) string
- func ReadBuildGo(path string) string
- func RuntimeMissing(err error) error
- func ScanDataDir(tool string) string
- func SemgrepVersion() string
- func UnderDraugrHome(path string) bool
- func Uninstall(destDir string, r Removal, withCaches bool) error
- func Uninstallable(destDir string) []string
- type Asset
- type Attestation
- type CosignSpec
- type Drift
- type GoSpec
- type InstallSpec
- type Installed
- type Kind
- type Level
- type LookPathFunc
- type NodeSpec
- type NucleiTemplateSet
- type PythonSpec
- type Removal
- type RemovedPath
- type RunFunc
- type Runtime
- type Status
- type Tool
- type Unwritable
- type Upstream
Constants ¶
const ( // CheckPinned is a release archive matched against a SHA-256 recorded in this build. CheckPinned = "sha256" // CheckPinnedSigned is CheckPinned and the upstream's cosign signature over its checksums. CheckPinnedSigned = "sha256 + cosign" // CheckSigned is another version, listed in checksums the upstream signed with cosign. CheckSigned = "upstream cosign" // CheckChecksum is another version, listed in an unsigned checksums file the upstream publishes. CheckChecksum = "upstream sha256" // CheckPyPI is every artifact of a Python package and its dependencies matched against a // SHA-256 recorded in this build. CheckPyPI = "sha256 (+deps)" // CheckNPM is every package in an npm tree matched against a SHA-512 integrity digest in the // lockfile recorded in this build. CheckNPM = "sha512 (+deps)" // CheckGoSumDB is a Go module and every module it builds with, verified against the Go // checksum database. CheckGoSumDB = "checksum db (+deps)" // CheckNone is an install nothing verified. CheckNone = "unverified" )
The checks an install can make, named as the plan's Verify column names them. One vocabulary for the plan and the result, so the line printed after an install says the same thing the plan said before it, or says why it differs.
const ( KICSVersion = "2.2.1" KICSImage = "checkmarx/kics:v2.2.1@sha256:49ccc54b6ae7f5d5fc95e96f8f95c18c57f3bba047ab611a03d80792bdff6757" )
KICSVersion is the KICS release the kics scanner runs, and KICSImage the image it runs it from, pinned by the digest of the multi-platform index Checkmarx published for that release, so one pin serves amd64 and arm64.
Quoted literals on lines of their own, so a bump is a two-line change a reviewer can check against `docker buildx imagetools inspect checkmarx/kics:<version>`.
const ( CategoryScanner = "scanner" CategoryUtility = "utility" )
Tool categories.
const ( KindBinary = "binary" KindPythonEnv = "python env" KindNodeEnv = "node env" KindData = "data" KindCache = "cache" )
Kinds of path an uninstall removes, as the plan names them.
const ProwlerTablesVersion = "5.48.0"
ProwlerTablesVersion is the Prowler release whose source the scanner's tables of what each check reads were taken from, for AWS by scripts/prowler-check-reads.py and for Google Cloud from each check's clients. Prowler is the one on PATH, of whatever release, so `draugr doctor` says when it is another one, and tool-bump's scheduled run raises an issue when Prowler publishes a newer one, which is the cue to regenerate the tables and move this.
A quoted literal on a line of its own: tool-bump reads it with grep.
Variables ¶
var ( // RuntimeGo is the Go toolchain, which a tool analyzing Go source runs to load a module's // packages. RuntimeGo = Runtime{Binary: "go", Name: "Go"} // RuntimeNode is Node, which runs a tool installed as an npm package. RuntimeNode = Runtime{Binary: "node", Name: "Node"} )
The runtimes a tool in the catalog runs on.
var ErrRuntimeMissing = errors.New("this host does not have the runtime the tool is built with")
ErrRuntimeMissing marks an install that failed because this host lacks the runtime a tool is built with, rather than because of the tool, the network or the pin.
The distinction is what lets `draugr tools install` with no arguments mean "everything this host can have". Asking for a named tool and being told it worked has to stay a guarantee, so a named install still fails; asking for what is available should not refuse nine installs to report that a tenth needs a toolchain nobody asked for.
Three runtimes reach this: the Go toolchain, npm and Python. Each is absent or too old in the same way and for the same kind of reason.
var RuntimeDocker = Runtime{Binary: "docker", Name: "Docker"}
RuntimeDocker is Docker, which runs a tool from its container image.
Functions ¶
func BinDir ¶ added in v0.8.0
BinDir is Draugr's managed tool directory: bin/ under $DRAUGR_HOME when it is set, and ~/.draugr/bin otherwise.
The Python and Node environments sit beside it, under the same directory, because the install derives their place from this one.
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 Current ¶ added in v0.158.1
Current reports whether a tool is installed in destDir at the version an install of version would fetch, unchanged since Draugr wrote it, and returns that version. An empty version means the one Draugr ships.
It is the test InstallVersion applies before leaving a tool alone, so a plan built from it and the install that follows agree about what is current. A copy on PATH that Draugr did not install is not current by this test, whatever version it reports, because nothing recorded what it is.
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 DescribeFor ¶ added in v0.77.0
DescribeFor renders a level for one named tool.
One answer for everything external, because the row it fills is a row of facts about where each binary came from and that is the fact. Whether Draugr could have installed this one is a real distinction and it is carried where it changes what somebody does: a scan offers the command under TRY only for the tools the command can obtain, and `doctor` answers it in full.
The tool argument stays. Every other level's wording is the same for every tool, and this one reads the tool to decide nothing today, but the signature is what the caller has and the levels are what may gain a tool-specific answer.
func GoToolchain ¶ added in v0.165.2
GoToolchain is the oldest Go release a Go-built tool is built with, as goX.Y.Z, or "" for a tool that is not built with Go.
func GoToolchainBehind ¶ added in v0.165.2
GoToolchainBehind reports whether buildGo, the Go a copy of a tool was built with, is older than the release GoToolchain names for it. False for a tool not built with Go and for a buildGo that is not a Go version, such as the empty string a binary with no build information reads as.
func GoVersion ¶ added in v0.114.0
GoVersion is the pinned version of a tool built with the Go toolchain.
func GovulncheckVersion ¶ added in v0.114.0
GovulncheckVersion reads govulncheck's own version from its `-version` output.
That output names two versions, the toolchain's first:
Go: go1.26.7 Scanner: govulncheck@v1.5.0
Taking the first semver-looking token reports the Go toolchain as the scanner's version. A number that is real, plausible, and about something else, which then travels into every report the scanner produces. The Scanner line is read instead, and an output without one yields nothing rather than the wrong thing.
func GrypeDBOK ¶ added in v0.91.0
GrypeDBOK reports whether Grype has a usable vulnerability database, and when it was built.
`valid` is Grype's own verdict and the only one worth reporting: a database file can exist, be readable, and still be one Grype will refuse to scan with because it is too old or its schema belongs to a version of the tool that is no longer served.
func Installable ¶ added in v0.8.0
func Installable() []string
Installable returns the names of the tools `tools install` can provision, sorted.
func InstalledCopy ¶ added in v0.162.0
InstalledCopy reports whether path, where name was found, is the copy `draugr tools install` put in destDir. That holds when path sits in destDir and `draugr tools uninstall` would remove name from there. A copy anywhere else was installed some other way, whatever destDir holds.
func LatestGo ¶ added in v0.165.2
LatestGo is the newest stable Go release go.dev publishes, as goX.Y.Z.
func ManagedVersion ¶ added in v0.114.0
ManagedVersion is the pinned version of a tool provisioned through one of the language-package paths, or "" for anything obtained as a release archive or not managed at all.
One place to ask, because the callers that need it, the install plan, `tools list`, the up-to-date check, each named the paths individually, and a path added later joined none of them.
func NodeVersion ¶ added in v0.94.0
NodeVersion is the pinned version of a tool obtained as an npm package.
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 PinnedVersion ¶ added in v0.123.0
PinnedVersion is the version Draugr installs for a tool, whichever way it is packaged.
func PlannedCheck ¶ added in v0.158.1
PlannedCheck names the check an install of version will make, before it runs, in the words the install's result uses. Empty when Draugr cannot install the tool.
func PlannedVersion ¶ added in v0.158.1
PlannedVersion is the version an install of version would fetch, and false when Draugr cannot install that tool at that version on this platform. An empty version means the one Draugr ships.
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 PointToolWritesUnderDraugrHome ¶ added in v0.189.5
func PointToolWritesUnderDraugrHome() error
PointToolWritesUnderDraugrHome sets, when DRAUGR_HOME is set, the variable each installed tool reads for where it writes, so a scan run with a home directory it cannot write to still runs. A variable already set is left alone: whoever set it chose that place.
For the process, and so for every tool it starts, `doctor`'s version probes and the warm-up before a scan included. Without DRAUGR_HOME nothing changes, and each tool keeps its own default, which another install of the same tool shares.
func Provisionable ¶ added in v0.89.0
Provisionable reports whether `draugr tools install` can obtain this tool, by any of its methods: a release download, a Python package, a Node package or a Go module.
func PullCommand ¶ added in v0.187.0
PullCommand is the command that puts an image tool's image on this machine.
func PythonVersion ¶ added in v0.89.0
PythonVersion is the pinned version of a tool obtained as a Python package.
func ReadBuildGo ¶ added in v0.165.2
ReadBuildGo is the Go release a binary was built with, read from the build information the Go linker writes into it, or "" when path is not a Go binary or cannot be read.
The binary's own answer is the only reliable one. `govulncheck -version` prints the Go on PATH, which is not the Go whose go/types decides which modules it can load.
func RuntimeMissing ¶ added in v0.123.0
RuntimeMissing marks an error as one of those without changing what it says.
Wrapping with %w would append the sentinel's own sentence to a message that has already said the same thing more precisely, and the reader gets the specific one. This keeps the text theirs and makes the classification something the caller can test for.
func ScanDataDir ¶ added in v0.153.0
ScanDataDir is where a scanner keeps what it writes for tool at scan time, or "" when it writes nothing or there is no home directory.
func SemgrepVersion ¶ added in v0.8.0
func SemgrepVersion() string
SemgrepVersion is the pinned Semgrep version.
func UnderDraugrHome ¶ added in v0.189.5
UnderDraugrHome reports whether path is one PointToolWritesUnderDraugrHome chose, under the data directory DRAUGR_HOME names, so the setting that moves it is DRAUGR_HOME and not the tool's own.
func Uninstall ¶ added in v0.153.0
Uninstall removes what r lists, the caches too when withCaches is set, and then drops the tool from destDir's install record. A path that cannot be removed stops it before the record changes, so a tool half removed is still listed as installed and a second run can finish it.
func Uninstallable ¶ added in v0.153.0
Uninstallable lists the tools Draugr installed into destDir: those in its install record, and any provisionable tool whose binary is there without one, since the record is best-effort and destDir holds nothing Draugr did not put there. Sorted.
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 labeled, 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 Drift ¶ added in v0.123.0
type Drift struct {
// Tool is the tool's name as Draugr and its own command line spell it.
Tool string
// Pinned is the version this build installs.
Pinned string
// Latest is what the upstream publishes now, empty where the question could not be answered.
Latest string
// PinnedGo is the Go release a Go-built tool is built with (GoToolchain), and LatestGo the
// newest stable release go.dev publishes. Both empty for a tool not built with Go.
PinnedGo string
LatestGo string
// Err is why Latest or LatestGo is empty. A network that refused is a different answer from
// "current", and reporting the second for the first is how a checker comes to report
// everything current while reaching nothing.
Err error
}
Drift is one tool, what Draugr pins, and what its upstream publishes.
func Outdated ¶ added in v0.123.0
Outdated compares every pinned tool against its upstream, in name order.
One entry per tool whatever happened, including the ones that could not be reached. A list that silently omits a tool nobody could ask about is a list that says everything is fine.
func (Drift) Behind ¶ added in v0.123.0
Behind reports whether the upstream has moved past the pin, or go.dev past the Go minor release a Go-built tool is built with.
Only a difference, never an ordering. Version schemes here are not comparable to each other and a pin ahead of its upstream is a real state, a release withdrawn after Draugr pinned it, which somebody needs to see rather than have reported as current.
func (Drift) GoBehind ¶ added in v0.165.2
GoBehind reports whether go.dev's newest stable Go is another language version than the one a Go-built tool is built with, as go1.28 is to go1.27.3.
The language version and not the release, because a Go only changes which modules the tool can load at a new language version. A patch release loads the same modules, and calling the tool behind for one would have it rebuilt for nothing.
type GoSpec ¶ added in v0.114.0
type GoSpec struct {
// Command is the package path of the command to build.
Command string
}
GoSpec describes a tool built from its module with the Go toolchain.
Some tools publish no release binary at all. govulncheck is distributed only as a package path, `go install golang.org/x/vuln/cmd/govulncheck`, with no archives on any release page, which is the same position Semgrep is in on PyPI and retire.js is in on npm. A tool Draugr asks a control to run and then cannot obtain is a control that needs a separate installation story, and most people will simply not have the control.
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
// Verified is the level recorded for this install, the one a scan's attestation reports.
Verified Level
// Checked names the check the install passed, one of the Check constants. CheckNone when
// nothing verified it.
Checked string
// SignatureVerified is true when an upstream cosign signature was verified.
SignatureVerified bool
// ProvenanceNote says why the install was checked less strongly than the plan expected, such as
// cosign being absent or the pinned set not applying. Empty when the plan's check was made.
ProvenanceNote string
// AlreadyPresent is true when the requested build was already installed and left untouched.
AlreadyPresent bool
// Toolchain is the Go release a Go-built tool was built with, as goX.Y.Z. Empty for every other
// tool.
Toolchain string
}
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 Kind ¶ added in v0.123.0
type Kind string
Kind is a way of finding the newest published version.
const ( // KindGitHubRelease reads the repository's latest *release*, which is what most projects // publish and what their users are told to install. KindGitHubRelease Kind = "github-release" // KindGitHubTag reads the newest semver *tag* instead. // // For a repository holding several modules the release marked latest is whichever was // published most recently, which is not the newest version of the command Draugr installs: // golang/vuln answers v1.1.4 there while its newest tag is v1.8.0. A resolver that trusted // the release would hold govulncheck seven minor versions back and report itself current. KindGitHubTag Kind = "github-tag" // KindPyPI reads the version PyPI serves as current. KindPyPI Kind = "pypi" // KindNPM reads the version tagged `latest` in the npm registry. KindNPM Kind = "npm" )
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 NodeSpec ¶ added in v0.94.0
type NodeSpec struct {
// Package is the name on npm.
Package string
// Pins names the generated pair under nodepins/, without the suffixes.
Pins string
// Command is the executable the package provides under node_modules/.bin.
Command string
}
NodeSpec describes a tool obtained as an npm package.
type NucleiTemplateSet ¶ added in v0.131.0
type NucleiTemplateSet struct {
Present bool // the directory holds templates Nuclei can load
Version string // empty where Nuclei could not say, which happens with templates present
Dir string
}
NucleiTemplateSet is what `nuclei -templates-version` says is installed, checked against the directory it names.
func NucleiTemplates ¶ added in v0.131.0
func NucleiTemplates(out []byte) NucleiTemplateSet
NucleiTemplates reads `nuclei -templates-version` and confirms against the directory.
type PythonSpec ¶ added in v0.89.0
type PythonSpec struct {
// Package is the distribution name on PyPI.
Package string
// Pins names the generated requirements file under pythonpins/, without the extension.
Pins string
// MinPythonMinor is the oldest Python 3 minor this package supports.
MinPythonMinor int
}
PythonSpec describes a tool that ships as a Python package rather than a release binary.
Some scanners publish no binary at all: Semgrep's GitHub releases carry zero assets, and it exists as PyPI wheels, a Docker image and a Homebrew formula. Rather than leaving those tools outside `tools install`. Which makes one control's provisioning everybody's special case, Draugr builds a virtual environment it owns and installs the pinned set into it.
The verification floor is the same one a release archive gets, and there is more of it: every artifact in the resolved tree carries the SHA-256 PyPI publishes, so the transitive dependencies are pinned too, which a single checksum over one archive does not do.
func PythonTool ¶ added in v0.89.0
func PythonTool(name string) (PythonSpec, bool)
PythonTool reports the spec for a tool obtained as a Python package.
type Removal ¶ added in v0.153.0
type Removal struct {
Name string
// Version is what the install record says was installed, or "" where the binary is in Draugr's
// directory with no record beside it.
Version string
Files []RemovedPath
Caches []RemovedPath
}
Removal is what uninstalling one tool takes off this machine: the files Draugr put under ~/.draugr for it, and separately the caches the tool keeps for itself.
func PlanUninstall ¶ added in v0.153.0
PlanUninstall describes what removing name from destDir takes off the machine. Only paths that exist are listed. The second result is false when Draugr did not install name there.
type RemovedPath ¶ added in v0.153.0
RemovedPath is one file or directory an uninstall removes, with its size on disk.
type Runtime ¶ added in v0.162.2
type Runtime struct {
// Binary is the executable looked up on PATH, e.g. "go".
Binary string
// Name is what a reader calls it, e.g. "Go".
Name string
}
Runtime is a program a tool runs on.
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
// BuildGo is the Go release the binary was built with, read for a tool Draugr builds with Go
// (GoToolchain). Empty for any other tool, and where the file carries no build information.
BuildGo string
// Unwritable lists the places the tool writes as it runs that cannot be written, each of which
// fails a scan as surely as the tool being absent. Empty where every such place can be, or
// nobody asked.
Unwritable []Unwritable
}
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
// VersionFrom reads the version out of the probe's output, for a tool that names more than
// one. Nil takes the first semver-looking token, which is right for almost everything.
VersionFrom func([]byte) string
// ProbeEnv is layered over the environment for the probes below, each "K=V".
//
// For a tool that treats "what version are you" as an opportunity to call home. Semgrep does:
// `semgrep --version` contacts semgrep.dev to see whether a newer release exists, and Draugr
// asks on every scan, so the question would reach the network on a machine that has said it
// has none. Disabling that returns the same answer.
ProbeEnv []string
// 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
// Runtime is the program the tool runs on, which has to be on PATH beside it. The zero value
// is a tool that needs nothing else to run.
//
// Not the same as how the tool is installed. gosec arrives as a release binary and still loads
// a module's packages with `go`, so a host with gosec and no Go has a gosec that cannot run.
Runtime Runtime
// Image is the container image the tool runs from, pinned by digest, for a tool Draugr runs with
// `docker run` rather than from PATH. Binary is then the name Draugr knows the tool by, and the
// tool is present when the local Docker daemon holds this image. Empty for every other tool.
//
// Pinned by digest because a tag can be pushed again: a scan that ran one build of the tool's
// rules yesterday would run another today under the same name, and the report could not say which.
Image string
// ImageVersion is the tool's release that Image holds, reported as its version when the image is
// present. A digest names exactly one build, so the release is known without running it.
ImageVersion string
}
Tool describes an external executable a scanner shells out to.
type Unwritable ¶ added in v0.189.5
type Unwritable struct {
// Path is where the tool writes, as the variable or the tool's default names it.
Path string
// Var is the variable that moves it.
Var string
// Named is true where Var was set to Path by somebody other than Draugr, so Var is what to
// change; otherwise Path is the tool's default or under DRAUGR_HOME, and DRAUGR_HOME is.
Named bool
// Stays is true where DRAUGR_HOME does not move Path, so Var is what to change whether or not
// anybody set it.
Stays bool
}
Unwritable is a place a tool writes that it will not be able to.
func UnwritableFor ¶ added in v0.189.5
func UnwritableFor(tool string) []Unwritable
UnwritableFor returns every place the tool writes as it runs that cannot be written, in the order toolWrites lists them, or nil when every one can or the tool writes nowhere Draugr knows of. Every place rather than the first, so one doctor run names all a user has to move. A place that does not exist yet is judged by the nearest directory above it that does, since the tool makes the rest.
Tested by writing, not by reading permission bits: a read-only mount, an ACL and running as root each make the bits say something other than what a write would do.
type Upstream ¶ added in v0.123.0
type Upstream struct {
// Kind is how the newest version is read. Each is a different answer to the same question and
// the difference is not cosmetic: see KindGitHubTag.
Kind Kind
// Ref names the thing to ask about: "owner/repo" on GitHub, a package name on PyPI or npm.
Ref string
}
Upstream says where a tool's releases are published and how to read the newest one.
In Draugr rather than in a workflow, so one implementation answers both a person asking what is out of date and a pipeline proposing a bump. The alternative is release-API handling written twice, in Go and in YAML, where only the half somebody runs by hand stays true.
func UpstreamFor ¶ added in v0.123.0
UpstreamFor reports where a tool is published.