dockerproxy

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const MaxBodyBytes = 32 * 1024 * 1024 // 32 MiB

MaxBodyBytes caps body reads to prevent DoS / memory exhaustion.

Variables

This section is empty.

Functions

func Reap

func Reap(ctx context.Context, upstreamSocket string, l *Ledger) error

Reap reads the ledger and issues stop+rm to the upstream Docker socket for every resource the job created. Deletion order is containers → networks → volumes (dependency order); exec entries are skipped because they are cleaned up automatically when their container is removed.

Individual stop/rm failures are logged and skipped rather than aborting, so a single stuck container does not prevent the rest from being cleaned up. C5 (cleanupSandboxAfterWait and the GC loop) calls this function.

func ResolveUpstream

func ResolveUpstream(explicit string) (string, error)

ResolveUpstream finds the upstream Docker socket path using this precedence:

  1. explicit — non-empty value from config (returned as-is, no existence check)
  2. DOCKER_HOST env var — must be unix:// prefix; TCP returns an error
  3. $XDG_RUNTIME_DIR/docker.sock — rootless
  4. /run/user/<uid>/docker.sock — rootless fallback
  5. /var/run/docker.sock — rootful

Types

type Ledger

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

Ledger persists Docker resource IDs created by a sandbox job to a JSONL file, enabling both id scope checks and GC (Reap) after the job exits. The file path (runtime directory) is injected by the caller; Ledger itself has no knowledge of the daemon's directory structure.

func NewLedger

func NewLedger(path string) *Ledger

NewLedger returns a Ledger backed by the given file path. The file is created on first Append if it does not exist.

func (*Ledger) Append

func (l *Ledger) Append(e ResourceEntry) error

Append writes the entry to the ledger file (append + fsync) before updating the in-memory cache. Callers must call Append before returning the creation response to the client so that "every ID the client knows is in the ledger".

func (*Ledger) Contains

func (l *Ledger) Contains(resourceType, id string) (bool, error)

Contains returns true when the ledger holds an entry with the given type and ID.

func (*Ledger) ReadAll

func (l *Ledger) ReadAll() ([]ResourceEntry, error)

ReadAll returns a snapshot of all entries currently in the ledger. Returns nil (not an error) when the ledger file does not exist yet.

type ResourceEntry

type ResourceEntry struct {
	Type string `json:"type"` // "container", "network", "volume", "exec"
	ID   string `json:"id"`
}

ResourceEntry is a single entry in the Docker resource ledger.

type Server

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

Server is a Docker API proxy that filters and forwards requests to an upstream Docker daemon via a Unix socket.

func New

func New(upstreamSocket string) *Server

New creates a Server that forwards to the given upstream Unix socket path.

func NewWithLedger

func NewWithLedger(upstreamSocket string, l *Ledger) *Server

NewWithLedger creates a Server with an attached resource ledger. The ledger enables id scope checks (404 for IDs not owned by this sandbox) and write-ahead ID recording from creation responses.

func (*Server) Close

func (s *Server) Close() error

Close shuts down the server.

func (*Server) Serve

func (s *Server) Serve(ln net.Listener) error

Serve begins accepting connections on ln. It blocks until Close is called.

type Verdict

type Verdict struct {
	Allow  bool
	Reason string // populated when Allow==false
}

Verdict is the result of a policy check.

func CheckRequest

func CheckRequest(method, path string, body []byte) Verdict

CheckRequest is the main policy entry point. method is the HTTP method, path is the raw request path (may include API version prefix), body is the request body bytes (may be nil for GET/HEAD).

Jump to

Keyboard shortcuts

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