Documentation
¶
Overview ¶
Package hostdiag answers a fixed set of read-only host questions for the web CLI console, in process. It never executes anything and takes no input beyond a subcommand name chosen from a closed list.
Index ¶
- Constants
- Variables
- func Check(argv []string) (string, error)
- func Enabled() bool
- func FormatDF(rows []DiskUsage) string
- func FormatFree(m Meminfo) string
- func FormatLoad(l Loadavg, cpus int) string
- func FormatService(s ServiceInfo) string
- func HumanDuration(d time.Duration) string
- func ParseOSRelease(text string) string
- func ParseUptime(text string) (time.Duration, error)
- func ParseVMRSS(text string) (uint64, error)
- func Run(sub string, info Info) (string, error)
- func Sanitize(s string) string
- func Subcommands() []string
- type DiskUsage
- type HardeningCheck
- type HardeningPlan
- type HardeningReport
- type Info
- type Loadavg
- type Meminfo
- type PlanStep
- type ServiceInfo
- type UsageError
Constants ¶
const ( CheckSSHPassword = "ssh_password_login" CheckSSHRoot = "ssh_root_login" CheckSecurityUpdates = "unattended_security_updates" HardeningPass = "pass" HardeningFail = "fail" HardeningUnknown = "unknown" FamilyDebian = "debian" FamilyRHEL = "rhel" )
Host hardening check ids and statuses.
const ( ReasonUnsupportedOS = "unsupported_os" ReasonUnsupportedDistro = "unsupported_distro" ReasonContainer = "container" ReasonNoAccess = "no_access" ReasonNotFound = "config_not_found" ReasonUnparsed = "config_not_parsed" ReasonStartupOptions = "startup_options" ReasonMatchBlock = "match_block" ReasonKbdInteractive = "keyboard_interactive" ReasonAuthMethods = "authentication_methods" ReasonDistroDefault = "distro_default" ReasonEnabled = "enabled" ReasonDisabled = "disabled" ReasonNotInstalled = "not_installed" ReasonTimerUnproven = "timer_unproven" ReasonOriginsUnproven = "security_origin_unproven" )
Reasons are stable codes so every client can word them itself.
const Command = "host"
Command is the console word that routes a line here.
const EnvSwitch = "APP_CLI_CONSOLE_HOST"
EnvSwitch turns host diagnostics off without turning off the console.
Variables ¶
var ErrUnsupported = errors.New("not supported on this platform")
ErrUnsupported means the current OS has no implementation.
Functions ¶
func Enabled ¶
func Enabled() bool
Enabled reports whether host diagnostics are allowed by the environment.
func FormatFree ¶
FormatFree renders a Meminfo as the free report.
func FormatService ¶
func FormatService(s ServiceInfo) string
FormatService renders the service report.
func HumanDuration ¶
HumanDuration renders d as "3d 4h 5m", or seconds when under a minute.
func ParseOSRelease ¶
ParseOSRelease returns PRETTY_NAME, falling back to NAME VERSION.
func ParseUptime ¶
ParseUptime reads the first field of /proc/uptime as seconds since boot.
func ParseVMRSS ¶
ParseVMRSS reads VmRSS from /proc/self/status, in bytes.
func Subcommands ¶
func Subcommands() []string
Subcommands returns the closed list of host subcommands.
Types ¶
type HardeningCheck ¶
type HardeningCheck struct {
ID string `json:"id"`
Status string `json:"status"`
Reason string `json:"reason,omitempty"`
Value string `json:"value,omitempty"`
Source string `json:"source,omitempty"`
}
HardeningCheck is one verdict. Source is the file and line that decided it.
type HardeningPlan ¶
type HardeningPlan struct {
LockoutRisk bool `json:"lockout_risk"`
Warning string `json:"warning,omitempty"`
Steps []PlanStep `json:"steps"`
}
HardeningPlan is a preview of the fixes for a report. It is never applied.
func PlanHardening ¶
func PlanHardening(r HardeningReport) HardeningPlan
PlanHardening builds ordered steps for failing checks, and an inspection step for unproven ones.
type HardeningReport ¶
type HardeningReport struct {
Distro string `json:"distro,omitempty"`
Family string `json:"family,omitempty"`
DropIn bool `json:"drop_in"`
Checks []HardeningCheck `json:"checks"`
}
HardeningReport is the state of the control plane host as read from disk.
func CheckHardening ¶
func CheckHardening() HardeningReport
CheckHardening reads this host's SSH and update configuration. It never writes or executes.
type Loadavg ¶
Loadavg is the parsed /proc/loadavg.
func ParseLoadavg ¶
ParseLoadavg reads "0.10 0.20 0.30 1/234 5678"; the last pid field is ignored.
type Meminfo ¶
type Meminfo struct {
Total, Available, SwapTotal, SwapFree uint64
}
Meminfo holds the /proc/meminfo fields the free report uses, in bytes.
func ParseMeminfo ¶
ParseMeminfo reads /proc/meminfo text; values there are in kB.
type PlanStep ¶
type PlanStep struct {
ID string `json:"id"`
Check string `json:"check"`
Title string `json:"title"`
Commands []string `json:"commands"`
}
PlanStep is one manual step. Commands are for the operator to copy; nothing here runs them.
type ServiceInfo ¶
type ServiceInfo struct {
Version string
GoVersion string
Started time.Time
Now time.Time
Goroutines int
RSS uint64
RSSKnown bool
Supervised bool
}
ServiceInfo describes this control plane process.
type UsageError ¶
type UsageError struct{ Reason string }
UsageError is a refusal whose message is safe to show the operator.
func (*UsageError) Error ¶
func (e *UsageError) Error() string