dockerprovider

package
v0.3.4 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 29 Imported by: 0

Documentation

Overview

Package dockerprovider implements the honey Docker Engine search backend.

Search modes (YAML mode or --docker-mode): containers, swarm, or both. Results are hosts.Record rows with provider "docker" and meta.kind container or swarm_task.

Daemon connections:

  • Local or DOCKER_HOST (unix://, tcp://, https:// with optional TLS paths in config)
  • Moby ssh:// (Engine SDK SSH; no Honey ~/.ssh/config integration)
  • Honey SSH: via_local / via_ssh + socket + optional run_as (sudo -n -u … + docker system dial-stdio over an sshclient session; reuses TUI SSH when cached)

Auto-discover registers with searchrun.RegisterDockerDiscover. When HONEY_FEATURE_DOCKER_VIA_PROVIDERS=1 and --docker-discover-providers are set, searchrun runs a second pass over VM records from the already-filtered search (respecting --backends and --provider) and merges container rows.

Execution (terminals, parallel e, web exec, file browser) is wired through hostexec.SetDockerExecutor in internal/ui; the Moby client is github.com/moby/moby/client (API types in github.com/moby/moby/api).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContainerIDFromRecord

func ContainerIDFromRecord(containerID string) (string, error)

ContainerIDFromRecord returns the target container ID for exec/file ops.

func DefaultSocket

func DefaultSocket(platform string) string

DefaultSocket returns the default Engine socket path/URI for a platform.

func DialDockerCheck added in v0.3.3

func DialDockerCheck(user string, r hosts.Record, reg hostexec.Registry) error

DialDockerCheck verifies that a docker record can reach the Engine API (dial + close).

func DialSSH

func DialSSH(hop SSHHop, defaultUser string) (*ssh.Client, func(), error)

DialSSH opens an SSH client using Honey's sshclient stack.

func DiscoverOnVMs

func DiscoverOnVMs(ctx context.Context, q hosts.Query, vms []hosts.Record) ([]hosts.Record, error)

DiscoverOnVMs lists Docker containers on cloud VM records from an earlier search pass. VMs are already scoped by --backends / --provider filters on the parent search.

func DockerInteractiveShellCmd added in v0.3.3

func DockerInteractiveShellCmd(dc *DockerNativeClient) []string

DockerInteractiveShellCmd returns the shell command for an interactive session.

func DockerShellQuote added in v0.3.3

func DockerShellQuote(s string) string

DockerShellQuote returns a shell-safe single-quoted form of s.

func EffectiveDockerSSHUser added in v0.3.3

func EffectiveDockerSSHUser(user string, r hosts.Record) string

EffectiveDockerSSHUser returns the SSH user for docker transport resolution.

func FeatureDockerViaProviders

func FeatureDockerViaProviders() bool

FeatureDockerViaProviders reports whether auto-discover on cloud VMs is enabled.

func ListOptionsForBackend

func ListOptionsForBackend(all bool) client.ContainerListOptions

ListOptionsForBackend returns container list options for search.

func NewAPIClient

func NewAPIClient(ctx context.Context, b BackendConfig, opts APIClientOptions) (*client.Client, error)

NewAPIClient builds a Moby client for the given backend settings.

func NewAPIClientFromRuntime

func NewAPIClientFromRuntime(ctx context.Context, rt DockerBackendRuntime, opts APIClientOptions) (*client.Client, error)

NewAPIClientFromRuntime builds a client from hostexec runtime config.

func NewFactory added in v0.3.4

func NewFactory(interactive InteractiveRunner) searchrun.ProviderFactory

NewFactory returns a new factory for this provider. interactive (implemented in the ui package) is injected so resolver-created executors can run TTY sessions.

func NormalizeMode

func NormalizeMode(mode string) string

NormalizeMode returns containers, swarm, or both.

func NormalizePlatform

func NormalizePlatform(p string) string

NormalizePlatform returns linux or windows.

func RecordMetaBase

func RecordMetaBase(bc BackendConfig, hop SSHHop, discover bool) map[string]string

RecordMetaBase returns common docker record meta for a backend connection.

func RegisterFlags added in v0.3.3

func RegisterFlags(cmd *cobra.Command)

RegisterFlags adds Docker CLI flags to cmd.

func ResolveSocket

func ResolveSocket(socket, platform string) string

ResolveSocket returns configured socket or platform default.

func RunAsProxyCommandForTest

func RunAsProxyCommandForTest(runAs, socketPath string) string

RunAsProxyCommandForTest returns the remote command used for run_as dial (tests).

func VMRecordForHoneyDocker added in v0.3.3

func VMRecordForHoneyDocker(r hosts.Record) (hosts.Record, bool)

VMRecordForHoneyDocker extracts a VM hop record from docker record metadata.

Types

type APIClientOptions

type APIClientOptions struct {
	SSHUser      string
	BorrowedSSH  *ssh.Client
	OwnsSSH      bool // if true, close SSH on client close
	VMRecord     *hosts.Record
	DiscoverOpts *DiscoverOpts
}

APIClientOptions optional SSH borrow and user for honey-ssh transport.

type BackendConfig

type BackendConfig struct {
	Name          string
	Host          string
	ViaLocal      string
	ViaSSH        config.DockerViaSSH
	Socket        string
	Platform      string
	SSHUser       string
	RunAs         string
	LocalBackends []config.LocalBackend
	Mode          string
	AllContainers bool
	TLSVerify     bool
	CACert        string
	Cert          string
	Key           string
}

BackendConfig is the runtime settings for one docker backend (search + dial).

func BackendConfigFromYAML

func BackendConfigFromYAML(e config.DockerBackend, locals []config.LocalBackend, sshUser string) BackendConfig

BackendConfigFromYAML converts a config entry to BackendConfig.

func (BackendConfig) ResolvedHost

func (b BackendConfig) ResolvedHost() string

ResolvedHost returns the host URI stored on records for Moby-direct backends.

func (BackendConfig) UsesHoneySSH

func (b BackendConfig) UsesHoneySSH() bool

UsesHoneySSH reports whether this backend dials Docker via Honey SSH + remote socket.

type DialParams

type DialParams struct {
	Network string
	Address string
	HostURL string
}

DialParams describes how to dial the remote Engine socket over SSH.

func SocketDialParams

func SocketDialParams(socket, platform string) (DialParams, error)

SocketDialParams maps a socket URI and platform to SSH dial network/address and Moby host URL.

type DiscoverOpts

type DiscoverOpts struct {
	Socket   string
	Platform string
	RunAs    string
}

DiscoverOpts configures auto-discovery pass (feature-flag only).

type Docker

type Docker struct {
	Config BackendConfig
}

Docker implements hosts.Backend for Engine API search (local, Moby ssh://, or Honey SSH).

func (*Docker) BackendName

func (d *Docker) BackendName() string

BackendName returns the optional YAML backends.docker[].name value.

func (*Docker) CacheIdentity

func (d *Docker) CacheIdentity() string

CacheIdentity scopes cache entries per docker backend configuration.

func (*Docker) ID

func (d *Docker) ID() string

ID returns the honey backend identifier ("docker").

func (*Docker) Search

func (d *Docker) Search(ctx context.Context, q hosts.Query) ([]hosts.Record, error)

Search lists containers and/or swarm tasks from the configured Engine endpoint.

type DockerBackendRuntime added in v0.3.3

type DockerBackendRuntime struct {
	Name          string
	Host          string
	ViaLocal      string
	ViaSSH        config.DockerViaSSH
	Socket        string
	Platform      string
	RunAs         string
	Transport     string
	LocalBackends []config.LocalBackend
	TLSVerify     bool
	CACert        string
	Cert          string
	Key           string
}

DockerBackendRuntime holds Docker API connection settings.

func BackendByName added in v0.3.3

func BackendByName(name string) (DockerBackendRuntime, bool)

BackendByName returns runtime config for a named Docker backend (empty name matches first entry).

type DockerExecutor added in v0.3.3

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

DockerExecutor implements hostexec.Executor for Docker containers.

func (*DockerExecutor) Dial added in v0.3.3

Dial connects to the Docker container and returns a DockerNativeClient.

func (*DockerExecutor) DialDockerClient added in v0.3.4

func (e *DockerExecutor) DialDockerClient(user string, r hosts.Record) (*client.Client, error)

DialDockerClient builds a moby client from record metadata (transport resolution).

func (*DockerExecutor) DialUpstream added in v0.3.3

func (e *DockerExecutor) DialUpstream(_ context.Context, user string, r hosts.Record, address string) (net.Conn, error)

DialUpstream connects to a port inside the container via nc/socat.

func (*DockerExecutor) RunInteractive added in v0.3.3

func (e *DockerExecutor) RunInteractive(user string, r hosts.Record) error

RunInteractive delegates to the injected InteractiveRunner.

func (*DockerExecutor) RunTunnel added in v0.3.3

RunTunnel is not supported for Docker containers.

type DockerNativeClient added in v0.3.3

type DockerNativeClient struct {
	Cli         *client.Client
	ContainerID string
	ContainerOS string
}

DockerNativeClient implements hostexec.HostClient via the Docker Engine API.

func (*DockerNativeClient) Close added in v0.3.3

func (c *DockerNativeClient) Close() error

Close closes the underlying Docker client connection.

func (*DockerNativeClient) Download added in v0.3.3

func (c *DockerNativeClient) Download(remotePath, localPath string) error

Download copies a file from the container to localPath.

func (*DockerNativeClient) ExecInteractive added in v0.3.3

func (c *DockerNativeClient) ExecInteractive(
	ctx context.Context,
	cmd []string,
	execEnv []string,
	stdin io.Reader,
	stdout io.Writer,
	cols, rows int,
	resizeCh <-chan DockerTerminalSize,
) error

ExecInteractive runs a TTY exec with bidirectional I/O and optional resize events.

func (*DockerNativeClient) IsWindowsContainer added in v0.3.3

func (c *DockerNativeClient) IsWindowsContainer() bool

IsWindowsContainer reports whether the container runs Windows.

func (*DockerNativeClient) ListRemoteDir added in v0.3.3

func (c *DockerNativeClient) ListRemoteDir(dir string) ([]hostexec.RemoteFileEntry, error)

ListRemoteDir lists files in dir inside the container.

func (*DockerNativeClient) MkdirAllRemote added in v0.3.3

func (c *DockerNativeClient) MkdirAllRemote(remotePath string) error

MkdirAllRemote creates remotePath (and parents) inside the container.

func (*DockerNativeClient) RemoveRemote added in v0.3.3

func (c *DockerNativeClient) RemoveRemote(remotePath string, recursive bool) error

RemoveRemote deletes remotePath inside the container; recursive removes directories.

func (*DockerNativeClient) Run added in v0.3.3

func (c *DockerNativeClient) Run(cmd string) ([]byte, error)

Run executes cmd in the container and returns combined stdout.

func (*DockerNativeClient) RunWithStreams added in v0.3.3

func (c *DockerNativeClient) RunWithStreams(cmd string, stdin io.Reader, stdout, stderr io.Writer) error

RunWithStreams executes cmd in the container with the provided I/O streams.

func (*DockerNativeClient) StatRemote added in v0.3.3

func (c *DockerNativeClient) StatRemote(remotePath string) (hostexec.RemoteFileEntry, error)

StatRemote returns metadata for remotePath inside the container.

func (*DockerNativeClient) Upload added in v0.3.3

func (c *DockerNativeClient) Upload(localPath, remotePath string) error

Upload copies a local file into the container at remotePath.

type DockerTerminalSize added in v0.3.3

type DockerTerminalSize struct {
	Cols int
	Rows int
}

DockerTerminalSize is a cols/rows pair for docker exec resize.

type InteractiveRunner added in v0.3.4

type InteractiveRunner interface {
	RunInteractive(user string, r hosts.Record, reg hostexec.Registry) error
}

InteractiveRunner runs an interactive TTY session against a Docker container. It is implemented in the ui package and injected via NewFactory to keep dockerprovider a leaf package (ui imports dockerprovider, not vice versa).

type SSHHop

type SSHHop struct {
	Host         string
	Port         int
	User         string
	IdentityFile string
}

SSHHop is a resolved SSH target for Honey SSH transport to Docker.

func ResolveSSHHop

func ResolveSSHHop(bc BackendConfig, vm *hosts.Record) (SSHHop, bool, error)

ResolveSSHHop resolves SSH settings from backend config, optional local backends, or a VM record.

func (SSHHop) HopRecord

func (h SSHHop) HopRecord() hosts.Record

HopRecord builds a hosts.Record used for ClientCache key lookup.

func (SSHHop) RecordHostURI

func (h SSHHop) RecordHostURI() string

RecordHostURI returns a stable label stored on docker records.

Jump to

Keyboard shortcuts

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