cmd

package
v4.24.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: AGPL-3.0 Imports: 117 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// PropEnrichedFrom is the digest of the document this was made from.
	PropEnrichedFrom = "vulnetix:bom/enriched-from"
	// PropEnrichedAt is when.
	PropEnrichedAt = "vulnetix:bom/enriched-at"
	// PropEnrichedBy is the tool and version that did it.
	PropEnrichedBy = "vulnetix:bom/enriched-by"
	// PropOriginalSignature points at the input's preserved signature.
	PropOriginalSignature = "vulnetix:bom/original-signature"
)

Property names recording what enrichment did.

View Source
const (
	// ExitOK — the command succeeded.
	ExitOK = 0
	// ExitFailure — the command failed, or a policy gate breached. Every error
	// that does not name its own code lands here, which is what the CLI did
	// before this file existed.
	ExitFailure = 1
	// ExitUsage — a local argument or configuration error, before any
	// meaningful work was attempted.
	ExitUsage = 2
	// ExitIndeterminate — the gate ran but could not reach a verdict, because
	// the backend state it needs is stale or absent. NOT a pass and NOT a
	// breach.
	ExitIndeterminate = 3
	// ExitPlanBlocked: `config plan` or `config apply` produced a plan with
	// blocking conditions (invalid document, metadata.org naming another
	// tenant, an object owned by another manager), so nothing was applied.
	// It shares 3 with ExitIndeterminate on purpose: in both, nothing is wrong
	// with the code under test; the pipeline's configuration has to be fixed
	// before a verdict or an apply is possible. The two never come from the
	// same command, so a pipeline reads 3 by the command it ran.
	ExitPlanBlocked = 3
)

Process exit codes. These are a contract with every pipeline in the field; changing what one means is a breaking change to somebody's CI.

Variables

This section is empty.

Functions

func AgentHookActive

func AgentHookActive() bool

AgentHookActive reports whether the process is answering a hook. Read by printBanner and startupHooks.

func CommandAcceptsFlag

func CommandAcceptsFlag(path []string, flag string) (bool, error)

CommandAcceptsFlag reports whether the command at path (the arguments after `vulnetix`, subcommands only, for example {"gha", "publish", "campaigns"}) defines the flag, given without its leading dashes. It exists for tools/actiongen, which checks that every flag a generated GitHub Action passes is one the command accepts.

func CommandPaths added in v4.23.0

func CommandPaths() []string

CommandPaths lists every runnable command, as words after `vulnetix`.

func Execute

func Execute() error

func ExitCode

func ExitCode(err error) int

ExitCode resolves the process exit code for an error returned by Execute.

errors.As, not a bare type assertion. A future `fmt.Errorf("...: %w", err)` wrapper anywhere in a call chain would make an assertion miss, silently demoting a 3 to a 1 — and a demoted 3 reads to a pipeline as an ordinary build failure rather than "the gate could not tell". That is the whole distinction this file exists to preserve, so it is asserted in exit_codes_test.go.

func LSPActive

func LSPActive() bool

LSPActive reports whether the process is serving LSP. Read by startupHooks.

func LoadFromMemory

func LoadFromMemory(rootPath string, freshExploits, freshAdvisories, freshVulns bool) error

LoadFromMemory reconstructs the scan pretty output from .vulnetix/sbom.cdx.json. When fresh* flags are true, selective API calls are made to refresh that data.

Types

type AIBOMPassOptions

type AIBOMPassOptions struct {
	RootPath         string
	Depth            int
	Ignore           []string
	CatalogPath      string
	NoBuiltinCatalog bool
	// Passes selects which detection passes run; the zero value runs none, so
	// callers must be explicit.
	Passes           aibomPasses
	IncludeHome      bool
	IncludeSystem    bool
	SystemRoot       string
	CommitMax        int
	RespectGitignore bool
	// SpecVersion defaults to 1.7.
	SpecVersion string
	// Upload submits the AIBOM to the backend when authenticated.
	Upload bool
	GitCtx *gitctx.GitContext
	// Authoring is what the caller stated about the document's identity and
	// content. The zero value derives everything.
	Authoring cdx.AuthoringInputs
}

AIBOMPassOptions is the AIBOM owner's entry contract. The `aibom` command builds it from its flags; `scan` builds it with the pass defaults. Both go through runAIBOMPass, so there is one definition of "detect AI usage".

type AIBOMPassResult

type AIBOMPassResult struct {
	Detections  cyclonedx.AIDetections
	BOM         []byte
	SpecVersion string
	// Suppressed counts AI components dropped by an active ignore rule. They are
	// skipped outright rather than labelled: an ignored AI component is also
	// never shown in the console.
	Suppressed int
}

AIBOMPassResult carries what the caller renders or writes.

type AttestVerifyOptions

type AttestVerifyOptions struct {
	// ArtifactPath is the file to verify.
	ArtifactPath string
	// SignaturePath, CertificatePath and EnvelopePath override sidecar
	// discovery. Empty means "look beside the artefact".
	SignaturePath, CertificatePath, EnvelopePath string
	// Identity is the exact certificate subject required; IdentityRegex is the
	// pattern form.
	Identity      string
	IdentityRegex string
	// Issuer is the OIDC issuer the certificate must name. A shortcut name is
	// accepted as well as a URL.
	Issuer string
	// TrustedRootPath overrides trust-anchor discovery.
	TrustedRootPath string
	// Require names checks that must have been performed.
	Require []string
	// Strict requires the verification to be fully pinned.
	Strict bool
}

AttestVerifyOptions is the options struct for the one entry point into attestation verification.

type BOMCorpusOptions

type BOMCorpusOptions struct {
	// Paths are the files, directories or globs to read.
	Paths []string
	// Recursive walks directories to any depth.
	Recursive bool
	// MaxDepth bounds a recursive walk; zero means unlimited.
	MaxDepth int
}

BOMCorpusOptions is the options struct for building a corpus index.

type BOMCorpusResult

type BOMCorpusResult struct {
	Index     *bom.Index
	Collected *bom.Collected
}

BOMCorpusResult is a built index plus what it could not read.

type BOMEnrichOptions

type BOMEnrichOptions struct {
	// InputPath is the document to enrich.
	InputPath string
	// OutPath receives the enriched document.
	OutPath string
	// VEXPaths are VEX documents to apply.
	VEXPaths []string
	// NoLicenses, NoVulns and NoVEX skip a pass.
	NoLicenses, NoVulns, NoVEX bool
	// KeepOriginal writes the input beside the output.
	KeepOriginal bool
	// Sign re-signs the result with this machine's ambient identity.
	Sign bool
}

BOMEnrichOptions is the options struct for the enrichment pass.

type BOMEnrichResult

type BOMEnrichResult struct {
	Document *bom.Document `json:"-"`
	// LicensesResolved is how many components gained a licence.
	LicensesResolved int `json:"licensesResolved"`
	// VulnerabilitiesAttached is how many entries were added.
	VulnerabilitiesAttached int `json:"vulnerabilitiesAttached"`
	// VEX carries the total/effective/suppressed split when VEX was applied.
	VEX *VEXPassResult `json:"-"`
	// Written names every file produced.
	Written []string `json:"written,omitempty"`
	// Warnings are passes that degraded rather than failed.
	Warnings []string `json:"warnings,omitempty"`
	// Signature is the outcome of re-signing, when asked for.
	Signature cdxsign.Result `json:"-"`
}

BOMEnrichResult reports what enrichment changed.

type BOMImportOptions

type BOMImportOptions struct {
	// Path is the document to read; "-" reads stdin.
	Path string
	// OutPath, when set, receives the normalised CycloneDX document.
	OutPath string
	// Deployment tags the document with where it is deployed and what owns it.
	Deployment scanopts.DeploymentContext
	// Verify, when set, checks the document's attestation before trusting it.
	// Nil skips verification entirely — reading a document does not imply
	// believing it, and conflating the two would make every parse a trust
	// decision the caller did not ask for.
	Verify *AttestVerifyOptions
}

BOMImportOptions is the options struct for the one entry point into SBOM reading. See the file header for why this exists.

type BOMImportResult

type BOMImportResult struct {
	Document *bom.Document
	// Written is the path the normalised document was written to, or "".
	Written string
	// Verification is the attestation result when the caller asked for one.
	Verification *attest.Result
}

BOMImportResult is what a successful import produced.

type CBOMPassOptions

type CBOMPassOptions struct {
	RootPath         string
	Depth            int
	Ignore           []string
	CatalogPath      string
	NoBuiltinCatalog bool
	// Passes selects which detection passes run; the zero value runs none.
	Passes           cbomPasses
	RespectGitignore bool
	// SpecVersion defaults to 1.7.
	SpecVersion string
	// Upload submits the CBOM to the backend when authenticated.
	Upload bool
	GitCtx *gitctx.GitContext
	// Authoring is what the caller stated about the document's identity and
	// content. The zero value derives everything.
	Authoring cdx.AuthoringInputs
}

CBOMPassOptions is the CBOM owner's entry contract, mirroring AIBOMPassOptions: the `cbom` command builds it from its flags, `scan` builds it with the pass defaults, and runCBOMPass is the only implementation.

type CBOMPassResult

type CBOMPassResult struct {
	Detections  cyclonedx.CryptoDetections
	BOM         []byte
	SpecVersion string
	// Suppressed counts crypto assets dropped by an active ignore rule, so the
	// caller can say so rather than silently reporting a smaller inventory.
	Suppressed int
}

CBOMPassResult carries what the caller renders, writes or gates on.

type CommandManifest

type CommandManifest struct {
	Commands map[string]ManifestCommand `json:"commands"`
}

CommandManifest is the serialized shape of the Cobra tree.

func BuildCommandManifest

func BuildCommandManifest() CommandManifest

BuildCommandManifest walks the live root command and records every command path with its flags. Persistent flags are attributed to the command that declares them and to every descendant, because that is how a user sees them.

type EcoGroups

type EcoGroups struct {
	Configured []EcoStatus
	Available  []EcoStatus
}

type EcoStatus

type EcoStatus struct {
	Ecosystem pfw.Ecosystem
	Path      string
}

type ExitCodeError

type ExitCodeError interface {
	error
	ExitCode() int
}

ExitCodeError is an error that names the process exit code it should produce.

Absent this interface an error still exits 1, which is what every command in the tree did before jail existed and must keep doing.

type GateBreach

type GateBreach struct {
	Gate    string // "malware" | "exploits" | "severity" | "eol"
	Count   int
	Message string // pre-formatted, ready to print
}

GateBreach captures one quality gate's failure details.

type JailRunOptions

type JailRunOptions struct {
	Mode string

	RootPath  string
	Repo      string
	Branch    string
	RuleUuids []string

	// KnownSnapshotUuids names scanner runs the caller just created, so a
	// scan-then-gate in one invocation is not defeated by read-replica lag.
	KnownSnapshotUuids []string

	// Artefacts
	VexPath    string
	VexFormat  string
	SarifPath  string
	WriteVex   bool
	WriteSarif bool

	// Gate behaviour
	NoFail          bool
	StalenessDays   int
	OnStale         string
	MaxLookbackDays int

	// Exempt mode
	ExemptRuleUuid         string
	ExemptReason           string
	ExemptExpires          time.Duration
	ExemptDeactivate       string
	ExemptDeactivateReason string

	BaseURL string
	Output  string
	Timeout time.Duration
	Stdout  io.Writer
	Stderr  io.Writer
}

JailRunOptions is the single input to the jail capability.

type JailRunResult

type JailRunResult struct {
	Response  *vdb.CliJailResponse
	Exemption *vdb.CliJailExemptResponse
	Artefacts []string
	ExitCode  int
}

JailRunResult is what the caller needs to render and to decide an exit code.

type JailUsageError

type JailUsageError struct {
	// contains filtered or unexported fields
}

JailUsageError is a local argument or configuration failure: an unparseable duration, a scope override on an assess run, an unwritable artefact path, no credentials.

Its exit code 2 is deliberately scoped to this command. Cobra's own usage errors across the rest of the tree keep exiting 1; promoting them globally would change the contract of every pipeline in the field.

func (*JailUsageError) Error

func (e *JailUsageError) Error() string

func (*JailUsageError) ExitCode

func (e *JailUsageError) ExitCode() int

func (*JailUsageError) Unwrap

func (e *JailUsageError) Unwrap() error

type JailVerdictError

type JailVerdictError struct {
	Verdict string
	Code    int
	Summary vdb.CliJailSummary
}

JailVerdictError is returned when the gate reports jailed or indeterminate.

The command has already rendered the full verdict block, so Execute() suppresses the generic "Error:" line for it the same way it does for a quality-gate breach.

func (*JailVerdictError) Error

func (e *JailVerdictError) Error() string

func (*JailVerdictError) ExitCode

func (e *JailVerdictError) ExitCode() int

ExitCode reports 1 for a breach and 3 for an indeterminate verdict.

type LicensePolicyFlags

type LicensePolicyFlags struct {
	Mode      string
	AllowCSV  string
	AllowFile string
	// PolicyFile and ExceptionsFile are the declarative forms
	// (--policy-file / --exceptions-file). Empty means "discover the default
	// path under the scanned root, and fall back to the built-in policy".
	PolicyFile     string
	ExceptionsFile string
}

LicensePolicyFlags is the license policy as the scan-family flags express it (`--license-mode`, `--allow`, `--allow-file`). It travels through the scan pipeline to the license owner so a scan and a standalone `license` run apply the same policy.

type LicenseRunOptions

type LicenseRunOptions struct {
	RootPath string
	// Mode is the license.EvalConfig mode ("inclusive" or "individual"). Empty
	// defaults to inclusive.
	Mode string
	// AllowCSV / AllowFile are the two spellings of the allow list; AllowFile
	// wins when both are set.
	AllowCSV  string
	AllowFile string
	// SeverityThreshold filters findings below the given severity.
	SeverityThreshold string
	// PolicyFile is a declarative licence policy (.vulnetix/license-policy.yaml).
	// Empty means the default policy, which reproduces what the evaluator did
	// before policies existed.
	PolicyFile string
	// ExceptionsFile is the approved-exception set
	// (.vulnetix/license-exceptions.yaml). Empty means no exceptions.
	ExceptionsFile string
	// Project selects per-project policy overrides, from --project.
	Project string
	// Packages are the parsed manifest packages to analyse.
	Packages []scan.ScopedPackage
	// ManifestGroups carries the dependency graph used for introduced-via chains.
	ManifestGroups []scan.ManifestGroup
	// LicensedPackages lets a caller reuse an earlier license.DetectLicenses
	// result (the scan pipeline resolves licenses before its SCA round-trip so
	// the payload can carry them). Empty means "detect now".
	LicensedPackages []license.PackageLicense
	// Memory, when non-nil, receives this run's findings and the resolution of
	// findings that have disappeared. The caller owns saving it.
	Memory *memory.Memory
	GitCtx *gitctx.GitContext
	// Stderr receives warnings; nil means os.Stderr.
	Stderr io.Writer
}

LicenseRunOptions is everything the license pipeline needs from a caller. The `license` command builds it from its own flags; `scan --evaluate-licenses` builds it from the scan-family license flags and passes the packages it has already parsed. Both go through runLicensePipeline so there is exactly one implementation of "what does a license finding mean".

type LicenseRunResult

type LicenseRunResult struct {
	Result           *license.AnalysisResult
	LicensedPackages []license.PackageLicense
	// FindingVulnerabilities are this run's open license findings as CycloneDX
	// vulnerability entries.
	FindingVulnerabilities []cdx.Vulnerability
	// VEXVulnerabilities are the resolution attestations read back from memory.
	// They are kept separate from the findings because the scan pipeline feeds
	// them through cdx.ApplyVEXAnalysis (which annotates an existing entry rather
	// than appending a twin), while the license command merges both into the BOM
	// in one call.
	VEXVulnerabilities []cdx.Vulnerability
	// StateChanges are the memory transitions this run produced (new findings,
	// resolutions). Empty when Options.Memory was nil.
	StateChanges []memory.StateChange
}

LicenseRunResult is the pipeline's output. Callers decide what to do with it: the `license` command merges the CycloneDX entries into the on-disk BOM, the scan pipeline appends them to the BOM it is already building in memory.

func (*LicenseRunResult) CDXVulnerabilities

func (r *LicenseRunResult) CDXVulnerabilities() []cdx.Vulnerability

CDXVulnerabilities is the findings and their VEX attestations in one slice, for callers that merge everything into the BOM at once.

func (*LicenseRunResult) LicenseSpdxIDByPackage

func (r *LicenseRunResult) LicenseSpdxIDByPackage() map[string]string

LicenseSpdxIDByPackage maps "name@version" → resolved SPDX id for every package whose license was determined. It is what the CycloneDX component population and the /v2/cli.sca payload both consume.

type ManifestCommand

type ManifestCommand struct {
	Short      string   `json:"short"`
	Flags      []string `json:"flags"`
	Deprecated []string `json:"deprecatedFlags,omitempty"`
	Subs       []string `json:"subcommands,omitempty"`
}

ManifestCommand describes one command path (e.g. "auth login").

type MultiPolicyBreachError

type MultiPolicyBreachError struct {
	Breaches []GateBreach
}

MultiPolicyBreachError is returned when one or more quality gates are breached.

func (*MultiPolicyBreachError) Error

func (e *MultiPolicyBreachError) Error() string

type PolicyBreachError

type PolicyBreachError interface {
	error
	// contains filtered or unexported methods
}

PolicyBreachError is implemented by all quality-gate breach errors. Execute() uses this interface to suppress redundant error printing — the command itself has already printed the breach details.

type SeverityBreachError

type SeverityBreachError struct {
	// contains filtered or unexported fields
}

SeverityBreachError is returned when --severity threshold is breached. It signals main() to exit with code 1 without printing a redundant error message.

func (*SeverityBreachError) Error

func (e *SeverityBreachError) Error() string

type VEXPassOptions

type VEXPassOptions struct {
	// Paths are the VEX files or directories to read.
	Paths []string
	// BOM is the document to apply statements to. Modified in place.
	BOM *cdx.BOM
	// Console are the rules the Vulnetix console holds for the repository that
	// came from VEX statements (see consoleVEXRules). They are applied with the
	// documents, after those, and a statement a document already makes is not
	// counted twice.
	Console []vex.ConsoleRule
	// Org are the organisation's own statements about this scan's findings (see
	// scanOrgVEX), and Repo the repository the scan is in. Each is checked before
	// it can close anything: see vex.CheckOrgStatements.
	Org  []vex.OrgStatement
	Repo string
}

VEXPassOptions is the options struct for the one entry point into VEX application. See the file header for why this exists.

type VEXPassResult

type VEXPassResult struct {
	// Result carries the total/effective/suppressed split.
	Result *vex.Result
	// Documents is the number of VEX documents read.
	Documents int
	// Statements is the number of statements indexed.
	Statements int
	// Skipped names files under a supplied directory that were not VEX.
	Skipped []string
	// Problems are validation problems found in the supplied documents.
	Problems map[string][]vex.Problem
	// ConsoleStatements is how many console statements were applied alongside
	// the documents, ConsoleDuplicates how many were left out because a document
	// or another console rule already made them, and ConsoleSkipped how many
	// rules had no status this CLI reads.
	ConsoleStatements, ConsoleDuplicates, ConsoleSkipped int
	// OrgCheck says what became of the organisation's statements, and OrgHeld
	// names the findings left open because a statement about them was overruled.
	OrgCheck *vex.OrgCheck
	OrgHeld  []vex.HeldFinding
	// Raw holds the exact bytes of every document read, so a caller can send
	// them to Vulnetix unchanged (see ingestVEX).
	Raw []vexRawDocument
}

VEXPassResult is what applying a statement set produced.

Source Files

Directories

Path Synopsis
Command vulnetix-sensor is the Vulnetix runtime sensor.
Command vulnetix-sensor is the Vulnetix runtime sensor.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL