Documentation
¶
Overview ¶
Package integrity checks the control plane SQLite database for corruption and stages a verified snapshot to replace it.
Index ¶
- Constants
- Variables
- func BootCheck(ctx context.Context, path string) error
- func ClearPending(dataDir string) error
- func IntervalsFromEnv(getenv func(string) string) (quick, full time.Duration)
- func LatestVerified(ctx context.Context, m BackupLister) (string, error)
- func RunPragma(ctx context.Context, db Querier, mode string) error
- func Swap(ctx context.Context, dataDir, dbFile, src string, now time.Time) (aside string, version int, err error)
- type Applied
- type BackupLister
- type Candidate
- type Checker
- type Pending
- type Querier
- type Service
- type Status
- type View
Constants ¶
const ( ModeQuick = "quick" ModeFull = "full" )
Check modes.
const ( EnvCheckInterval = "APP_INTEGRITY_CHECK_INTERVAL" EnvFullInterval = "APP_INTEGRITY_FULL_INTERVAL" )
Environment variables that tune the checks.
const PendingFilename = "restore-pending.json"
PendingFilename is the marker the next boot reads to swap in a staged snapshot.
Variables ¶
var ErrCorrupt = errors.New("database file is corrupt")
ErrCorrupt means SQLite reported the database file as damaged.
var ErrNoVerifiedBackup = errors.New("no verified control plane snapshot is available")
ErrNoVerifiedBackup means no snapshot passed verification.
Functions ¶
func BootCheck ¶
BootCheck runs a quick_check on the database file before the store opens it. A missing file is fine.
func IntervalsFromEnv ¶
IntervalsFromEnv reads the quick and full check intervals; zero disables the loop.
func LatestVerified ¶
func LatestVerified(ctx context.Context, m BackupLister) (string, error)
LatestVerified re-verifies snapshots newest first and returns the first that passes.
Types ¶
type Applied ¶
Applied is the result of swapping a staged snapshot in at boot.
func ApplyPending ¶
ApplyPending swaps a staged snapshot in. It runs before the store opens, so no connection holds the file. The marker is removed whether or not the swap succeeds, so a bad snapshot cannot loop every boot.
type BackupLister ¶
type BackupLister interface {
List() ([]cpbackup.Info, error)
Verify(ctx context.Context, name string) (cpbackup.VerifyResult, error)
}
BackupLister is the slice of cpbackup.Manager the restore path needs.
type Candidate ¶
type Candidate struct {
Name string `json:"name"`
SizeBytes int64 `json:"size_bytes"`
CreatedAt time.Time `json:"created_at"`
VerifiedAt *time.Time `json:"verified_at,omitempty"`
Verified bool `json:"verified"`
}
Candidate is one snapshot the operator can restore.
func Candidates ¶
func Candidates(m BackupLister) ([]Candidate, error)
Candidates lists snapshots newest first with their last recorded verification.
type Checker ¶
type Checker struct {
// contains filtered or unexported fields
}
Checker runs quick and full integrity checks and remembers the result.
func NewChecker ¶
NewChecker returns a Checker over db. Before the first check it reports healthy.
func (*Checker) Check ¶
Check runs one check in the given mode (anything but ModeFull runs the cheap quick_check) and records it.
type Pending ¶
type Pending struct {
Name string `json:"name"`
SHA256 string `json:"sha256"`
SchemaVersion int `json:"schema_version"`
StagedAt time.Time `json:"staged_at"`
StagedBy string `json:"staged_by,omitempty"`
}
Pending describes a snapshot staged to replace the database at the next boot.
func ReadPending ¶
ReadPending returns the staged restore, or nil when none is staged.
type Service ¶
type Service struct {
*Checker
// contains filtered or unexported fields
}
Service ties the checker to the snapshot store and the staged restore marker.
func NewService ¶
NewService returns a Service for the database behind db, with snapshots listed by backups under dataDir.
func (*Service) CancelRestore ¶
CancelRestore removes a staged restore.
type Status ¶
type Status struct {
Healthy bool `json:"healthy"`
Mode string `json:"mode"`
CheckedAt time.Time `json:"checked_at"`
Error string `json:"error,omitempty"`
Checks int64 `json:"checks"`
Failures int64 `json:"failures"`
LastFullAt time.Time `json:"last_full_at"`
}
Status is the outcome of the most recent check.