Documentation
¶
Overview ¶
Package guest holds the files and helpers that run inside the managed VM: the egress firewall baseline, the isolation self-check and the provisioning script.
Index ¶
- Constants
- Variables
- func CheckScript(o Options) (string, error)
- func EgressRules(o Options) (string, error)
- func ParseHostLabel(product string) string
- func ParseManagedMarker(raw []byte) string
- func ParseStage(raw []byte, bootID string) (stage string, failed bool)
- func ProgressCommand() []string
- func ProvisionScript(o Options, sc Sidecar) (string, error)
- func UserData(o Options, sc Sidecar) (string, error)
- type Check
- type File
- type Options
- type Sidecar
- type Status
Constants ¶
const ( StatusPath = "/var/lib/levelrail/isolation-status.json" EgressRulesPath = "/etc/levelrail/lr-egress.nft" CheckScriptPath = "/usr/local/sbin/lr-isolation-check" IsolationUnit = "lr-isolation.service" CheckUnit = "lr-isolation-check.service" RecheckTimer = "lr-isolation-recheck.timer" ClockDropinPath = "/etc/systemd/system/chrony.service.d/10-lr-clock.conf" // ClockService is the guest time daemon; restarting it also steps a clock that is already behind. ClockService = "chrony.service" )
Guest paths the host side (status reads, S2 and S4) relies on.
const ( // One constant for the firewall and the control plane unit so they cannot drift: // a /15 beside the bridge and the daemon pool, about 500 app networks. DefaultAppNetworkPool = "172.30.0.0/15" // Bounds of the periodic self-check while the Docker socket is open to the host. DefaultRecheckSec = 300 MinRecheckSec = 60 MaxRecheckSec = 3600 )
Defaults block: the only place guest network numbers live.
const ( ProvisionStatePath = "/var/lib/levelrail/provision-state" ManagedMarkerPath = "/etc/levelrail/managed-vm" ProvisionLogPath = "/var/log/cloud-init-output.log" )
Guest files the host reads to follow provisioning and the guest control plane reads to know where it runs.
Variables ¶
var HostLabels = []string{"MacBook Pro", "MacBook Air", "MacBook Neo", "MacBook", "Mac mini", "Mac Studio", "Mac Pro", "iMac"}
HostLabels are the only host model names that may enter the guest. Longer names come first.
Functions ¶
func CheckScript ¶
CheckScript renders the self-check alone, so the host can run a fresh copy of it.
func EgressRules ¶
EgressRules renders the nftables baseline.
func ParseHostLabel ¶
ParseHostLabel picks the model family out of a product name such as "MacBook Pro (14-inch, 2024)". Anything else yields an empty string.
func ParseManagedMarker ¶
ParseManagedMarker returns the host label of a marker file; unknown values read as empty.
func ParseStage ¶
ParseStage reads the state file, ignoring one left by another boot.
func ProgressCommand ¶
func ProgressCommand() []string
ProgressCommand prints the stage and the sizes of the provisioning logs, so a change means progress.
func ProvisionScript ¶
ProvisionScript returns one root shell script: files first, then the firewall, then Docker (so Docker can only start behind the baseline), then the sidecar.
Types ¶
type Check ¶
type Check struct {
Name string `json:"name"`
Result string `json:"result"`
Detail string `json:"detail"`
}
Check is one line of the guest self-check result.
type Options ¶
type Options struct {
HostGateway string // Lima host address as seen from the guest, always dropped.
DNSServers []string // Resolvers that may be reached on port 53 despite the drops.
DockerPool string // The only 172.16/12 slice containers may talk to.
DockerBridge string // docker0 address, inside DockerPool.
DockerPoolBase string // User network pool, inside DockerPool.
AppNetworkPool string // Control plane per-app network block, inside DockerPool and clear of the bridge and pool base.
PublishIP string // Default bind address for published ports.
LANProbe string // Address the self-check expects to be unreachable.
ProbeTimeoutSec int
// DockerSocket opens the guest Docker socket to the Lima user and adds the periodic self-check.
DockerSocket bool
RecheckSec int // Seconds between self-checks while DockerSocket is on.
// HostLabel is the model family of the host, one of HostLabels, or empty.
HostLabel string
// LoopbackRelayPorts get a guest [::1] listener relaying to 127.0.0.1, so the host can forward [::1] too.
LoopbackRelayPorts []int
}
Options tunes the guest baseline. Zero value is invalid, use DefaultOptions.
type Sidecar ¶
type Sidecar struct {
BinaryPath string // Absolute guest path the unit's ExecStart uses.
UnitName string // File name under /etc/systemd/system, ends in .service.
UnitContent string
}
Sidecar is the control plane slot. S2 and S4 supply the binary and unit; when UnitContent is empty the step is skipped.
type Status ¶
type Status struct {
Result string `json:"result"`
BootID string `json:"boot_id"`
CheckedAt string `json:"checked_at"`
Checks []Check `json:"checks"`
}
Status is the parsed self-check file.
func ParseStatus ¶
ParseStatus parses the file read from StatusPath and requires it to belong to the current boot (bootID is /proc/sys/kernel/random/boot_id read over limactl). It only catches stale files: root inside the guest can write any status.