scan

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: Apache-2.0 Imports: 38 Imported by: 0 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

Overview

Package scan builds a Flightbay bundle from a code repository instead of a live cluster: plain manifests, Helm charts, Kustomize overlays and the Argo CD and Flux objects that point at them. The bundle is a normal one (header, discovery, resources, coverage, manifest with SHA-256s) marked source "repo", so the desk, the Scorecard, reach, search, SQL and Compare all work on it unchanged. It is declared state: there is no status, no pods and no logs, and the checks that need them say so.

Index

Constants

View Source
const (
	SourceAnnotation     = "flightbay.dev/source"      // repo-relative file (the template, for Helm)
	LineAnnotation       = "flightbay.dev/source-line" // line of the document, when known
	RenderedByAnnotation = "flightbay.dev/rendered-by" // yaml, helm <chart>, kustomize <dir>, argocd ..., flux ...
)

Annotations every rendered object carries, so the desk and the CI report can say where it came from.

View Source
const NamespaceAnnotation = "flightbay.dev/namespace"

NamespaceAnnotation on a Chart.yaml sets the namespace a scan renders the chart into when --namespace is not given.

Variables

This section is empty.

Functions

func FileName

func FileName(r *Result, now time.Time) string

FileName is the default bundle name for a scan.

func Load

func Load(b []byte) (*store.Workspace, error)

Load imports a bundle held in memory into a new in-memory workspace, the same way the desk opens one.

func NormalizeRepoURL

func NormalizeRepoURL(u string) string

NormalizeRepoURL reduces the forms a Git remote is written in (https://host/org/repo.git, git@host:org/repo, ssh://git@host/org/repo) to host/org/repo for comparison.

func Plural

func Plural(n int, one, many string) string

Plural picks the word for n.

func RuntimeOnly

func RuntimeOnly(group, resource string) bool

RuntimeOnly reports whether a type exists only at runtime (pods, nodes, events, endpoints), so a repo scan cannot judge its absence.

func SARIFLevel

func SARIFLevel(sev string) string

SARIFLevel maps a check severity to a SARIF level.

func ValidSeverity

func ValidSeverity(s string) bool

ValidSeverity reports whether s is a --fail-on value.

Types

type Failure

type Failure struct {
	Check    string       `json:"check"`
	Area     string       `json:"area"`
	Category string       `json:"category"`
	Severity string       `json:"severity"`
	Title    string       `json:"title"`
	Detail   string       `json:"detail"`
	Guide    string       `json:"guide"`          // a related public field guide
	Docs     string       `json:"docs,omitempty"` // a related product documentation page
	Item     posture.Item `json:"item"`
	File     string       `json:"file"`
	Line     int          `json:"line,omitempty"`
	Renderer string       `json:"renderedBy,omitempty"`
	New      bool         `json:"new"`
}

Failure is one failing object of one Scorecard check, with the file it was declared in.

func (Failure) Key

func (f Failure) Key() string

Key identifies a failure across two scans: the check and the object.

func (Failure) Object

func (f Failure) Object() string

Object names the item as Kind ns/name.

type FixPackResult

type FixPackResult struct {
	Files     []string
	Proposals []string
}

FixPackResult lists what a fix pack wrote.

func WriteFixPack

func WriteFixPack(dir string, g Gate, ws *store.Workspace) (*FixPackResult, error)

WriteFixPack writes one YAML file per failing check into dir, with the affected objects' names filled in (Agent reach fixes come fully written), proposals for new objects next to plain-YAML sources under proposals/, and a README.md listing each check, the objects and their source files. The repository's own files are never changed.

type Gate

type Gate struct {
	Repo     *bundle.RepoInfo    `json:"repo,omitempty"`
	Areas    []posture.AreaScore `json:"areas"`
	Failures []Failure           `json:"failures"`
	Baseline string              `json:"baseline,omitempty"` // what --new-only compared with
	Checks   []posture.Check     `json:"-"`
}

Gate is the result of scoring a scan.

func Evaluate

func Evaluate(ws *store.Workspace) Gate

Evaluate scores a scanned workspace with the Scorecard (and Agent reach when that feature is on) and lists every failing object with its source.

func (Gate) CodeQuality

func (g Gate) CodeQuality() []map[string]any

CodeQuality renders the reported failures as a GitLab Code Quality report (the Code Climate issue subset GitLab reads): one issue per failing object.

func (Gate) ExitCode

func (g Gate) ExitCode(threshold string) int

ExitCode is 1 when anything gates at the threshold, else 0.

func (Gate) Gating

func (g Gate) Gating(threshold string) []Failure

Gating returns the failures that count: new ones (all, without a baseline) at or above the threshold. An empty threshold gates nothing.

func (*Gate) MarkNew

func (g *Gate) MarkNew(base Gate, label string) int

MarkNew compares with a baseline gate: failures the baseline already had are not new. It returns how many are new.

func (Gate) Reported

func (g Gate) Reported() []Failure

Reported is what the report shows: only new failures when compared with a baseline, otherwise all.

func (Gate) SARIF

func (g Gate) SARIF(version string) any

SARIF renders the reported failures as a SARIF 2.1.0 log: one result per failing object, one rule per check, located at the file (and line) the object was declared in.

func (Gate) Write

func (g Gate) Write(w io.Writer, format, threshold, version string) error

Write renders the gate in a format: text, json, sarif or github.

type Options

type Options struct {
	Paths       []string // files or directories inside one repository; default "."
	Root        string   // the repository root that source paths are relative to; default the Git top level, else the scanned directory
	Values      []string // FILE (every chart) or CHARTDIR=FILE
	Set         []string // key=value, as helm --set, for every chart
	Overlays    []string // kustomize directories to build; default every overlay that is not only a base
	Env         string   // pick overlays/<env>, values-<env>.yaml, envs/<env>
	Release     string   // Helm release name; default the chart name
	Namespace   string   // namespace for namespaced objects without one; default "default"
	ContextName string   // the synthetic cluster name; default repo:<name>
	RepoURL     string   // treat GitOps sources with this URL as this repository
	HelmFetch   bool     // allow helm dependency update (network)
	Version     string   // collector version for the header
	Log         io.Writer
}

Options control a scan.

type Result

type Result struct {
	Header    bundle.Header
	Cluster   string
	Objects   int
	Inputs    []bundle.Coverage
	Resources []bundle.APIResource
	Picked    []string // environment choices, as printed
	Bundle    []byte   // the bundle, tar.zst
}

Result describes a finished scan.

func Run

func Run(o Options) (*Result, error)

Run scans the repository and returns the bundle.

func RunAtRef

func RunAtRef(o Options, ref string) (*Result, error)

RunAtRef scans the same paths, with the same options, at another commit (such as origin/main), from a temporary git worktree that is removed afterwards. It is how --new-only --base-ref finds what a change introduces.

Jump to

Keyboard shortcuts

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