Documentation
¶
Overview ¶
Package audit provides audit logging for HostMCP. It records security-relevant events for monitoring and compliance.
auditパッケージはHostMCPの監査ログを提供します。 セキュリティ関連イベントを監視とコンプライアンスのために記録します。
Index ¶
- func Initialize(cfg config.AuditConfig) error
- func LogAccessDenied(ctx context.Context, tool, container, reason string, details map[string]any)
- func LogClientConnect(ctx context.Context, clientName, sessionID string)
- func LogClientDisconnect(ctx context.Context, clientName, sessionID string, durationMs int64)
- func LogSecurityPolicy(ctx context.Context, tool string, details map[string]any)
- func LogToolCall(ctx context.Context, tool, container string, result Result, durationMs int64, ...)
- func MeasureDuration(start time.Time) int64
- func ResetLogger()
- func SetLogger(l *Logger)
- type Event
- type EventType
- type Logger
- type Result
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 ¶
LogAccessDenied logs an access denial. LogAccessDeniedはアクセス拒否をログ記録します。
func LogClientConnect ¶
LogClientConnect logs a client connection. LogClientConnectはクライアント接続をログ記録します。
func LogClientDisconnect ¶
LogClientDisconnect logs a client disconnection. LogClientDisconnectはクライアント切断をログ記録します。
func LogSecurityPolicy ¶
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 ¶
MeasureDuration is a helper to measure operation duration. MeasureDurationは操作の所要時間を計測するヘルパーです。
func ResetLogger ¶
func ResetLogger()
ResetLogger resets the global audit logger (for testing). ResetLoggerはグローバルAuditロガーをリセットします(テスト用)。
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 ¶
Close closes the audit logger. Safe to call multiple times. Closeは監査ロガーをクローズします。複数回呼び出し可能です。