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
- func Covers(allow []string, host string) bool
- func Forget(ctx context.Context, id string) error
- func ForgetShort(ctx context.Context, short string) error
- func GuardSocket(root, short string) string
- func Purge(ctx context.Context, tapName string) error
- func RuleFor(line string) (int, int, bool)
- func ServeGuard(ctx context.Context, cfg GuardConfig) error
- func ShortID(id string) string
- func ValidBindingPath(p string) bool
- func ValidateAllow(allow []string) error
- type Attachment
- func (a *Attachment) Detach(ctx context.Context) error
- func (a *Attachment) DialGuest(ctx context.Context, port int) (net.Conn, error)
- func (a *Attachment) HasGuard() bool
- func (a *Attachment) SetBindings(ctx context.Context, policy Policy, cutHosts []string) error
- func (a *Attachment) SetEgress(ctx context.Context, policy Policy) error
- type Binding
- type GuardConfig
- type Leaf
- type Manager
- func (m *Manager) Adopt(ctx context.Context, id, tapName string, policy Policy) (*Attachment, error)
- func (m *Manager) Attach(ctx context.Context, id string, policy Policy) (*Attachment, error)
- func (m *Manager) EnsureBase(ctx context.Context) error
- func (m *Manager) Flush()
- func (m *Manager) Reserve(mark int)
- type Policy
- type Record
- type RequestRecord
Constants ¶
const ( DecisionAllowed = "allowed" DecisionDenied = "denied" DecisionInjected = "injected" DecisionObserved = "observed" )
The decision one egress record carries.
const Table = "kiln"
Table is the one nftables table Kiln owns.
Variables ¶
This section is empty.
Functions ¶
func ForgetShort ¶
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
GuardSocket returns the socket path of the guard with one short id.
func Purge ¶
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 ¶
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 ValidBindingPath ¶ added in v0.12.0
ValidBindingPath reports whether a binding names a path prefix a request can match.
func ValidateAllow ¶
ValidateAllow reports whether every entry is a hostname.
Types ¶
type Attachment ¶
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 ¶
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
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
GuardConfig names the link one guard serves.
type Leaf ¶ added in v0.12.0
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 ¶
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 ¶
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 ¶
EnsureBase creates the Kiln table and its shared mark chain, and enables forwarding. It is idempotent.
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.