audit

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package audit provides audit logging for HostMCP. It records security-relevant events for monitoring and compliance.

auditパッケージはHostMCPの監査ログを提供します。 セキュリティ関連イベントを監視とコンプライアンスのために記録します。

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Initialize

func Initialize(cfg config.AuditConfig) error

Initialize sets up the global audit logger. Idempotent: subsequent calls are no-ops and return nil.

InitializeはグローバルAuditロガーを設定します。 冪等: 2回目以降の呼び出しは何もせずnilを返します。

func LogAccessDenied

func LogAccessDenied(ctx context.Context, tool, container, reason string, details map[string]any)

LogAccessDenied logs an access denial. LogAccessDeniedはアクセス拒否をログ記録します。

func LogClientConnect

func LogClientConnect(ctx context.Context, clientName, sessionID string)

LogClientConnect logs a client connection. LogClientConnectはクライアント接続をログ記録します。

func LogClientDisconnect

func LogClientDisconnect(ctx context.Context, clientName, sessionID string, durationMs int64)

LogClientDisconnect logs a client disconnection. LogClientDisconnectはクライアント切断をログ記録します。

func LogSecurityPolicy

func LogSecurityPolicy(ctx context.Context, tool string, details map[string]any)

LogSecurityPolicy logs a security policy query. LogSecurityPolicyはセキュリティポリシー照会をログ記録します。

func LogToolCall

func LogToolCall(ctx context.Context, tool, container string, result Result, durationMs int64, details map[string]any)

LogToolCall logs a tool invocation. LogToolCallはツール呼び出しをログ記録します。

func MeasureDuration

func MeasureDuration(start time.Time) int64

MeasureDuration is a helper to measure operation duration. MeasureDurationは操作の所要時間を計測するヘルパーです。

func ResetLogger

func ResetLogger()

ResetLogger resets the global audit logger (for testing). ResetLoggerはグローバルAuditロガーをリセットします(テスト用)。

func SetLogger

func SetLogger(l *Logger)

SetLogger sets the global audit logger (for testing). It closes any existing logger and updates the initialized flag accordingly.

SetLoggerはグローバルAuditロガーを設定します(テスト用)。 既存ロガーをクローズし、initializedフラグも合わせて更新します。

Types

type Event

type Event struct {
	// Type is the type of audit event.
	// Typeは監査イベントのタイプです。
	Type EventType

	// Tool is the name of the MCP tool (for tool_call events).
	// ToolはMCPツールの名前です(tool_callイベント用)。
	Tool string

	// Container is the target container name.
	// Containerは対象コンテナ名です。
	Container string

	// Result is the outcome of the operation.
	// Resultは操作の結果です。
	Result Result

	// ClientName is the name of the MCP client.
	// ClientNameはMCPクライアントの名前です。
	ClientName string

	// SessionID is the unique session identifier.
	// SessionIDはユニークなセッション識別子です。
	SessionID string

	// Details contains additional event-specific information.
	// Detailsは追加のイベント固有情報を含みます。
	Details map[string]any

	// DurationMs is the operation duration in milliseconds.
	// DurationMsは操作の所要時間(ミリ秒)です。
	DurationMs int64

	// ErrorMessage contains the error message if Result is error/denied.
	// ErrorMessageはResultがerror/deniedの場合のエラーメッセージです。
	ErrorMessage string
}

Event represents an audit event. Eventは監査イベントを表します。

type EventType

type EventType string

EventType represents the type of audit event. EventTypeは監査イベントのタイプを表します。

const (
	// EventToolCall is logged when an MCP tool is invoked.
	// EventToolCallはMCPツールが呼び出された時にログ記録されます。
	EventToolCall EventType = "tool_call"

	// EventAccessDenied is logged when access is denied.
	// EventAccessDeniedはアクセスが拒否された時にログ記録されます。
	EventAccessDenied EventType = "access_denied"

	// EventClientConnect is logged when a client connects.
	// EventClientConnectはクライアントが接続した時にログ記録されます。
	EventClientConnect EventType = "client_connect"

	// EventClientDisconnect is logged when a client disconnects.
	// EventClientDisconnectはクライアントが切断した時にログ記録されます。
	EventClientDisconnect EventType = "client_disconnect"

	// EventSecurityPolicy is logged when security policy is queried.
	// EventSecurityPolicyはセキュリティポリシーが照会された時にログ記録されます。
	EventSecurityPolicy EventType = "security_policy"
)

type Logger

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

Logger is the audit logger. Loggerは監査ロガーです。

func GetLogger

func GetLogger() *Logger

GetLogger returns the global audit logger for testing. GetLoggerはテスト用にグローバルAuditロガーを返します。

func (*Logger) Close

func (l *Logger) Close() error

Close closes the audit logger. Safe to call multiple times. Closeは監査ロガーをクローズします。複数回呼び出し可能です。

func (*Logger) FilePath added in v0.4.0

func (l *Logger) FilePath() string

FilePath returns the resolved (expanded) path of the audit log file.

FilePathは監査ログファイルの展開済みパスを返します。

func (*Logger) Log

func (l *Logger) Log(ctx context.Context, event Event)

Log records an audit event. Logは監査イベントを記録します。

type Result

type Result string

Result represents the outcome of an operation. Resultは操作の結果を表します。

const (
	ResultSuccess Result = "success"
	ResultDenied  Result = "denied"
	ResultError   Result = "error"
)

Jump to

Keyboard shortcuts

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