Documentation
¶
Overview ¶
Package hostsec looks for signs that a NextDeploy VPS has been compromised: things an intruder leaves behind (new SSH keys, accounts, cron jobs, services, listeners, processes running from /tmp, modified app files) and gaps that make a break-in likely (password SSH, no firewall, no updates).
It is honest about its limits: a check that runs on the machine can be lied to by an attacker who already has root. A clean report means "none of the common signs", not proof of a clean host.
Index ¶
- Constants
- func Format(w io.Writer, r *Report, showOK bool)
- func ManifestPath(dir, app, release string) string
- func SaveBaseline(path string, b *Baseline) error
- func WriteReleaseManifest(integrityDir, appsDir, app, release, releaseDir string) error
- type Baseline
- type Drift
- type Finding
- type Manifest
- type Options
- type Report
- type Severity
- type System
Constants ¶
const ( // DefaultIntegrityDir is root-only: the app runs as `nextdeploy` and can // write its own release dir (ISR), so the fingerprints must live where // the app can't rewrite them to cover its tracks. DefaultIntegrityDir = "/var/lib/nextdeploy/integrity" // DefaultAppsDir is where NextDeploy keeps each app's releases. DefaultAppsDir = "/opt/nextdeploy/apps" )
const DefaultBaselinePath = "/var/lib/nextdeploy/security/baseline.json"
DefaultBaselinePath is root-only state written by prepare / --accept.
Variables ¶
This section is empty.
Functions ¶
func ManifestPath ¶
ManifestPath is where a release's manifest lives.
func SaveBaseline ¶
SaveBaseline writes it root-only and atomically.
func WriteReleaseManifest ¶
WriteReleaseManifest fingerprints a freshly extracted release (before it runs) and prunes manifests of releases that no longer exist.
Types ¶
type Baseline ¶
type Baseline struct {
CreatedAt time.Time `json:"created_at"`
Users []string `json:"users"` // name:uid:shell for login-capable accounts
SSHKeys map[string][]string `json:"ssh_keys"` // user -> "SHA256:… comment"
Files map[string]string `json:"files"` // sudoers + cron path -> sha256
Services []string `json:"services"` // enabled systemd services/timers
Listeners []string `json:"listeners"` // "proc/proto" listening on a public address
}
Baseline is the expected state of the things intruders change.
func CollectBaseline ¶
CollectBaseline snapshots the current state.
type Drift ¶
type Drift struct {
Modified, Added, Removed []string
}
Drift is how a release differs from its manifest.
type Finding ¶
type Finding struct {
Severity Severity `json:"severity"`
Check string `json:"check"` // ssh, firewall, listeners, processes, accounts, ssh-keys, sudoers, cron, services, logins, updates, fail2ban, integrity
Title string `json:"title"`
Detail []string `json:"detail,omitempty"`
Fix string `json:"fix,omitempty"`
}
Finding is one result.
type Manifest ¶
type Manifest struct {
App string `json:"app"`
Release string `json:"release"`
CreatedAt time.Time `json:"created_at"`
Files map[string]string `json:"files"` // rel path -> sha256 (or "link:<target>")
}
Manifest fingerprints every deployed file of one release.
func BuildManifest ¶
BuildManifest hashes a release directory.
type Options ¶
type Options struct {
Baseline Baseline
HasBaseline bool
// IntegrityDir holds release manifests (see WriteReleaseManifest).
IntegrityDir string
AppsDir string
LoginWindow time.Duration
}
Options for a check run.
type Report ¶
type Report struct {
GeneratedAt time.Time `json:"generated_at"`
Hostname string `json:"hostname,omitempty"`
BaselineAt time.Time `json:"baseline_at,omitzero"`
BaselineCreated bool `json:"baseline_created,omitempty"`
BaselineAccepted bool `json:"baseline_accepted,omitempty"`
Verdict string `json:"verdict"`
Counts map[Severity]int `json:"counts"`
Findings []Finding `json:"findings"`
}
Report is the JSON contract of `nextdeployd security-check --json` and `nextdeploy security check --json`. Add fields; don't rename them.
type Severity ¶
type Severity string
Severity orders findings. Critical = likely compromise; High = a door is open or something changed that an attacker would change; Medium = weaker posture; Info = context; OK = a passed check.
type System ¶
type System struct {
Root string
Run func(name string, args ...string) (string, error)
// Country maps an IP to a country code for login reports ("" = unknown).
Country func(ip string) string
Now func() time.Time
}
System is the machine being checked. Root prefixes every file path (tests point it at a temp dir); Run executes a command.