Documentation
¶
Overview ¶
Package truenas implements the sandbox.Sandbox interface using TrueNAS Incus containers via the WebSocket API.
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) ContainerDataset(ctx context.Context, name string) (string, error)
- func (c *Client) CreateInstance(ctx context.Context, opts CreateInstanceOpts) (*truenas.VirtInstance, error)
- func (c *Client) DefaultNIC(ctx context.Context) (*NICOpts, error)
- func (c *Client) ListInstances(ctx context.Context) ([]truenas.VirtInstance, error)
- func (c *Client) ListSnapshots(ctx context.Context, dataset string) ([]truenas.Snapshot, error)
- func (c *Client) Provision(ctx context.Context, name string, opts ProvisionOpts) error
- func (c *Client) ReplaceContainerRootfs(ctx context.Context, containerName, snapshotID string) error
- func (c *Client) SnapshotRollback(ctx context.Context, snapshotID string) error
- func (c *Client) WriteAuthorizedKey(ctx context.Context, name, sshPubKey string) error
- func (c *Client) WriteContainerFile(ctx context.Context, name, path string, content []byte, mode fs.FileMode) error
- type CreateInstanceOpts
- type NICOpts
- type ProvisionOpts
- type TrueNAS
- func (t *TrueNAS) AllowDomain(ctx context.Context, name, domain string) error
- func (t *TrueNAS) Capabilities() sandbox.Capabilities
- func (t *TrueNAS) CloneFrom(ctx context.Context, source, label, newName string) error
- func (t *TrueNAS) Close() error
- func (t *TrueNAS) Console(ctx context.Context, name string, opts sandbox.ConsoleOpts) error
- func (t *TrueNAS) Create(ctx context.Context, opts sandbox.CreateOpts) (*sandbox.Instance, error)
- func (t *TrueNAS) CreateSnapshot(ctx context.Context, name, label string) error
- func (t *TrueNAS) Delete(ctx context.Context, name string) error
- func (t *TrueNAS) DeleteSnapshot(ctx context.Context, name, label string) error
- func (t *TrueNAS) DenyDomain(ctx context.Context, name, domain string) error
- func (t *TrueNAS) Get(ctx context.Context, name string) (*sandbox.Instance, error)
- func (t *TrueNAS) GetPolicy(ctx context.Context, name string) (*sandbox.Policy, error)
- func (t *TrueNAS) List(ctx context.Context) ([]sandbox.Instance, error)
- func (t *TrueNAS) ListSnapshots(ctx context.Context, name string) ([]sandbox.Snapshot, error)
- func (t *TrueNAS) Output(ctx context.Context, name string, cmd []string) ([]byte, error)
- func (t *TrueNAS) Ready(ctx context.Context, name string, timeout time.Duration) error
- func (t *TrueNAS) RestoreSnapshot(ctx context.Context, name, label string) error
- func (t *TrueNAS) Run(ctx context.Context, name string, opts sandbox.ExecOpts) (int, error)
- func (t *TrueNAS) SetEgressMode(ctx context.Context, name string, mode sandbox.EgressMode) error
- func (t *TrueNAS) Start(ctx context.Context, name string) error
- func (t *TrueNAS) Stop(ctx context.Context, name string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Virt truenas.VirtServiceAPI
Snapshot truenas.SnapshotServiceAPI
Interface truenas.InterfaceServiceAPI
Network truenas.NetworkServiceAPI
Filesystem truenas.FilesystemServiceAPI
Cron truenas.CronServiceAPI
// contains filtered or unexported fields
}
Client wraps a truenas-go WebSocket client and its typed services.
func (*Client) ContainerDataset ¶
ContainerDataset returns the ZFS dataset path for a container by name.
func (*Client) CreateInstance ¶
func (c *Client) CreateInstance(ctx context.Context, opts CreateInstanceOpts) (*truenas.VirtInstance, error)
CreateInstance creates an Incus container via the Virt service.
func (*Client) DefaultNIC ¶
DefaultNIC discovers the host's gateway interface and returns NIC options suitable for container creation.
func (*Client) ListInstances ¶
ListInstances queries all Incus instances with the px- prefix.
func (*Client) ListSnapshots ¶
ListSnapshots queries snapshots for the given ZFS dataset.
func (*Client) Provision ¶
Provision writes SSH keys, rc.local for openssh-server install, dev tools setup, and optional DNS/env config into a running container's rootfs via file_receive.
func (*Client) ReplaceContainerRootfs ¶
func (c *Client) ReplaceContainerRootfs(ctx context.Context, containerName, snapshotID string) error
ReplaceContainerRootfs destroys the container's ZFS dataset and clones the checkpoint snapshot in its place. The container must be stopped.
func (*Client) SnapshotRollback ¶
SnapshotRollback rolls back to the given snapshot ID (dataset@name).
func (*Client) WriteAuthorizedKey ¶
WriteAuthorizedKey writes an SSH public key to a running container's authorized_keys files (root and pixel user) via the TrueNAS file_receive API.
type CreateInstanceOpts ¶
type CreateInstanceOpts struct {
Name string
Image string
CPU string
Memory int64 // bytes
Autostart bool
NIC *NICOpts
}
CreateInstanceOpts contains options for creating a container.
type NICOpts ¶
type NICOpts struct {
NICType string // "MACVLAN" or "BRIDGED"
Parent string // host interface (e.g. "eno1")
}
NICOpts describes a NIC device to attach during container creation.
type ProvisionOpts ¶
type ProvisionOpts struct {
SSHPubKey string
DNS []string // nameservers (e.g. ["1.1.1.1", "8.8.8.8"])
Env map[string]string // environment variables to inject into /etc/environment
DevTools bool // whether to install dev tools (mise, claude-code, codex, opencode)
Egress string // "unrestricted", "agent", or "allowlist"
EgressAllow []string // custom domains (merged into agent, standalone for allowlist)
ProvisionScript string // zmx provision script content (written to /usr/local/bin/pixels-provision.sh)
Log io.Writer // optional; verbose progress output
}
ProvisionOpts contains options for provisioning a container.
type TrueNAS ¶
type TrueNAS struct {
// contains filtered or unexported fields
}
TrueNAS implements sandbox.Sandbox using the TrueNAS WebSocket API for container lifecycle, SSH for execution, and the local cache for fast lookups.
func NewForTest ¶
NewForTest creates a TrueNAS backend with injected dependencies for testing.
func (*TrueNAS) AllowDomain ¶
AllowDomain adds a domain to the egress allowlist and re-resolves.
func (*TrueNAS) Capabilities ¶
func (t *TrueNAS) Capabilities() sandbox.Capabilities
Capabilities advertises that TrueNAS supports all optional features.
func (*TrueNAS) Create ¶
Create creates a new container instance with the full provisioning flow: NIC resolution, instance creation, provisioning, restart, IP poll, SSH wait. When opts.Bare is true, only the instance is created (no provisioning or SSH wait).
func (*TrueNAS) CreateSnapshot ¶
CreateSnapshot creates a ZFS snapshot for the named instance.
func (*TrueNAS) DeleteSnapshot ¶
DeleteSnapshot deletes a ZFS snapshot by label.
func (*TrueNAS) DenyDomain ¶
DenyDomain removes a domain from the egress allowlist and re-resolves.
func (*TrueNAS) ListSnapshots ¶
ListSnapshots returns all snapshots for the named instance.
func (*TrueNAS) Ready ¶
Ready waits until the instance is reachable via SSH. If key auth fails, it pushes the current machine's SSH public key via the TrueNAS file API.
func (*TrueNAS) RestoreSnapshot ¶
RestoreSnapshot rolls back to the given snapshot: stop, rollback, start, poll IP, SSH wait.
func (*TrueNAS) Run ¶
Run executes a command inside a sandbox instance. If ExecOpts provides custom Stdin/Stdout/Stderr, it builds a custom exec.Cmd using ssh.Args(). Otherwise it delegates to ssh.Exec.
func (*TrueNAS) SetEgressMode ¶
SetEgressMode sets the egress filtering mode for a container.
For "unrestricted": flushes nftables, removes egress files, restores blanket sudoers.
For "agent"/"allowlist": writes nftables config, domains/cidrs, resolve script, safe-apt wrapper, restricted sudoers via the TrueNAS API, then SSHes in to install nftables and resolve domains.