audit

package
v0.0.0-...-d5e66a9 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	RequestIDCtxKey contextKey = "request_id"
	TraceIDCtxKey   contextKey = "trace_id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AttestationResult

type AttestationResult struct {
	// Handshake details
	ATLSHandshake     bool          `json:"atls_handshake"`
	HandshakeDuration time.Duration `json:"handshake_duration"`

	// Attestation verification
	AttestationOK    bool   `json:"attestation_ok"`
	AttestationError string `json:"attestation_error,omitempty"`

	// Platform details
	AttestationType  string `json:"attestation_type,omitempty"` // SNP, TDX, Azure, NoCC
	AttestationNonce string `json:"attestation_nonce,omitempty"`

	// Report details (platform-specific)
	Report map[string]any `json:"report,omitempty"`

	// TLS details
	TLSVersion     string `json:"tls_version,omitempty"`
	CipherSuite    string `json:"cipher_suite,omitempty"`
	ServerName     string `json:"server_name,omitempty"`
	PeerCertIssuer string `json:"peer_cert_issuer,omitempty"`
	PeerCertSerial string `json:"peer_cert_serial,omitempty"`
}

AttestationResult holds the results of an aTLS handshake and attestation verification.

type Config

type Config struct {
	EnablePIIMask    bool
	EnableTokens     bool
	SensitiveHeaders []string
	ComplianceMode   bool
	MaxBodyCapture   int
}

type Event

type Event struct {
	// Core identification
	TraceID   string    `json:"trace_id"`
	RequestID string    `json:"request_id"`
	Timestamp time.Time `json:"timestamp"`
	EventType string    `json:"event_type"`

	// Authentication & Authorization
	Session         authn.Session `json:"session,omitzero"`
	AuthMethod      string        `json:"auth_method,omitempty"`
	AttestationType string        `json:"attestation_type,omitempty"`
	AttestationOK   bool          `json:"attestation_ok,omitempty"`

	// Request details
	Method    string            `json:"method"`
	Path      string            `json:"path"`
	Endpoint  string            `json:"endpoint"`
	UserAgent string            `json:"user_agent"`
	ClientIP  string            `json:"client_ip"`
	Headers   map[string]string `json:"headers,omitempty"`

	// Response details
	StatusCode       int           `json:"status_code"`
	ResponseSize     int64         `json:"response_size"`
	RequestSize      int64         `json:"request_size"`
	Duration         time.Duration `json:"duration"`
	DurationMs       float64       `json:"duration_ms"`
	UpstreamDuration time.Duration `json:"upstream_duration,omitempty"`
	UpstreamMs       float64       `json:"upstream_ms,omitempty"`

	// LLM specific
	Model        string  `json:"model,omitempty"`
	InputTokens  int     `json:"input_tokens,omitempty"`
	OutputTokens int     `json:"output_tokens,omitempty"`
	Temperature  float64 `json:"temperature,omitempty"`
	MaxTokens    int     `json:"max_tokens,omitempty"`

	// Security & Compliance
	TLSVersion      string   `json:"tls_version,omitempty"`
	CipherSuite     string   `json:"cipher_suite,omitempty"`
	PeerCertIssuer  string   `json:"peer_cert_issuer,omitempty"`
	ContentFiltered bool     `json:"content_filtered"`
	PIIDetected     bool     `json:"pii_detected"`
	ComplianceTags  []string `json:"compliance_tags,omitempty"`

	// aTLS & Attestation (extends Auth section above)
	ATLSHandshake     bool           `json:"atls_handshake"`
	ATLSHandshakeMs   float64        `json:"atls_handshake_ms,omitempty"`
	AttestationError  string         `json:"attestation_error,omitempty"`
	AttestationNonce  string         `json:"attestation_nonce,omitempty"`
	AttestationReport map[string]any `json:"attestation_report,omitempty"`

	// Error handling
	Error     string `json:"error,omitempty"`
	ErrorCode string `json:"error_code,omitempty"`

	// Additional metadata
	Metadata map[string]any `json:"metadata,omitempty"`
}

Event represents a complete audit log entry.

type InstrumentedTransport

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

InstrumentedTransport wraps an http.RoundTripper to capture aTLS and attestation details.

func NewInstrumentedTransport

func NewInstrumentedTransport(base http.RoundTripper, attestationType string) *InstrumentedTransport

NewInstrumentedTransport creates a new instrumented transport wrapper.

func (*InstrumentedTransport) GetLastResult

func (it *InstrumentedTransport) GetLastResult() *AttestationResult

GetLastResult returns the last attestation result (thread-safe).

func (*InstrumentedTransport) RoundTrip

func (it *InstrumentedTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements http.RoundTripper and captures attestation details.

type Service

type Service interface {
	// Middleware returns the HTTP middleware function for audit logging.
	Middleware(next http.Handler) http.Handler
}

func NewAuditMiddleware

func NewAuditMiddleware(logger *slog.Logger, config Config) Service

NewAuditMiddleware creates a new audit middleware instance.

Jump to

Keyboard shortcuts

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