bundle

package
v0.3.0 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: 21 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 bundle writes and reads Flightbay bundles: a plain tar stream, compressed with zstd and optionally wrapped in age encryption.

Layout rules that make progressive import possible:

  • bundle.json is always the first member;
  • data arrives in bounded chunks, each a complete tar member;
  • a coverage record follows each finished collection;
  • manifest.json, with a sha256 for every member, is always last.

Index

Constants

View Source
const (
	SchemaVersion = 1
	HeaderName    = "bundle.json"
	ManifestName  = "manifest.json"
	RedactionName = "redaction-report.json"
	CollectionLog = "collection-log.jsonl"
	// SignatureName is the customer's signature over manifest.json. It is the
	// only member allowed after the manifest, and it is optional.
	SignatureName = "manifest.sig"
	// LedgerName records what a customer removed in review (flightbay review).
	LedgerName    = "review-ledger.json"
	MaxWindow     = 128 << 20 // stock zstd and tar --zstd open this without extra flags
	DefaultWindow = 8 << 20

	DefaultMaxMember = 512 << 20
)
View Source
const (
	CoverageResource = "resource"
	CoverageLogs     = "logs"
	CoverageEvents   = "events"
	// CoverageDiagnostic is a proxy dump, control-plane debug output or metrics scrape.
	CoverageDiagnostic = "diagnostic"
	// CoverageFlows is a flow log file attached to the bundle (Hubble, Calico,
	// VPC flow logs, generic CSV/JSON) or collected from hubble-relay.
	CoverageFlows = "flows"
	// CoverageInput is one repo scan input: a manifest file, a Helm chart, a
	// Kustomize overlay or a GitOps source (flightbay scan).
	CoverageInput = "input"

	StateComplete  = "complete"
	StateFailed    = "failed"
	StateExcluded  = "excluded"
	StateTruncated = "truncated"
	// StateRemoved marks data the customer took out in review before sending.
	StateRemoved = "removed"
)

Coverage types and states.

View Source
const (
	PathHeader      = "header"
	PathManifest    = "manifest"
	PathResource    = "resource"
	PathLog         = "log"
	PathEvents      = "events"
	PathCoverage    = "coverage"
	PathDiscovery   = "discovery"
	PathRedaction   = "redaction"
	PathCollection  = "collection-log"
	PathDiagnostics = "diagnostics"
	PathFlows       = "flows"
	PathSignature   = "signature"
	PathLedger      = "ledger"
)

Path kinds.

View Source
const SourceRepo = "repo"

SourceRepo marks a bundle built by flightbay scan from a code repository.

Variables

This section is empty.

Functions

func CoveragePath

func CoveragePath(cluster, id string) string

func DiagnosticsPath

func DiagnosticsPath(cluster, kind, ns, pod, file string) string

DiagnosticsPath is clusters/<c>/diagnostics/<kind>/<ns>/<pod>/<file>, or clusters/<c>/diagnostics/<file> when kind is empty. kind is proxies or control-plane.

func DiscoveryPath

func DiscoveryPath(cluster, file string) string

func EventsPath

func EventsPath(cluster string, part int) string

func FlowsPath

func FlowsPath(cluster, format, file string) string

FlowsPath is clusters/<c>/flows/<format>/<file>: a flow log file attached to the bundle, in a format internal/flows reads.

func LogPath

func LogPath(cluster, ns, pod, container, stream string, part int) string

func NewBundleID

func NewBundleID() string

NewBundleID returns a random identifier.

func ResourcePath

func ResourcePath(cluster, group, version, resource string, part int) string

func SafeID

func SafeID(id string) string

SafeID converts an arbitrary identifier into a single safe path segment.

func ValidName

func ValidName(name string) error

ValidName reports whether a member name is safe to extract.

Types

type APIResource

type APIResource struct {
	Group        string   `json:"group"`
	Version      string   `json:"version"`
	Resource     string   `json:"resource"`
	Kind         string   `json:"kind"`
	Namespaced   bool     `json:"namespaced"`
	SingularName string   `json:"singularName,omitempty"`
	ShortNames   []string `json:"shortNames,omitempty"`
	Categories   []string `json:"categories,omitempty"`
}

APIResource describes a collected resource type. It is written to clusters/<name>/discovery/apiresources.json so the desk can serve discovery.

func (APIResource) GroupVersion

func (a APIResource) GroupVersion() string

GroupVersion returns "v1" or "apps/v1".

func (APIResource) Name

func (a APIResource) Name() string

Name returns "pods" or "deployments.apps".

type Coverage

type Coverage struct {
	ID         string   `json:"id"`
	Cluster    string   `json:"cluster"`
	Type       string   `json:"type"`
	Group      string   `json:"group,omitempty"`
	Version    string   `json:"version,omitempty"`
	Resource   string   `json:"resource,omitempty"`
	Kind       string   `json:"kind,omitempty"`
	Namespaced bool     `json:"namespaced,omitempty"`
	Namespace  string   `json:"namespace,omitempty"`
	Pod        string   `json:"pod,omitempty"`
	Container  string   `json:"container,omitempty"`
	Stream     string   `json:"stream,omitempty"`
	Chunks     []string `json:"chunks,omitempty"`
	Items      int      `json:"items"`
	State      string   `json:"state"`
	Reason     string   `json:"reason,omitempty"`
	Source     string   `json:"source,omitempty"`   // repo scan: the input path
	Renderer   string   `json:"renderer,omitempty"` // repo scan: yaml, helm, kustomize, argocd, flux
	// Trimmed counts what the customer removed from this collection in review
	// while keeping the rest of it.
	Trimmed *Trimmed `json:"trimmed,omitempty"`
}

Coverage says what one collection produced, so absence can be told apart from exclusion, failure or truncation.

type Header struct {
	SchemaVersion int             `json:"schemaVersion"`
	BundleID      string          `json:"bundleId"`
	Case          string          `json:"case,omitempty"`
	Collector     string          `json:"collector,omitempty"`
	CaptureStart  time.Time       `json:"captureStart"`
	Contexts      []string        `json:"contexts"`
	Policy        json.RawMessage `json:"policy,omitempty"`
	Planned       []string        `json:"planned,omitempty"`
	Unavailable   []string        `json:"unavailable,omitempty"`
	// Source is "" or "cluster" for a capture and "repo" for a scan of a code
	// repository (flightbay scan): declared state, with no status, pods or logs.
	Source string    `json:"source,omitempty"`
	Repo   *RepoInfo `json:"repo,omitempty"`
	// CollectorSHA256 is the SHA-256 of the collector binary that wrote the
	// bundle, so either side can match it to a signed release.
	CollectorSHA256 string `json:"collectorSha256,omitempty"`
	// PolicySource describes the approved collection policy file, when one was used.
	PolicySource *PolicySource `json:"policySource,omitempty"`
	// Review is set on a bundle the customer trimmed with flightbay review.
	Review *ReviewInfo `json:"review,omitempty"`
}

Header is bundle.json. It is known before collection starts.

func (*Header) Declared

func (h *Header) Declared() bool

Declared reports whether the header describes a repo scan.

type Manifest

type Manifest struct {
	SchemaVersion int               `json:"schemaVersion"`
	BundleID      string            `json:"bundleId"`
	CaptureEnd    time.Time         `json:"captureEnd"`
	Complete      bool              `json:"complete"`
	Errors        int               `json:"errors"`
	Coverage      []string          `json:"coverage"`
	Members       map[string]string `json:"members"`
}

Manifest is manifest.json, written last.

type Member

type Member struct {
	Name   string
	Data   []byte
	SHA256 string
}

Member is one decoded tar member.

type PathInfo

type PathInfo struct {
	Kind, Cluster, Group, Version, Resource, Namespace, Pod, Container, Stream, ID, File, Sub string
	Part                                                                                      int
}

PathInfo classifies a member name.

func ParsePath

func ParsePath(name string) (PathInfo, bool)

ParsePath classifies a member name produced by the helpers above.

type PolicySource

type PolicySource struct {
	File   string `json:"file"`
	SHA256 string `json:"sha256"`
	// Signature is the check of POLICY.sig at collection time; nil when the
	// file was not signed.
	Signature *sign.Result `json:"signature,omitempty"`
	// ChangedBy lists the command-line flags that refined the file.
	ChangedBy []string `json:"changedBy,omitempty"`
}

PolicySource records which collection policy file a capture used and who approved it.

type Reader

type Reader struct {
	Encrypted bool
	// contains filtered or unexported fields
}

Reader decodes a bundle incrementally.

func NewReader

func NewReader(r io.Reader, o ReaderOptions) (*Reader, error)

NewReader starts decoding. Encrypted bundles need an identity.

func (*Reader) Header

func (r *Reader) Header() *Header

Header returns bundle.json once read.

func (*Reader) Manifest

func (r *Reader) Manifest() *Manifest

Manifest returns manifest.json once read.

func (*Reader) ManifestSHA256

func (r *Reader) ManifestSHA256() string

ManifestSHA256 is the hex SHA-256 of manifest.json once read: the one value that identifies the exact content of a bundle.

func (*Reader) Next

func (r *Reader) Next() (*Member, error)

Next returns the next member, io.EOF at the end of the archive.

func (*Reader) Signature

func (r *Reader) Signature(trusted []sign.PublicKey) sign.Result

Signature checks manifest.sig against manifest.json and the trusted keys. Call it after reading to the end. A bundle that also fails Verify is modified however its signature reads.

func (*Reader) Signed

func (r *Reader) Signed() bool

Signed reports whether the bundle carries manifest.sig (read so far).

func (*Reader) Verify

func (r *Reader) Verify() error

Verify checks the finished stream against the manifest.

type ReaderOptions

type ReaderOptions struct {
	Identities     []age.Identity
	MaxMemberBytes int64 // default 512 MiB
	MaxTotalBytes  int64 // default unlimited
}

ReaderOptions bound the resources a malformed or hostile bundle can consume.

type RepoInfo

type RepoInfo struct {
	Name    string         `json:"name"`
	Path    string         `json:"path,omitempty"`
	Remote  string         `json:"remote,omitempty"`
	Commit  string         `json:"commit,omitempty"`
	Branch  string         `json:"branch,omitempty"`
	Dirty   bool           `json:"dirty,omitempty"`
	Options map[string]any `json:"options,omitempty"` // render options: values, overlays, env, release, namespace
}

RepoInfo describes the repository a declared-state bundle was built from.

type ReviewInfo

type ReviewInfo struct {
	OriginalBundleID string    `json:"originalBundleId"`
	Reviewer         string    `json:"reviewer,omitempty"`
	ReviewedAt       time.Time `json:"reviewedAt"`
}

ReviewInfo links a reviewed bundle to the capture it was made from. The original's manifest hash and signature are in review-ledger.json, which is written at the end, once the original has been read and verified.

type Trimmed

type Trimmed struct {
	Objects     int `json:"objects,omitempty"`     // removed one by one
	ByNamespace int `json:"byNamespace,omitempty"` // removed with a whole namespace
	Lines       int `json:"lines,omitempty"`       // log lines
	Files       int `json:"files,omitempty"`       // diagnostic or flow files
}

Trimmed says how a collection was cut down in review.

type Writer

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

Writer streams a bundle in a single pass with no temporary files.

func NewWriter

func NewWriter(w io.Writer, o WriterOptions) (*Writer, error)

NewWriter starts a bundle on w.

func (*Writer) Add

func (w *Writer) Add(name string, data []byte) error

Add writes one data member.

func (*Writer) AddJSON

func (w *Writer) AddJSON(name string, v any) error

AddJSON marshals v and writes it.

func (*Writer) Close

func (w *Writer) Close(m Manifest) error

Close writes manifest.json and finishes every layer of the stream.

func (*Writer) CompressedBytes

func (w *Writer) CompressedBytes() int64

CompressedBytes is the number of bytes written to the destination so far.

func (*Writer) Coverage

func (w *Writer) Coverage(c Coverage) error

Coverage records a finished collection and flushes, so importers learn promptly.

func (*Writer) Flush

func (w *Writer) Flush() error

Flush forces buffered data out to the underlying writer.

func (*Writer) WriteHeader

func (w *Writer) WriteHeader(h Header) error

WriteHeader writes bundle.json. It must be the first member.

type WriterOptions

type WriterOptions struct {
	Compression string // best, better, default, fastest
	WindowSize  int    // bytes, power of two, capped at MaxWindow
	Recipients  []age.Recipient
	FlushEvery  time.Duration
	// Signer, when set, signs manifest.json and writes manifest.sig after it.
	Signer *sign.PrivateKey
}

WriterOptions configure compression and encryption.

Jump to

Keyboard shortcuts

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