network

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package network owns the host side of every microVM link: the TAP device, the per-VM nftables chains and the resolver that answers only the names in a sandbox's allowlist. Guest addresses never vary; only the host side does.

Index

Constants

View Source
const (
	DecisionAllowed  = "allowed"
	DecisionDenied   = "denied"
	DecisionInjected = "injected"
	DecisionObserved = "observed"
)

The decision one egress record carries.

View Source
const Table = "kiln"

Table is the one nftables table Kiln owns.

Variables

This section is empty.

Functions

func Covers added in v0.12.0

func Covers(allow []string, host string) bool

Covers reports whether an egress list reaches one host.

func Forget

func Forget(ctx context.Context, id string) error

forget removes the per-VM chains and the allow set of one sandbox id.

func ForgetShort

func ForgetShort(ctx context.Context, short string) error

ForgetShort removes the per-VM chains and the allow set of one short id. The reconciler uses it for chains that no row owns. An absent chain is not an error.

func GuardSocket added in v0.11.0

func GuardSocket(root, short string) string

GuardSocket returns the socket path of the guard with one short id.

func Purge

func Purge(ctx context.Context, tapName string) error

Purge removes a TAP device and its routing state when no row owns them. The reconciler calls it for a device a crashed daemon left behind.

func RuleFor

func RuleFor(line string) (int, int, bool)

RuleFor reads the mark and table out of one Kiln fwmark rule line: a rule that sends traffic to the guest address through a table Kiln owns.

func ServeGuard added in v0.11.0

func ServeGuard(ctx context.Context, cfg GuardConfig) error

ServeGuard runs until the context ends or the daemon sends a stop. It holds no policy until a daemon gives it one, so it refuses everything at first.

func ShortID

func ShortID(id string) string

ShortID is the short name a sandbox's network resources carry.

func ValidBindingPath added in v0.12.0

func ValidBindingPath(p string) bool

ValidBindingPath reports whether a binding names a path prefix a request can match.

func ValidateAllow

func ValidateAllow(allow []string) error

ValidateAllow reports whether every entry is a hostname.

Types

type Attachment

type Attachment struct {
	ID      string
	TAPName string
	// contains filtered or unexported fields
}

Attachment is one VM's host-side link: a TAP device, a routing table, a firewall mark and the resolver sockets.

func (*Attachment) Detach

func (a *Attachment) Detach(ctx context.Context) error

Detach removes every host resource this attachment owns. It is idempotent.

func (*Attachment) DialGuest

func (a *Attachment) DialGuest(ctx context.Context, port int) (net.Conn, error)

DialGuest opens a TCP connection to one guest port through this attachment's TAP device and routing table. Every guest has the same address, so the mark and the device are what select the sandbox.

func (*Attachment) HasGuard added in v0.11.0

func (a *Attachment) HasGuard() bool

HasGuard reports whether this attachment enforces through a guard. A sandbox adopted from before the guard does not, until its next wake.

func (*Attachment) SetBindings added in v0.12.0

func (a *Attachment) SetBindings(ctx context.Context, policy Policy, cutHosts []string) error

SetBindings replaces the credentials of one live attachment. A rotation takes effect on the next request. A host that gains or loses its binding ends only its own connections, because a client's open connection to it would otherwise stay undecrypted or keep a stale proxy.

func (*Attachment) SetEgress added in v0.9.0

func (a *Attachment) SetEgress(ctx context.Context, policy Policy) error

SetEgress replaces the policy of one live attachment. Every connection the guest opened ends, because repository code holds such a connection open otherwise. A connection the host opened to a published port stays.

type Binding added in v0.12.0

type Binding struct {
	Name    string   `json:"name"`
	Host    string   `json:"host"`
	Header  string   `json:"header"`
	Value   string   `json:"value"`
	Path    string   `json:"path,omitempty"`
	Methods []string `json:"methods,omitempty"`
}

Binding ties one credential to one exact host. Value travels only from the daemon to the guard of this sandbox, and only the guard holds it opened.

type GuardConfig added in v0.11.0

type GuardConfig struct {
	Sock string
	Tap  string
	Mark int
}

GuardConfig names the link one guard serves.

type Leaf added in v0.12.0

type Leaf struct {
	Host string `json:"host"`
	Cert string `json:"cert"`
	Key  string `json:"key"`
}

Leaf is the certificate of one bound host. The guard holds no key that signs a certificate for any other name.

type Manager

type Manager struct {

	// OnRecords takes the egress records of one sandbox, and the count of
	// records that had no room. A sandbox manager sets it before any attach.
	OnRecords func(id string, records []Record, dropped int64)
	// OnRequests takes the request log of one sandbox's bound hosts.
	OnRequests func(id string, rows []RequestRecord, dropped int64)
	// OnGuardExit takes the id of a sandbox whose guard died.
	OnGuardExit func(id string)
	// contains filtered or unexported fields
}

Manager creates and removes per-VM network attachments.

func New

func New(binary, root string) *Manager

New returns the network manager. binary is the kilnd executable that runs each egress guard, and root is the Kiln root that holds their sockets.

func (*Manager) Adopt

func (m *Manager) Adopt(ctx context.Context, id, tapName string, policy Policy) (*Attachment, error)

Adopt reattaches to the network of a microVM whose process survived a daemon restart. The TAP device and its rules belong to the running VM, so they stay. The resolver runs in this process and died with the old daemon, so it starts again and the DNS rules are rewritten. The guard outlives the daemon, so a new link reaches it. A guard that also died starts again, and a sandbox from before the guard keeps its address set.

func (*Manager) Attach

func (m *Manager) Attach(ctx context.Context, id string, policy Policy) (*Attachment, error)

Attach creates the TAP device, the resolver, the nftables chains and the routing rule for one VM, and starts its egress guard.

func (*Manager) EnsureBase

func (m *Manager) EnsureBase(ctx context.Context) error

EnsureBase creates the Kiln table and its shared mark chain, and enables forwarding. It is idempotent.

func (*Manager) Flush added in v0.11.0

func (m *Manager) Flush()

Flush hands every held record to OnRecords.

func (*Manager) Reserve

func (m *Manager) Reserve(mark int)

Reserve makes one mark number taken, so a later attach cannot collide with a sandbox adopted from a previous daemon.

type Policy added in v0.11.0

type Policy struct {
	Allow   []string
	Observe bool
	// Bindings and Leaves are the credentials of this sandbox and the certificate
	// of each host they name.
	Bindings []Binding
	Leaves   []Leaf
}

Policy is what one sandbox may reach. With Observe set, any TLS name passes and Allow waits for the next change.

type Record added in v0.11.0

type Record struct {
	Host     string `json:"host"`
	Port     int    `json:"port"`
	Decision string `json:"decision"`
	Count    int64  `json:"count"`
	BytesOut int64  `json:"bytes_out"`
	BytesIn  int64  `json:"bytes_in"`
	First    int64  `json:"first"`
	Last     int64  `json:"last"`
	// Binding names the credential binding of an injected row.
	Binding string `json:"binding,omitempty"`
}

Record is a summary of one destination over some period. A later record for the same destination adds to it.

type RequestRecord added in v0.12.0

type RequestRecord struct {
	Method  string `json:"method"`
	Host    string `json:"host"`
	Path    string `json:"path"`
	Status  int    `json:"status"`
	Binding string `json:"binding,omitempty"`
	At      int64  `json:"at"`
}

RequestRecord is one request a guard read on a bound host. It holds no query string, no header value and no body.

Jump to

Keyboard shortcuts

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