Help us shape the future of Go! Take the 2026 Go Developer Survey

configguard

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package configguard installs complete configuration files through a detached rollback watchdog. The application supplies client-native, read-only validation; this package owns the file transaction and recovery journal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Watch

func Watch(manifest string) error

Watch is the hidden executable entry point. It requires the parent keepalive pipe on fd 3 and the already-held, target-specific lock on fd 4. It never accepts a standalone manifest as sufficient authority to change a file.

Types

type Options

type Options struct {
	Target      string
	Candidate   []byte
	Expected    Snapshot
	RecoveryDir string
	Executable  string
	WatchArgs   []string
	Timeout     time.Duration
	Validate    func(context.Context, string) error
	Verify      func(context.Context, string) error
}

Options describes a complete candidate. Validate must read the complete file using the actual client in an isolated home. It is called for the saved original (when present), then the candidate. Verify must read the installed configuration through the live client and check every changed setting. Callbacks must be read-only and honor their context. They must not send model requests. Executable must dispatch WatchArgs followed by the manifest path to Watch; WatchArgs defaults to ["__config-watch"].

type RestoreOptions

type RestoreOptions struct {
	Directory  string
	Executable string
	WatchArgs  []string
	Timeout    time.Duration
	Validate   func(context.Context, string) error
	Verify     func(context.Context, string) error
}

RestoreOptions identifies a prior committed Apply. Restore refuses to overwrite any change made since that candidate was installed.

type Result

type Result struct {
	Directory string `json:"directory"`
	Status    Status `json:"status"`
}

func Apply

func Apply(ctx context.Context, o Options) (Result, error)

Apply validates complete files before starting the watchdog. Only the detached watchdog can install or roll back; a stalled or dead caller cannot install after the watchdog exits.

func Restore

func Restore(ctx context.Context, o RestoreOptions) (Result, error)

Restore starts another detached transaction using the complete saved original, including its permissions or original absence. Divergent edits are preserved. Recovery files remain available after restoration.

type Snapshot

type Snapshot struct {
	Exists bool   `json:"exists"`
	SHA256 string `json:"sha256,omitempty"`
	Mode   uint32 `json:"mode,omitempty"`
}

Snapshot is a complete optimistic concurrency check, including absence and permission changes. Obtain it with Inspect before constructing a candidate.

func Inspect

func Inspect(path string) (Snapshot, error)

Inspect refuses symbolic links, traversal components, special files, and files larger than 8 MiB. Missing target files produce a zero Snapshot.

type Status

type Status struct {
	State      string    `json:"state"`
	Reason     string    `json:"reason,omitempty"`
	Current    Snapshot  `json:"current"`
	WatcherPID int       `json:"watcher_pid"`
	At         time.Time `json:"at"`
}

Status is the durable outcome written by the sole configuration writer. A preserved_concurrent_change outcome always requires inspection by a human.

func ReadStatus

func ReadStatus(directory string) (Status, error)

ReadStatus reads a private transaction's durable terminal status.

Jump to

Keyboard shortcuts

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