confine

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package confine is the client's self-check of its containment (lockkit#133): whether the agent behind a lock client runs where it cannot reach what protects the Locks: the container runtime, the hub facades' keys, the project's .lockfamily directory.

The check runs in the agent's environment, where the facts are visible, and its Report travels in the hello handshake (ipc.Confinement). The console decides; it also checks, on Linux, the kernel's record of the peer's groups (RuntimeGIDs), which the client cannot forge.

What it proves: an honest or confused agent run on the host is told so and refused by default. What it does not: a host process that lies runs as the human and can drive Docker anyway; no lock-side check stops it. Confined agents (lea) cannot reach the runtime, the keys or the console's terminal, and that is what makes the guarantees hold against prompt injection.

Index

Constants

View Source
const (
	// InContainer: the client does not run in a container.
	InContainer = "in_container"
	// NoHostRuntime: a rootful container runtime socket connects, or is
	// there behind permissions.
	NoHostRuntime = "no_host_runtime"
	// NoFamilyState: the Lock Family's state directory (the facades'
	// private keys) is readable.
	NoFamilyState = "no_family_state"
	// LockfamilyReadOnly: the project's .lockfamily directory is writable.
	LockfamilyReadOnly = "lockfamily_read_only"
	// RuntimeGroup: the peer holds a group owning a runtime socket
	// (decided by the console from the kernel's record, never reported).
	RuntimeGroup = "runtime_group"
	// OldClient: the client sent no confinement report (decided by the
	// console).
	OldClient = "old_client"
)

The reasons a client is unconfined: each names the check that failed. They are fixed codes, sent on the wire; Text gives the human text.

Variables

View Source
var RuntimeSockets = []string{
	"/var/run/docker.sock",
	"/run/docker.sock",
	"/run/podman/podman.sock",
	"/run/containerd/containerd.sock",
}

RuntimeSockets are the rootful container runtime sockets. A rootless runtime socket inside the container (lea's nested Podman under /run/user/<uid>/) is not one: it runs in the container's namespaces.

Functions

func Known

func Known(code string) bool

Known reports whether code is one of the reasons above.

func RuntimeGIDs

func RuntimeGIDs() []int

RuntimeGIDs are the groups that own a rootful runtime socket of this machine (RuntimeSockets) and may write it: a peer holding one can drive the runtime, whatever it reports. A socket its group cannot write (rootful Podman's root:root 0600) gives none. A console run on the host computes them itself; a containerized one is told them (--runtime-gids).

func Text

func Text(code string) string

Text is the human text of a reason code; "" for an unknown one.

Types

type Env

type Env struct {
	// GOOS is runtime.GOOS: only Linux has containers.
	GOOS string
	// Exists reports whether a path exists.
	Exists func(path string) bool
	// ReadFile reads a file (/proc/1/cgroup, /proc/self/mountinfo).
	ReadFile func(path string) ([]byte, error)
	// Connects reports whether a unix socket at path accepts a connection,
	// or refuses it for want of permission: a runtime socket mounted into
	// the container counts even when this account may not use it.
	Connects func(path string) bool
	// Readable reports whether the directory at path can be listed.
	Readable func(path string) bool
	// Writable reports whether the directory at path is writable
	// (access(2) W_OK: a read-only mount is not).
	Writable func(path string) bool
	Getenv   func(string) string
	Getwd    func() (string, error)
	HomeDir  func() (string, error)
}

Env is what Check reads; tests replace its functions.

func RealEnv

func RealEnv() Env

RealEnv is the process's own environment.

type Report

type Report struct {
	Confined bool
	// Reasons are the codes of the checks that failed, in check order.
	Reasons []string
}

Report is the outcome of Check.

func Check

func Check(env Env) Report

Check runs the four checks of env. The client is confined when all hold: it runs in a container, no rootful runtime socket connects, the Lock Family's state directory is absent or unreadable, and the nearest .lockfamily directory above the working directory, if any, is not writable.

Jump to

Keyboard shortcuts

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