dockercompose

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package dockercompose validates and runs docker compose invocations safely.

Index

Constants

This section is empty.

Variables

View Source
var ErrResolve = errors.New("safe docker-compose: resolve failed")

ErrResolve wraps any failure to resolve the Compose model (for example an invalid compose file or a docker error).

Functions

func CheckCLI

func CheckCLI(p ParsedArgs) []safe.Violation

CheckCLI refuses subcommands that are entrypoints for arbitrary command execution, and fails closed on any leading flag ParseArgs could not classify.

func CheckModel

func CheckModel(m Model, cwd string) []safe.Violation

CheckModel validates the resolved Compose model against the built-in rules, using cwd as the mount boundary.

func Prepare

func Prepare(ctx context.Context, args []string, cwd string, r Resolver) ([]safe.Violation, error)

Prepare runs the full safety pipeline for a docker compose invocation.

It parses args, applies CLI-level rules (which short-circuit before any docker process runs), resolves the canonical model, and applies model-level rules. The returned slice lists every violation found; an empty slice means the invocation is safe to execute. A non-nil error indicates an operational failure (the model could not be resolved) and the caller must run nothing.

func WantsGlobalHelp

func WantsGlobalHelp(args []string) bool

WantsGlobalHelp reports whether args request help at the global level (`docker-compose --help` or `-h`), before any subcommand.

Types

type Model

type Model struct {
	Services map[string]Service `json:"services"`
}

Model is the resolved Compose project as emitted by `docker compose config`.

func DecodeModel

func DecodeModel(data []byte) (Model, error)

DecodeModel parses `docker compose config --format json` output.

type Mount

type Mount struct {
	Type   string `json:"type"`   // "bind", "volume", or "tmpfs"
	Source string `json:"source"` // absolute host path for bind; volume name for volume
	Target string `json:"target"`
}

Mount is a normalized service mount from the resolved Compose model.

type ParsedArgs

type ParsedArgs struct {
	GlobalFlags   []string // global flags (and their values) before the subcommand
	Subcommand    string   // e.g. "up", "run"; "" when none is present
	Rest          []string // subcommand and everything after it
	Unrecognized  string   // a leading flag we could not classify; "" when none
	HelpRequested bool     // --help / -h given at the global level (before any subcommand)
}

ParsedArgs is the result of separating docker compose global flags from the subcommand and its arguments.

func ParseArgs

func ParseArgs(args []string) ParsedArgs

ParseArgs walks the leading flags, treating the first non-flag token as the subcommand. Every leading flag must be a recognized docker compose global flag; an unrecognized one sets Unrecognized and stops parsing, so the caller can fail closed rather than misidentify the subcommand and run it anyway.

type Resolver

type Resolver interface {
	Resolve(ctx context.Context, globalFlags []string) (Model, error)
}

Resolver produces the canonical Compose model for the given global flags.

func NewResolver

func NewResolver() Resolver

NewResolver returns the default Resolver, which runs `docker compose <globalFlags> config --format json`.

type Service

type Service struct {
	Privileged  bool              `json:"privileged"`
	NetworkMode string            `json:"network_mode"`
	Pid         string            `json:"pid"`
	Ipc         string            `json:"ipc"`
	UsernsMode  string            `json:"userns_mode"`
	CapAdd      []string          `json:"cap_add"`
	SecurityOpt []string          `json:"security_opt"`
	Devices     []json.RawMessage `json:"devices"`
	Volumes     []Mount           `json:"volumes"`
}

Service holds the security-relevant fields of one resolved service.

Jump to

Keyboard shortcuts

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