Documentation
¶
Overview ¶
Package compat says whether a go-common version is old enough to be missing a security fix that go-common itself shipped.
The manifest (compat.json, embedded in the package) names a floor, min_safe, and the fixes that put it there. A service pinned below the floor has a known, fixed problem; the check is how the fleet turns "please bump go-common" into a gate (a preflight or CI step calls CheckGoMod on each service's go.mod).
m, err := compat.Load()
res, err := m.CheckGoMod(goModBytes)
if res.Status == compat.StatusBelowFloor { ... }
The floor is about go-common's own fixes. It does not claim that a version at or above it is free of known vulnerabilities: advisories in go-common's dependencies and in the Go toolchain are tracked in scripts/govulncheck-allow.txt.
A release that ships a security fix settles the floor in the same change: either MinSafe is raised to it, or a MinSafeUnchanged record says why it stays (docs/releasing.md).
The package also carries the change feed (changes.json): the CHANGELOG.md bullets marked BREAKING, each with a one-line summary and, when there is one, the way back to the old behaviour. LoadChanges reads it and ChangeFeed.Between answers "what changes if I move my pin from one version to another"; scripts/whatchanged prints the answer for a pull request body, and docs/releasing.md has the grammar.
Index ¶
Constants ¶
const ModulePath = "github.com/baditaflorin/go-common"
ModulePath is the module this package is about.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Change ¶
type Change struct {
// Version is the release that shipped it, for example "v0.103.0".
Version string `json:"version"`
// Date is the release date in the CHANGELOG heading, "YYYY-MM-DD".
Date string `json:"date"`
// Class is the bullet's marker in lower case: "breaking", or "behavioural" for a
// bullet marked BEHAVIOURAL (patch-safe).
Class string `json:"class"`
// Qualifier is the text in parentheses after the marker, for example
// "behavioural" or "only for 0.102.59"; empty when there is none, which for
// a breaking change means the API itself (or a build requirement) changed.
Qualifier string `json:"qualifier,omitempty"`
// Summary is the bullet's summary: line, at most 200 characters.
Summary string `json:"summary"`
// OffSwitch is the bullet's off-switch: line, the setting, option or call that
// restores the old behaviour without waiting for a release. Empty when there is none.
OffSwitch string `json:"off_switch,omitempty"`
// Reason is the reason: line of a BEHAVIOURAL (patch-safe) bullet: why a patch release
// may carry the change. Empty for every other class.
Reason string `json:"reason,omitempty"`
}
Change is one CHANGELOG.md bullet that a consumer has to read before it bumps: a bullet whose marker is **BREAKING...**, written with a one-line summary and, when there is one, the way back to the old behaviour (docs/releasing.md has the grammar).
type ChangeFeed ¶
type ChangeFeed struct {
Schema int `json:"schema"`
Note string `json:"note,omitempty"`
Changes []Change `json:"changes"`
}
ChangeFeed is the parsed changes.json, newest release first.
func LoadChanges ¶
func LoadChanges() (ChangeFeed, error)
LoadChanges parses the feed embedded in this version of go-common.
func ParseChanges ¶
func ParseChanges(data []byte) (ChangeFeed, error)
ParseChanges parses and validates a feed. It checks what a consumer relies on (the schema, a version and a date on every change) and ignores fields and classes it does not know, so an older consumer can read a newer feed.
func (ChangeFeed) Between ¶
func (f ChangeFeed) Between(from, to string) ([]Change, error)
Between returns the changes shipped in releases newer than from, up to and including to, in the feed's order (newest first). It answers "what changes if I move my pin from from to to". Either end may be empty: from "" starts at the first release in the feed, to "" has no upper end.
A pin that is a pre-release or a pseudo-version sorts below its own release (v0.102.3-0.20261002000000-abcdefabcdef is older than v0.102.3), so the release it was cut for is included: a note that might not apply is better than one that is missing.
type FloorStatus ¶
type FloorStatus string
FloorStatus says what the floor does about the security fix a release shipped.
const ( // FloorCovers means the release is at or below min_safe: a pin below it is reported. FloorCovers FloorStatus = "covered" // FloorUnchanged means the floor was considered for this release and left alone; // the reason is in min_safe_unchanged. FloorUnchanged FloorStatus = "unchanged" // FloorUndecided means neither: no decision is recorded for the release. FloorUndecided FloorStatus = "undecided" )
type Manifest ¶
type Manifest struct {
Schema int `json:"schema"`
// MinSafe is the oldest release that contains every security fix in Reasons.
MinSafe string `json:"min_safe"`
// MinSafeDate is when MinSafe was committed, used to place pseudo-versions
// (which carry only a commit time) relative to the floor.
MinSafeDate time.Time `json:"min_safe_date"`
Reasons []Reason `json:"reasons"`
// MinSafeUnchanged records, for a release whose CHANGELOG.md entry has a
// **SECURITY:** bullet, that the floor was considered and left alone (the
// alternative to raising it). Optional: a reader that does not know the field
// ignores it, so the manifest stays readable by older releases of this package.
MinSafeUnchanged []Unchanged `json:"min_safe_unchanged,omitempty"`
// Lines holds the floor of each older release line that has security
// backports, keyed "vMAJOR.MINOR" (for example "v0.97": "v0.97.1"). A pin on a
// listed line is judged against that line's floor, not MinSafe. Empty unless
// a backport branch has been cut.
Lines map[string]string `json:"lines,omitempty"`
Note string `json:"note"`
}
Manifest is the parsed compat.json.
func (Manifest) CheckGoMod ¶
CheckGoMod judges the go-common requirement in a go.mod file.
func (Manifest) FloorDecision ¶
func (m Manifest) FloorDecision(ver string) (FloorStatus, string, error)
FloorDecision says what the floor does about the security fix shipped in release ver, and, for FloorUnchanged, the recorded reason.
type Result ¶
type Result struct {
Status Status `json:"status"`
Version string `json:"version,omitempty"`
Message string `json:"message"`
}
Result is the outcome of a check.
type Status ¶
type Status string
Status is the verdict for one go-common pin.
const ( // StatusOK means the pin is at or above the floor. StatusOK Status = "ok" // StatusBelowFloor means the pin predates a security fix. StatusBelowFloor Status = "below_min_safe" // StatusUnchecked means the pin cannot be judged, for example a replace // directive pointing at a local checkout. StatusUnchecked Status = "unchecked" // StatusNotUsed means the go.mod does not require go-common. StatusNotUsed Status = "not_used" )
type Unchanged ¶
type Unchanged struct {
// Version is the release that shipped the fix, for example "v0.106.0".
Version string `json:"version"`
// Reason says why the floor stays where it is: what the fix closes, and why a
// service on an older release is not left exposed to it.
Reason string `json:"reason"`
}
Unchanged is the decision that a release's security fix does not move the floor.