Documentation
¶
Overview ¶
Package docker provides a secure Docker client wrapper for HostMCP. This package implements controlled access to Docker containers through a security policy layer, enabling AI assistants to interact with containers in a safe and restricted manner.
The package wraps the official Docker SDK client and enforces security policies defined in the security package. All container operations are checked against the policy before execution.
dockerパッケージはHostMCP用のセキュアなDockerクライアントラッパーを提供します。 このパッケージはセキュリティポリシーレイヤーを通じてDockerコンテナへの 制御されたアクセスを実装し、AIアシスタントが安全かつ制限された方法で コンテナと対話できるようにします。
このパッケージは公式Docker SDKクライアントをラップし、securityパッケージで 定義されたセキュリティポリシーを適用します。すべてのコンテナ操作は 実行前にポリシーに対してチェックされます。
Package docker provides a secure Docker client wrapper for HostMCP. This file defines the DockerClientInterface that allows for dependency injection and mock-based testing of Docker operations.
dockerパッケージはHostMCP用のセキュアなDockerクライアントラッパーを提供します。 このファイルはDocker操作の依存性注入とモックベースのテストを可能にする DockerClientInterfaceを定義しています。
Package docker provides a mock Docker client for testing. This file contains the MockClient implementation which allows testing MCP handlers and other components without requiring a real Docker daemon.
dockerパッケージはテスト用のモックDockerクライアントを提供します。 このファイルは実際のDockerデーモンを必要とせずにMCPハンドラーや 他のコンポーネントをテストできるMockClient実装を含んでいます。
Index ¶
- type Client
- func (c *Client) Close() error
- func (c *Client) Exec(ctx context.Context, containerName string, command string, dangerously bool) (*ExecResult, error)
- func (c *Client) GetAllContainersWithCommands() map[string][]string
- func (c *Client) GetAllDangerousCommands() map[string][]string
- func (c *Client) GetAllowedCommands(containerName string) []string
- func (c *Client) GetBlockedPaths() []security.BlockedPath
- func (c *Client) GetBlockedPathsForContainer(containerName string) []security.BlockedPath
- func (c *Client) GetDangerousCommandsForContainer(containerName string) []string
- func (c *Client) GetLogs(ctx context.Context, containerName string, tail string, since string, ...) (string, error)
- func (c *Client) GetPolicy() *security.Policy
- func (c *Client) GetSecurityPolicy() map[string]any
- func (c *Client) GetStats(ctx context.Context, containerName string) (*container.StatsResponse, error)
- func (c *Client) InitBlockedPaths(containers []string) error
- func (c *Client) InspectContainer(ctx context.Context, containerName string) (*types.ContainerJSON, error)
- func (c *Client) IsDangerousModeEnabled() bool
- func (c *Client) ListContainers(ctx context.Context) ([]ContainerInfo, error)
- func (c *Client) ListFiles(ctx context.Context, containerName string, path string) (*FileAccessResult, error)
- func (c *Client) ReadFile(ctx context.Context, containerName string, path string, maxLines int) (*FileAccessResult, error)
- func (c *Client) RestartContainer(ctx context.Context, containerName string, timeout *int) error
- func (c *Client) StartContainer(ctx context.Context, containerName string) error
- func (c *Client) StopContainer(ctx context.Context, containerName string, timeout *int) error
- type ContainerInfo
- type DockerClientInterface
- type ExecResult
- type FileAccessResult
- type MockClient
- func (m *MockClient) Close() error
- func (m *MockClient) Exec(ctx context.Context, containerName string, command string, dangerously bool) (*ExecResult, error)
- func (m *MockClient) GetAllContainersWithCommands() map[string][]string
- func (m *MockClient) GetAllDangerousCommands() map[string][]string
- func (m *MockClient) GetAllowedCommands(containerName string) []string
- func (m *MockClient) GetBlockedPaths() []security.BlockedPath
- func (m *MockClient) GetBlockedPathsForContainer(containerName string) []security.BlockedPath
- func (m *MockClient) GetDangerousCommandsForContainer(containerName string) []string
- func (m *MockClient) GetLogs(ctx context.Context, containerName string, tail string, since string, ...) (string, error)
- func (m *MockClient) GetPolicy() *security.Policy
- func (m *MockClient) GetSecurityPolicy() map[string]any
- func (m *MockClient) GetStats(ctx context.Context, containerName string) (*container.StatsResponse, error)
- func (m *MockClient) InspectContainer(ctx context.Context, containerName string) (*types.ContainerJSON, error)
- func (m *MockClient) IsDangerousModeEnabled() bool
- func (m *MockClient) ListContainers(ctx context.Context) ([]ContainerInfo, error)
- func (m *MockClient) ListFiles(ctx context.Context, containerName string, path string) (*FileAccessResult, error)
- func (m *MockClient) ReadFile(ctx context.Context, containerName string, path string, maxLines int) (*FileAccessResult, error)
- func (m *MockClient) RestartContainer(ctx context.Context, containerName string, timeout *int) error
- func (m *MockClient) StartContainer(ctx context.Context, containerName string) error
- func (m *MockClient) StopContainer(ctx context.Context, containerName string, timeout *int) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client wraps the Docker client with security policy enforcement. It provides methods for container operations that are filtered and controlled by the associated security policy.
All operations check the security policy before accessing Docker, ensuring that only permitted containers and commands can be accessed.
ClientはセキュリティポリシーをDockerクライアントにラップします。 関連付けられたセキュリティポリシーによってフィルタリングおよび 制御されるコンテナ操作用のメソッドを提供します。
すべての操作はDockerにアクセスする前にセキュリティポリシーをチェックし、 許可されたコンテナとコマンドのみがアクセス可能であることを保証します。
func NewClient ¶
NewClient creates a new Docker client with security policy enforcement. It initializes the Docker SDK client using environment variables (DOCKER_HOST, DOCKER_API_VERSION, etc.) and wraps it with the provided security policy.
The policy parameter must not be nil - this ensures that all container operations are always subject to security checks.
Returns an error if the policy is nil or if the Docker client cannot be created (e.g., Docker daemon is not running).
NewClientはセキュリティポリシーを適用した新しいDockerクライアントを作成します。 環境変数(DOCKER_HOST、DOCKER_API_VERSIONなど)を使用してDocker SDKクライアントを 初期化し、提供されたセキュリティポリシーでラップします。
policyパラメータはnilであってはなりません - これにより、すべての コンテナ操作が常にセキュリティチェックの対象となることが保証されます。
ポリシーがnilの場合、またはDockerクライアントを作成できない場合 (例:Dockerデーモンが実行されていない場合)にエラーを返します。
func (*Client) Close ¶
Close closes the Docker client and releases associated resources. This should be called when the client is no longer needed.
Closeは Dockerクライアントを閉じ、関連リソースを解放します。 クライアントが不要になったときに呼び出す必要があります。
func (*Client) Exec ¶
func (c *Client) Exec(ctx context.Context, containerName string, command string, dangerously bool) (*ExecResult, error)
Exec executes a whitelisted command in a container. The command must be explicitly allowed in the security policy's exec_whitelist for the specific container.
This is a critical security feature - it prevents arbitrary command execution while still allowing specific, pre-approved commands (e.g., "npm test", "npm run lint").
The command string is parsed by splitting on whitespace. For complex commands with quoted arguments, this parsing may need enhancement.
Execはコンテナ内でホワイトリストに登録されたコマンドを実行します。 コマンドは特定のコンテナに対するセキュリティポリシーのexec_whitelistで 明示的に許可されている必要があります。
これは重要なセキュリティ機能です - 任意のコマンド実行を防止しながら、 特定の事前承認されたコマンド(例:"npm test"、"npm run lint")を 許可します。
コマンド文字列は空白で分割して解析されます。引用符付き引数を含む 複雑なコマンドの場合、この解析は強化が必要かもしれません。
func (*Client) GetAllContainersWithCommands ¶
GetAllContainersWithCommands returns a map of all containers and their respective whitelisted commands.
The map keys are container names (or patterns like "securenote-*"), and values are slices of allowed command strings.
GetAllContainersWithCommandsはすべてのコンテナとそれぞれの ホワイトリストコマンドのマップを返します。
マップのキーはコンテナ名(または"securenote-*"のようなパターン)、 値は許可されたコマンド文字列のスライスです。
func (*Client) GetAllDangerousCommands ¶
GetAllDangerousCommands returns a map of all containers and their dangerous commands. Returns a map of container name to list of dangerous commands. Includes the special "*" entry for global commands.
GetAllDangerousCommandsはすべてのコンテナとそれぞれの危険コマンドのマップを返します。 コンテナ名から危険コマンドリストへのマップを返します。 グローバルコマンドの特別な"*"エントリを含みます。
func (*Client) GetAllowedCommands ¶
GetAllowedCommands returns the list of commands that are whitelisted for execution in the specified container.
This is useful for discovering what commands an AI assistant can run in a particular container.
GetAllowedCommandsは指定されたコンテナで実行がホワイトリストに 登録されているコマンドのリストを返します。
これはAIアシスタントが特定のコンテナで実行できるコマンドを 発見するのに役立ちます。
func (*Client) GetBlockedPaths ¶
func (c *Client) GetBlockedPaths() []security.BlockedPath
GetBlockedPaths returns all blocked file paths defined in the security policy. These are paths that cannot be accessed through ListFiles or ReadFile.
GetBlockedPathsはセキュリティポリシーで定義されたすべての ブロックされたファイルパスを返します。 これらはListFilesまたはReadFileを通じてアクセスできないパスです。
func (*Client) GetBlockedPathsForContainer ¶
func (c *Client) GetBlockedPathsForContainer(containerName string) []security.BlockedPath
GetBlockedPathsForContainer returns blocked paths for a specific container. This includes both container-specific and global blocked paths.
GetBlockedPathsForContainerは特定のコンテナのブロックパスを返します。 これにはコンテナ固有とグローバルの両方のブロックパスが含まれます。
func (*Client) GetDangerousCommandsForContainer ¶
GetDangerousCommandsForContainer returns the dangerous commands allowed for a container. Includes both container-specific commands and global commands (*).
This is useful for discovering what commands can be executed with dangerously=true in a particular container.
GetDangerousCommandsForContainerはコンテナで許可される危険コマンドを返します。 コンテナ固有のコマンドとグローバルコマンド(*)の両方を含みます。
これはdangerously=trueで特定のコンテナで実行できるコマンドを 発見するのに役立ちます。
func (*Client) GetLogs ¶
func (c *Client) GetLogs(ctx context.Context, containerName string, tail string, since string, follow bool) (string, error)
GetLogs retrieves the logs from a specified container. The logs include both stdout and stderr with timestamps.
Parameters:
- containerName: The name or ID of the container
- tail: Number of lines to retrieve from the end (e.g., "100", "all")
- since: Show logs since timestamp (e.g., "2024-01-01T00:00:00Z") or relative (e.g., "42m"). Empty string disables filter.
- follow: Whether to stream logs continuously (not typically used in MCP)
This method requires both "logs" permission and access to the specified container according to the security policy.
GetLogsは指定されたコンテナからログを取得します。 ログには標準出力と標準エラー出力の両方がタイムスタンプ付きで含まれます。
パラメータ:
- containerName: コンテナの名前またはID
- tail: 末尾から取得する行数(例:"100"、"all")
- since: ログ表示開始タイムスタンプ(例:"2024-01-01T00:00:00Z")または相対時間(例:"42m")。空文字列でフィルタ無効。
- follow: ログを継続的にストリームするかどうか(MCPでは通常使用しない)
このメソッドはセキュリティポリシーに従って"logs"権限と 指定されたコンテナへのアクセスの両方が必要です。
func (*Client) GetPolicy ¶
GetPolicy returns the security policy associated with this client. This can be used to access policy features like output masking.
GetPolicyはこのクライアントに関連付けられたセキュリティポリシーを返します。 これは出力マスキングなどのポリシー機能にアクセスするために使用できます。
func (*Client) GetSecurityPolicy ¶
GetSecurityPolicy returns the current security policy configuration as a map. This provides visibility into the active security settings.
The returned map includes mode, permissions, allowed containers, and other policy details.
GetSecurityPolicyは現在のセキュリティポリシー設定をマップとして返します。 これにより、アクティブなセキュリティ設定への可視性が提供されます。
返されるマップにはモード、権限、許可コンテナ、 その他のポリシー詳細が含まれます。
func (*Client) GetStats ¶
func (c *Client) GetStats(ctx context.Context, containerName string) (*container.StatsResponse, error)
GetStats retrieves resource usage statistics for a container. This includes CPU, memory, network, and I/O statistics.
The statistics are a point-in-time snapshot (not streaming).
This method requires both "stats" permission and access to the specified container according to the security policy.
GetStatsはコンテナのリソース使用統計を取得します。 これにはCPU、メモリ、ネットワーク、I/O統計が含まれます。
統計はポイントインタイムのスナップショットです(ストリーミングではありません)。
このメソッドはセキュリティポリシーに従って"stats"権限と 指定されたコンテナへのアクセスの両方が必要です。
func (*Client) InitBlockedPaths ¶
InitBlockedPaths initializes the blocked paths manager with a list of containers. This should be called during startup to set up path blocking.
InitBlockedPathsはコンテナのリストでブロックパスマネージャを初期化します。 パスブロッキングを設定するために起動時に呼び出す必要があります。
func (*Client) InspectContainer ¶
func (c *Client) InspectContainer(ctx context.Context, containerName string) (*types.ContainerJSON, error)
InspectContainer retrieves detailed information about a specific container. This includes configuration, network settings, mount points, and more.
The returned ContainerJSON contains comprehensive container details from the Docker API.
This method requires both "inspect" permission and access to the specified container according to the security policy.
InspectContainerは特定のコンテナに関する詳細情報を取得します。 これには設定、ネットワーク設定、マウントポイントなどが含まれます。
返されるContainerJSONにはDocker APIからの包括的な コンテナ詳細が含まれます。
このメソッドはセキュリティポリシーに従って"inspect"権限と 指定されたコンテナへのアクセスの両方が必要です。
func (*Client) IsDangerousModeEnabled ¶
IsDangerousModeEnabled returns whether dangerous mode is globally enabled.
When dangerous mode is enabled, commands from exec_dangerously list can be executed using the dangerously=true parameter.
IsDangerousModeEnabledは危険モードがグローバルに有効かどうかを返します。
危険モードが有効な場合、dangerously=trueパラメータを使用して exec_dangerouslyリストのコマンドを実行できます。
func (*Client) ListContainers ¶
func (c *Client) ListContainers(ctx context.Context) ([]ContainerInfo, error)
ListContainers retrieves a list of all containers that are accessible according to the security policy. It filters out containers that don't match the allowed container patterns defined in the policy.
This method requires the "inspect" permission to be enabled in the policy.
Returns a slice of ContainerInfo for accessible containers, or an error if the permission is denied or if the Docker API call fails.
ListContainersはセキュリティポリシーに従ってアクセス可能な すべてのコンテナのリストを取得します。ポリシーで定義された 許可コンテナパターンに一致しないコンテナをフィルタリングします。
このメソッドはポリシーで"inspect"権限が有効になっている必要があります。
アクセス可能なコンテナのContainerInfoスライスを返します。 権限が拒否された場合やDocker API呼び出しが失敗した場合はエラーを返します。
func (*Client) ListFiles ¶
func (c *Client) ListFiles(ctx context.Context, containerName string, path string) (*FileAccessResult, error)
ListFiles lists files and directories in a container at the specified path. The path is checked against the security policy's blocked paths before access.
If the path is blocked, the result will indicate the block with details about why access was denied (e.g., security-sensitive directory).
This method internally executes "ls -la" in the container.
ListFilesはコンテナ内の指定されたパスにあるファイルとディレクトリを一覧表示します。 アクセス前にパスはセキュリティポリシーのブロックパスに対してチェックされます。
パスがブロックされている場合、結果はアクセスが拒否された理由 (例:セキュリティ上重要なディレクトリ)の詳細とともにブロックを示します。
このメソッドは内部的にコンテナ内で"ls -la"を実行します。
func (*Client) ReadFile ¶
func (c *Client) ReadFile(ctx context.Context, containerName string, path string, maxLines int) (*FileAccessResult, error)
ReadFile reads the contents of a file from a container. The path is checked against the security policy's blocked paths before access.
Parameters:
- containerName: The name or ID of the container
- path: The absolute path to the file in the container
- maxLines: Maximum number of lines to read (0 = all lines)
If maxLines > 0, uses "head -n" to limit output; otherwise uses "cat".
ReadFileはコンテナからファイルの内容を読み取ります。 アクセス前にパスはセキュリティポリシーのブロックパスに対してチェックされます。
パラメータ:
- containerName: コンテナの名前またはID
- path: コンテナ内のファイルへの絶対パス
- maxLines: 読み取る最大行数(0 = すべての行)
maxLines > 0の場合は"head -n"を使用して出力を制限し、そうでなければ"cat"を使用します。
func (*Client) RestartContainer ¶
RestartContainer restarts a container using Docker API directly. Checks lifecycle permission before executing.
RestartContainerはDocker APIを直接使用してコンテナを再起動します。 実行前にlifecycleパーミッションをチェックします。
func (*Client) StartContainer ¶
StartContainer starts a stopped container using Docker API directly. Checks lifecycle permission before executing.
StartContainerはDocker APIを直接使用して停止中のコンテナを起動します。 実行前にlifecycleパーミッションをチェックします。
func (*Client) StopContainer ¶
StopContainer stops a running container using Docker API directly. Checks lifecycle permission before executing.
StopContainerはDocker APIを直接使用して実行中のコンテナを停止します。 実行前にlifecycleパーミッションをチェックします。
type ContainerInfo ¶
type ContainerInfo struct {
// ID is the truncated container ID (first 12 characters).
// IDは短縮されたコンテナID(最初の12文字)です。
ID string `json:"id"`
// Name is the container name without the leading slash.
// Nameは先頭のスラッシュを除いたコンテナ名です。
Name string `json:"name"`
// Image is the name of the Docker image used by the container.
// ImageはコンテナがつかっているDockerイメージの名前です。
Image string `json:"image"`
// State is the current state (e.g., "running", "exited").
// Stateは現在の状態(例:"running"、"exited")です。
State string `json:"state"`
// Status is a human-readable status string (e.g., "Up 2 hours").
// Statusは人が読める状態文字列(例:"Up 2 hours")です。
Status string `json:"status"`
// Created is the Unix timestamp when the container was created.
// Createdはコンテナが作成されたUnixタイムスタンプです。
Created int64 `json:"created"`
// Labels contains the container's labels as key-value pairs.
// Labelsはコンテナのラベルをキーと値のペアとして含みます。
Labels map[string]string `json:"labels,omitempty"`
// Ports contains the port mappings as formatted strings.
// Example: ["0.0.0.0:80->80/tcp", "443/tcp"]
// Portsはフォーマットされた文字列としてのポートマッピングを含みます。
// 例: ["0.0.0.0:80->80/tcp", "443/tcp"]
Ports []string `json:"ports,omitempty"`
}
ContainerInfo represents simplified container information returned by the ListContainers method. It contains the essential details about a container that are safe to expose.
ContainerInfoはListContainersメソッドによって返される 簡略化されたコンテナ情報を表します。公開しても安全な コンテナに関する重要な詳細を含みます。
type DockerClientInterface ¶
type DockerClientInterface interface {
// ListContainers retrieves a list of all containers accessible
// according to the security policy.
// ListContainersはセキュリティポリシーに従ってアクセス可能な
// すべてのコンテナのリストを取得します。
ListContainers(ctx context.Context) ([]ContainerInfo, error)
// GetLogs retrieves logs from a specified container.
// The since parameter filters logs to only show entries after the given timestamp
// (e.g., "2024-01-01T00:00:00Z") or relative time (e.g., "42m" for 42 minutes ago).
// Pass an empty string to disable the filter.
//
// GetLogsは指定されたコンテナからログを取得します。
// sinceパラメータは指定されたタイムスタンプ(例:"2024-01-01T00:00:00Z")
// または相対時間(例:"42m"で42分前)以降のログのみを表示するフィルタです。
// フィルタを無効にするには空文字列を渡します。
GetLogs(ctx context.Context, containerName string, tail string, since string, follow bool) (string, error)
// GetStats retrieves resource usage statistics for a container.
// GetStatsはコンテナのリソース使用統計を取得します。
GetStats(ctx context.Context, containerName string) (*container.StatsResponse, error)
// Exec executes a whitelisted command in a container.
// Execはコンテナ内でホワイトリストに登録されたコマンドを実行します。
Exec(ctx context.Context, containerName string, command string, dangerously bool) (*ExecResult, error)
// InspectContainer retrieves detailed information about a container.
// InspectContainerはコンテナの詳細情報を取得します。
InspectContainer(ctx context.Context, containerName string) (*types.ContainerJSON, error)
// RestartContainer restarts a container using Docker API directly.
// timeout is optional (nil = Docker default 10s).
// RestartContainerはDocker APIを直接使用してコンテナを再起動します。
RestartContainer(ctx context.Context, containerName string, timeout *int) error
// StopContainer stops a running container using Docker API directly.
// timeout is optional (nil = Docker default 10s).
// StopContainerはDocker APIを直接使用して実行中のコンテナを停止します。
StopContainer(ctx context.Context, containerName string, timeout *int) error
// StartContainer starts a stopped container using Docker API directly.
// StartContainerはDocker APIを直接使用して停止中のコンテナを起動します。
StartContainer(ctx context.Context, containerName string) error
// ListFiles lists files in a container directory.
// ListFilesはコンテナディレクトリ内のファイルを一覧表示します。
ListFiles(ctx context.Context, containerName string, path string) (*FileAccessResult, error)
// ReadFile reads the contents of a file from a container.
// ReadFileはコンテナからファイルの内容を読み取ります。
ReadFile(ctx context.Context, containerName string, path string, maxLines int) (*FileAccessResult, error)
// GetPolicy returns the security policy associated with this client.
// GetPolicyはこのクライアントに関連付けられたセキュリティポリシーを返します。
GetPolicy() *security.Policy
// GetAllowedCommands returns the whitelisted commands for a container.
// GetAllowedCommandsはコンテナのホワイトリストコマンドを返します。
GetAllowedCommands(containerName string) []string
// GetSecurityPolicy returns the current security policy configuration.
// GetSecurityPolicyは現在のセキュリティポリシー設定を返します。
GetSecurityPolicy() map[string]any
// GetAllContainersWithCommands returns all containers and their commands.
// GetAllContainersWithCommandsはすべてのコンテナとそのコマンドを返します。
GetAllContainersWithCommands() map[string][]string
// IsDangerousModeEnabled returns whether dangerous mode is enabled.
// IsDangerousModeEnabledは危険モードが有効かどうかを返します。
IsDangerousModeEnabled() bool
// GetDangerousCommandsForContainer returns dangerous commands for a container.
// GetDangerousCommandsForContainerはコンテナの危険コマンドを返します。
GetDangerousCommandsForContainer(containerName string) []string
// GetAllDangerousCommands returns all containers and their dangerous commands.
// GetAllDangerousCommandsはすべてのコンテナとその危険コマンドを返します。
GetAllDangerousCommands() map[string][]string
// GetBlockedPaths returns all blocked file paths.
// GetBlockedPathsはすべてのブロックされたファイルパスを返します。
GetBlockedPaths() []security.BlockedPath
// GetBlockedPathsForContainer returns blocked paths for a specific container.
// GetBlockedPathsForContainerは特定のコンテナのブロックパスを返します。
GetBlockedPathsForContainer(containerName string) []security.BlockedPath
// Close closes the Docker client and releases resources.
// CloseはDockerクライアントを閉じ、リソースを解放します。
Close() error
}
DockerClientInterface defines the interface for Docker client operations. This interface allows for dependency injection and mock-based testing without requiring a real Docker daemon connection.
All implementations must enforce security policies for container access, command execution, and file operations.
DockerClientInterfaceはDockerクライアント操作のインターフェースを定義します。 このインターフェースは実際のDockerデーモン接続を必要とせずに、 依存性注入とモックベースのテストを可能にします。
すべての実装はコンテナアクセス、コマンド実行、ファイル操作に対する セキュリティポリシーを適用する必要があります。
type ExecResult ¶
type ExecResult struct {
// ExitCode is the exit status of the command (0 typically means success).
// ExitCodeはコマンドの終了ステータスです(0は通常成功を意味します)。
ExitCode int `json:"exit_code"`
// Output contains the combined stdout and stderr from the command.
// Outputはコマンドからの標準出力と標準エラー出力の組み合わせを含みます。
Output string `json:"output"`
}
ExecResult represents the result of executing a command in a container. It contains the exit code and the combined stdout/stderr output.
ExecResultはコンテナ内でコマンドを実行した結果を表します。 終了コードと標準出力/標準エラー出力の組み合わせを含みます。
type FileAccessResult ¶
type FileAccessResult struct {
// Success indicates whether the file operation completed successfully.
// Successはファイル操作が正常に完了したかどうかを示します。
Success bool `json:"success"`
// Data contains the file content or directory listing if successful.
// Dataは成功した場合のファイル内容またはディレクトリ一覧を含みます。
Data string `json:"data,omitempty"`
// Blocked indicates if the path was blocked by security policy.
// Blockedはパスがセキュリティポリシーによってブロックされたかを示します。
Blocked bool `json:"blocked,omitempty"`
// Block contains details about why the path was blocked.
// Blockはパスがブロックされた理由の詳細を含みます。
Block *security.BlockedPath `json:"block_info,omitempty"`
// Error contains the error message if the operation failed.
// Errorは操作が失敗した場合のエラーメッセージを含みます。
Error string `json:"error,omitempty"`
}
FileAccessResult represents the result of a file access operation (listing or reading files) in a container.
It indicates whether the operation succeeded, was blocked by policy, or failed with an error.
FileAccessResultはコンテナ内でのファイルアクセス操作 (ファイルの一覧表示または読み取り)の結果を表します。
操作が成功したか、ポリシーによってブロックされたか、 エラーで失敗したかを示します。
type MockClient ¶
type MockClient struct {
// ListContainersFunc is called by ListContainers if set.
// ListContainersFuncが設定されている場合、ListContainersから呼び出されます。
ListContainersFunc func(ctx context.Context) ([]ContainerInfo, error)
// GetLogsFunc is called by GetLogs if set.
// GetLogsFuncが設定されている場合、GetLogsから呼び出されます。
GetLogsFunc func(ctx context.Context, containerName string, tail string, since string, follow bool) (string, error)
// GetStatsFunc is called by GetStats if set.
// GetStatsFuncが設定されている場合、GetStatsから呼び出されます。
GetStatsFunc func(ctx context.Context, containerName string) (*container.StatsResponse, error)
// ExecFunc is called by Exec if set.
// ExecFuncが設定されている場合、Execから呼び出されます。
ExecFunc func(ctx context.Context, containerName string, command string, dangerously bool) (*ExecResult, error)
// InspectContainerFunc is called by InspectContainer if set.
// InspectContainerFuncが設定されている場合、InspectContainerから呼び出されます。
InspectContainerFunc func(ctx context.Context, containerName string) (*types.ContainerJSON, error)
// RestartContainerFunc is called by RestartContainer if set.
// RestartContainerFuncが設定されている場合、RestartContainerから呼び出されます。
RestartContainerFunc func(ctx context.Context, containerName string, timeout *int) error
// StopContainerFunc is called by StopContainer if set.
// StopContainerFuncが設定されている場合、StopContainerから呼び出されます。
StopContainerFunc func(ctx context.Context, containerName string, timeout *int) error
// StartContainerFunc is called by StartContainer if set.
// StartContainerFuncが設定されている場合、StartContainerから呼び出されます。
StartContainerFunc func(ctx context.Context, containerName string) error
// ListFilesFunc is called by ListFiles if set.
// ListFilesFuncが設定されている場合、ListFilesから呼び出されます。
ListFilesFunc func(ctx context.Context, containerName string, path string) (*FileAccessResult, error)
// ReadFileFunc is called by ReadFile if set.
// ReadFileFuncが設定されている場合、ReadFileから呼び出されます。
ReadFileFunc func(ctx context.Context, containerName string, path string, maxLines int) (*FileAccessResult, error)
// contains filtered or unexported fields
}
MockClient is a mock implementation of DockerClientInterface for testing. It allows customizing the behavior of each method through function fields. If a function field is not set, the method returns a default value or error.
MockClientはテスト用のDockerClientInterfaceのモック実装です。 各メソッドの動作を関数フィールドを通じてカスタマイズできます。 関数フィールドが設定されていない場合、メソッドはデフォルト値またはエラーを返します。
func NewMockClient ¶
func NewMockClient(policy *security.Policy) *MockClient
NewMockClient creates a new MockClient with the given security policy. The policy is used for GetPolicy and related methods.
NewMockClientは指定されたセキュリティポリシーで新しいMockClientを作成します。 ポリシーはGetPolicyおよび関連メソッドで使用されます。
func (*MockClient) Close ¶
func (m *MockClient) Close() error
Close is a no-op for the mock client. Closeはモッククライアントでは何もしません。
func (*MockClient) Exec ¶
func (m *MockClient) Exec(ctx context.Context, containerName string, command string, dangerously bool) (*ExecResult, error)
Exec returns the result of ExecFunc if set, otherwise returns an error.
ExecはExecFuncが設定されている場合はその結果を返し、 そうでなければエラーを返します。
func (*MockClient) GetAllContainersWithCommands ¶
func (m *MockClient) GetAllContainersWithCommands() map[string][]string
GetAllContainersWithCommands returns all containers and their commands. Delegates to the policy if available.
GetAllContainersWithCommandsはすべてのコンテナとそのコマンドを返します。 利用可能な場合はポリシーに委譲します。
func (*MockClient) GetAllDangerousCommands ¶
func (m *MockClient) GetAllDangerousCommands() map[string][]string
GetAllDangerousCommands returns all containers and their dangerous commands. Delegates to the policy if available.
GetAllDangerousCommandsはすべてのコンテナとその危険コマンドを返します。 利用可能な場合はポリシーに委譲します。
func (*MockClient) GetAllowedCommands ¶
func (m *MockClient) GetAllowedCommands(containerName string) []string
GetAllowedCommands returns the whitelisted commands for a container. Delegates to the policy if available.
GetAllowedCommandsはコンテナのホワイトリストコマンドを返します。 利用可能な場合はポリシーに委譲します。
func (*MockClient) GetBlockedPaths ¶
func (m *MockClient) GetBlockedPaths() []security.BlockedPath
GetBlockedPaths returns all blocked file paths. Delegates to the policy if available.
GetBlockedPathsはすべてのブロックされたファイルパスを返します。 利用可能な場合はポリシーに委譲します。
func (*MockClient) GetBlockedPathsForContainer ¶
func (m *MockClient) GetBlockedPathsForContainer(containerName string) []security.BlockedPath
GetBlockedPathsForContainer returns blocked paths for a specific container. Delegates to the policy if available.
GetBlockedPathsForContainerは特定のコンテナのブロックパスを返します。 利用可能な場合はポリシーに委譲します。
func (*MockClient) GetDangerousCommandsForContainer ¶
func (m *MockClient) GetDangerousCommandsForContainer(containerName string) []string
GetDangerousCommandsForContainer returns dangerous commands for a container. Delegates to the policy if available.
GetDangerousCommandsForContainerはコンテナの危険コマンドを返します。 利用可能な場合はポリシーに委譲します。
func (*MockClient) GetLogs ¶
func (m *MockClient) GetLogs(ctx context.Context, containerName string, tail string, since string, follow bool) (string, error)
GetLogs returns the result of GetLogsFunc if set, otherwise returns an error.
GetLogsはGetLogsFuncが設定されている場合はその結果を返し、 そうでなければエラーを返します。
func (*MockClient) GetPolicy ¶
func (m *MockClient) GetPolicy() *security.Policy
GetPolicy returns the security policy associated with this mock client.
GetPolicyはこのモッククライアントに関連付けられたセキュリティポリシーを返します。
func (*MockClient) GetSecurityPolicy ¶
func (m *MockClient) GetSecurityPolicy() map[string]any
GetSecurityPolicy returns the current security policy configuration. Delegates to the policy if available.
GetSecurityPolicyは現在のセキュリティポリシー設定を返します。 利用可能な場合はポリシーに委譲します。
func (*MockClient) GetStats ¶
func (m *MockClient) GetStats(ctx context.Context, containerName string) (*container.StatsResponse, error)
GetStats returns the result of GetStatsFunc if set, otherwise returns an error.
GetStatsはGetStatsFuncが設定されている場合はその結果を返し、 そうでなければエラーを返します。
func (*MockClient) InspectContainer ¶
func (m *MockClient) InspectContainer(ctx context.Context, containerName string) (*types.ContainerJSON, error)
InspectContainer returns the result of InspectContainerFunc if set, otherwise returns an error.
InspectContainerはInspectContainerFuncが設定されている場合はその結果を返し、 そうでなければエラーを返します。
func (*MockClient) IsDangerousModeEnabled ¶
func (m *MockClient) IsDangerousModeEnabled() bool
IsDangerousModeEnabled returns whether dangerous mode is enabled. Delegates to the policy if available.
IsDangerousModeEnabledは危険モードが有効かどうかを返します。 利用可能な場合はポリシーに委譲します。
func (*MockClient) ListContainers ¶
func (m *MockClient) ListContainers(ctx context.Context) ([]ContainerInfo, error)
ListContainers returns the result of ListContainersFunc if set, otherwise returns an empty slice.
ListContainersはListContainersFuncが設定されている場合はその結果を返し、 そうでなければ空のスライスを返します。
func (*MockClient) ListFiles ¶
func (m *MockClient) ListFiles(ctx context.Context, containerName string, path string) (*FileAccessResult, error)
ListFiles returns the result of ListFilesFunc if set, otherwise returns an error.
ListFilesはListFilesFuncが設定されている場合はその結果を返し、 そうでなければエラーを返します。
func (*MockClient) ReadFile ¶
func (m *MockClient) ReadFile(ctx context.Context, containerName string, path string, maxLines int) (*FileAccessResult, error)
ReadFile returns the result of ReadFileFunc if set, otherwise returns an error.
ReadFileはReadFileFuncが設定されている場合はその結果を返し、 そうでなければエラーを返します。
func (*MockClient) RestartContainer ¶
func (m *MockClient) RestartContainer(ctx context.Context, containerName string, timeout *int) error
RestartContainer returns the result of RestartContainerFunc if set, otherwise returns an error.
func (*MockClient) StartContainer ¶
func (m *MockClient) StartContainer(ctx context.Context, containerName string) error
StartContainer returns the result of StartContainerFunc if set, otherwise returns an error.
func (*MockClient) StopContainer ¶
StopContainer returns the result of StopContainerFunc if set, otherwise returns an error.