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
- func CoveragePath(cluster, id string) string
- func DiagnosticsPath(cluster, kind, ns, pod, file string) string
- func DiscoveryPath(cluster, file string) string
- func EventsPath(cluster string, part int) string
- func FlowsPath(cluster, format, file string) string
- func LogPath(cluster, ns, pod, container, stream string, part int) string
- func NewBundleID() string
- func ResourcePath(cluster, group, version, resource string, part int) string
- func SafeID(id string) string
- func ValidName(name string) error
- type APIResource
- type Coverage
- type Header
- type Manifest
- type Member
- type PathInfo
- type PolicySource
- type Reader
- type ReaderOptions
- type RepoInfo
- type ReviewInfo
- type Trimmed
- type Writer
- func (w *Writer) Add(name string, data []byte) error
- func (w *Writer) AddJSON(name string, v any) error
- func (w *Writer) Close(m Manifest) error
- func (w *Writer) CompressedBytes() int64
- func (w *Writer) Coverage(c Coverage) error
- func (w *Writer) Flush() error
- func (w *Writer) WriteHeader(h Header) error
- type WriterOptions
Constants ¶
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 )
const ( CoverageResource = "resource" CoverageLogs = "logs" CoverageEvents = "events" CoverageDiscovery = "discovery" // 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.
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.
const SourceRepo = "repo"
SourceRepo marks a bundle built by flightbay scan from a code repository.
Variables ¶
This section is empty.
Functions ¶
func CoveragePath ¶
func DiagnosticsPath ¶
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 EventsPath ¶
func FlowsPath ¶
FlowsPath is clusters/<c>/flows/<format>/<file>: a flow log file attached to the bundle, in a format internal/flows reads.
func ResourcePath ¶
Types ¶
type APIResource ¶
type APIResource struct {
Verbs []string `json:"verbs,omitempty"`
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 ¶
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"`
// 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.
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 PathInfo ¶
type PathInfo struct {
Kind, Cluster, Group, Version, Resource, Namespace, Pod, Container, Stream, ID, File, Sub string
Part int
}
PathInfo classifies a member name.
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) ManifestSHA256 ¶
ManifestSHA256 is the hex SHA-256 of manifest.json once read: the one value that identifies the exact content of a bundle.
func (*Reader) Signature ¶
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.
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) CompressedBytes ¶
CompressedBytes is the number of bytes written to the destination so far.
func (*Writer) Coverage ¶
Coverage records a finished collection and flushes, so importers learn promptly.
func (*Writer) WriteHeader ¶
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.