compose

package
v0.298.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 18 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 compose is the provisioner driver for the chief on the public `docker compose` install: a container the Compose file declares (the `chief` service, `--profile chief`), configured by FILES this driver writes into a named volume the two containers share.

🔴 IT DOES NOT START, STOP OR CREATE CONTAINERS, AND THAT IS ITS DESIGN

Starting a container from muster means the Docker socket, and the socket is root on the host: any muster bug a prompt-injected agent could reach would become root. So the container exists because the Compose file says so, and what this driver controls is what that container RUNS:

  • Create and Update write the instance's spec (its environment, its secrets, the replica count it should run, a generation and a data epoch) and its files into <root>/<name>/. The container mounts that directory read-only; its supervisor (`ccd compose`, images/claude-code-agent) starts the agent when replicas is 1, stops it — the CLI and its tmux server, not the container — when it is 0, and restarts it when the generation changes. The generation moves when the spec does AND when replicas goes from 0 to 1, so a Stop then Start always changes spec.json.
  • Get and List read that directory, then ask the container itself (GET /compose/status on the instance's endpoint) what it has applied.
  • Destroy removes the spec and every file, so the container goes back to waiting; the next Create mints a NEW epoch, and the supervisor wipes the container's /data before it starts the agent on it.

What it does not do, stated

  • Exec: none, so no terminal and no in-container command (Capabilities.Exec is false). Logs: `docker compose logs chief`, never through muster.
  • Network confinement: none. The Compose file keeps the container off the network the database is on, but its egress is not restricted, so Capabilities.NetworkIsolation is false and a spec asking for isolation is refused (provision.CheckSpec) rather than started "confined".
  • Resource limits: none it can enforce (false, refused the same way).
  • More than one replica: none (Scale false).
  • Process isolation: Spec.Security (RunAsNonRoot, Restricted, the uid and groups) is NOT applied and NOT refused — this driver drops it. The agent's uid, capabilities and privilege escalation are whatever the Compose file and the image's supervisor give it.

Which instances it accepts

Config.Admit decides, on every Create and Update, before anything is written. The Compose file runs ONE chief container, so muster-server admits exactly one name (the install's chief); this package does not know what a chief is, and takes the rule as data.

The on-disk contract with the container

Written by this driver, read by `ccd compose` (cmd/ccd/compose.go), and the two must move together:

<root>/<name>/spec.json      the container's contract: [ContainerSpec],
                             written LAST, by rename, so a reader that sees
                             generation N sees N's files
<root>/<name>/files/<path>   each Spec.File at its absolute path minus the
                             leading slash (files/etc/claude-code/CLAUDE.md)
<root>/<name>/driver.json    this driver's own bookkeeping; not the contract

Directories are created setgid 0750, spec.json and driver.json written 0640, and each Spec.File with its requested mode less the "other" class (a mode whose group cannot read is refused: see diskMode), each with the group "Who can read what" below gives it; the container's mount is read-only, so nothing on the volume can be written from it.

Who can read what

🔴 spec.json HOLDS THE AGENT'S SECRETS — its muster token, its turn bearer and (on a subscription) its Claude token — AND THE AGENT'S OWN SESSION MUST NOT READ IT. The turn bearer is what drives the agent's turn API, and the claude-code image keeps it out of the session's reach on Kubernetes (cmd/ccd/turncred.go). So the Compose file runs the container's supervisor as a different identity from the agent (uid 0 with primary group Config.SpecGroup, no capability but changing uid and signalling), and the supervisor starts the agent as uid 1000 group 1000 and nothing else:

  • spec.json, driver.json and every directory outside files/ get SpecGroup: the supervisor can read them, the agent cannot;
  • everything under files/ gets Config.FilesGroup, the agent's group: the managed CLAUDE.md reaches it through the Compose file's chief-instructions volume, which muster mounts at files/etc/claude-code and the chief at /etc/claude-code, read-only (no volume `subpath`: Compose before 2.25 refuses a file that has one).

muster writes as its own uid with both groups as supplementary groups (the Compose file's group_add), which is what lets it give each path its group.

🔴 DIRECTORIES ARE NEVER REMOVED, only files. files/etc/claude-code is the root of a volume of its own (chief-instructions) that the chief mounts at /etc/claude-code; a mount point cannot be removed, and any other directory removed and re-created is a new inode that a running container never sees. Keeping the directories keeps every mount live across Destroy and Create.

Index

Constants

View Source
const (
	FileMode fs.FileMode = 0o640
	DirMode  fs.FileMode = fs.ModeSetgid | 0o750
)

File and directory modes on the shared volume (see the package doc).

View Source
const (
	StateAwaitingSpec = "awaiting_spec"
	StateOff          = "off"
	StateStarting     = "starting"
	StateRunning      = "running"
	StateExited       = "exited"
	StateError        = "error"
)

The supervisor's states (cmd/ccd/compose.go).

View Source
const ContainerSpecVersion = 1

ContainerSpecVersion is the version of ContainerSpec this driver writes. The supervisor refuses a version it does not know rather than guess.

View Source
const DefaultProbeTimeout = 2 * time.Second

DefaultProbeTimeout bounds one status probe.

View Source
const DriverName = "compose"

DriverName is what Driver returns, and the MUSTER_CHIEF_RUNTIME value that selects it.

View Source
const StatusPath = "/compose/status"

StatusPath is the supervisor's status route on the instance's endpoint.

Variables

View Source
var Capabilities = provision.Capabilities{
	Isolation:   provision.IsolationContainer,
	Secrets:     true,
	Files:       true,
	Persistence: true,
}

Capabilities is what this driver can do. See the package doc for each false.

View Source
var ErrNoLogs = fmt.Errorf("%w: compose: an instance's output is its container's; read it with `docker compose logs`", provision.ErrUnsupported)

ErrNoLogs is StreamLogs' answer for an instance that exists: its output is the container's, read with `docker compose logs`.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Root is the shared volume's mount point in muster's container. Required.
	Root string
	// Admit is asked before every Create and Update; an error refuses the
	// spec and nothing is written. Required: a driver that admitted anything
	// would accept agents the Compose file runs no container for.
	Admit func(provision.Ref) error
	// Probe replaces the HTTP status probe (tests). nil is HTTPProbe.
	Probe Prober
	// Capabilities replaces [Capabilities] (the contract suite's restricted
	// driver). nil is the default.
	Capabilities *provision.Capabilities
	// Hint is appended to the reason an unreachable container is reported
	// with, telling the operator how to start it.
	Hint string
	// SpecGroup and FilesGroup are the group ids the driver gives what it
	// writes (see the package doc's "Who can read what"): SpecGroup to
	// spec.json, driver.json and every directory outside files/, FilesGroup to
	// everything under files/. Both are required, non-zero and different: New
	// refuses anything else, because spec.json holds the agent's secrets.
	SpecGroup, FilesGroup int
	// Chown replaces the group change (tests). nil is os.Lchown(path, -1, gid).
	Chown func(path string, gid int) error
}

Config configures a Driver.

type ContainerSpec

type ContainerSpec struct {
	Version    int      `json:"version"`
	Name       string   `json:"name"`
	Generation int64    `json:"generation"`
	Replicas   int      `json:"replicas"`
	Epoch      string   `json:"epoch"`
	Env        []EnvVar `json:"env"`
	Secrets    []EnvVar `json:"secrets"`
}

ContainerSpec is spec.json: what the container's supervisor reads.

🔴 Secrets ARE PLAIN VALUES ON THE VOLUME. The volume is mounted into exactly two containers, muster's and this instance's, and the file is 0640 — the same exposure as a Kubernetes Secret volume, which is why the driver declares Capabilities.Secrets. The supervisor exports them into the agent's environment, as the Kubernetes driver's envFrom does.

type Driver

type Driver struct {
	// contains filtered or unexported fields
}

Driver is the compose provisioner.

func New

func New(cfg Config) (*Driver, error)

New validates cfg and returns a driver. It does not touch Root: the volume may be checked only when an instance is asked about, and a missing or unreadable root is then provision.ErrBlind.

func (*Driver) Capabilities

func (d *Driver) Capabilities() provision.Capabilities

Capabilities implements provision.Provisioner.

func (*Driver) Create

func (d *Driver) Create(ctx context.Context, spec provision.Spec) error

Create implements provision.Provisioner: idempotent for an identical spec, ErrDivergentSpec for a different one.

func (*Driver) Destroy

func (d *Driver) Destroy(ctx context.Context, ref provision.Ref) error

Destroy implements provision.Provisioner: spec.json first (the container stops the agent), then the files and driver.json; directories stay (see the package doc). nil only when nothing of the instance is left to read.

It never returns provision.ErrNotManaged: the volume is written by muster alone (the container's mount is read-only), so a directory under the instance's name that holds no driver.json is the Compose file's one-shot skeleton or an earlier Destroy, not a stranger's object.

func (*Driver) Driver

func (d *Driver) Driver() string

Driver implements provision.Provisioner.

func (*Driver) Endpoint

func (d *Driver) Endpoint(ctx context.Context, ref provision.Ref) (provision.Endpoint, error)

Endpoint implements provision.Provisioner.

func (*Driver) Get

func (d *Driver) Get(ctx context.Context, ref provision.Ref) (provision.Instance, error)

Get implements provision.Provisioner. It asks the container's own status whatever the stored replica count; fromStatus maps it for replicas 1 and fromStopStatus for replicas 0.

🔴 A STOP IS PROBED TOO. Scale(0) only writes spec.json, so the stored count says muster ASKED for a stop, not that one happened: the supervisor reports error ("the chief did not stop: <pid> … still running") when a process outlives the kill, and only that status can carry it to muster.

func (*Driver) List

func (d *Driver) List(ctx context.Context) ([]provision.Instance, error)

List implements provision.Provisioner: every directory under the root that holds a driver.json.

func (*Driver) Root

func (d *Driver) Root() string

Root is the shared volume's mount point.

func (*Driver) Scale

func (d *Driver) Scale(ctx context.Context, ref provision.Ref, replicas int) error

Scale implements provision.Provisioner: 0 or 1, rewritten into spec.json.

func (*Driver) StreamLogs

func (d *Driver) StreamLogs(ctx context.Context, ref provision.Ref, _ func(string)) error

StreamLogs implements provision.Provisioner.

func (*Driver) Update

func (d *Driver) Update(ctx context.Context, spec provision.Spec) error

Update implements provision.Provisioner: it writes spec over whatever is there (creating it when absent), with replicas from the spec, as the Kubernetes driver's Deployment does — Start relies on that.

type EnvVar

type EnvVar struct {
	Name  string `json:"name"`
	Value string `json:"value"`
}

EnvVar is one name and value in ContainerSpec.

type Prober

type Prober func(ctx context.Context, ep provision.Endpoint) (Status, error)

Prober asks the container at ep what it has applied.

func HTTPProbe

func HTTPProbe(client *http.Client, timeout time.Duration) Prober

HTTPProbe is the default Prober: GET <ep>/compose/status within timeout.

type Status

type Status struct {
	State      string `json:"state"`
	Generation int64  `json:"generation"`
	Replicas   int    `json:"replicas"`
	Epoch      string `json:"epoch"`
	Boot       string `json:"boot"`
	Ready      bool   `json:"ready"`
	Reason     string `json:"reason"`
}

Status is what the supervisor answers on StatusPath.

Generation and Epoch are those of the spec.json the supervisor last ATTEMPTED to apply, including one it failed on: an error about the current spec must carry the current generation, or Get reads it as not applied yet (fromStatus checks the generation before the state).

Boot identifies ONE RUN OF THE AGENT: the supervisor mints a new value every time it starts the agent (the container's first start, a restart on a new generation, a start after replicas 0), and keeps it while that run lasts. It is not per container: a restart of the agent inside a container that stayed up gets a new Boot. Get reports it as the InstanceID ("<name>-<boot>"), which is how a restart is told apart from the run before it.

Jump to

Keyboard shortcuts

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