Documentation
¶
Overview ¶
Package audithook bridges Shield lifecycle events to an audit trail backend.
It defines a local Recorder interface so the package does not import Chronicle directly. Callers inject a RecorderFunc adapter that bridges to Chronicle at wiring time.
Index ¶
- Constants
- type AuditEvent
- type Extension
- func (e *Extension) Name() string
- func (e *Extension) OnAwarenessDetected(ctx context.Context, scanID id.ScanID, detectorName string, findingCount int) error
- func (e *Extension) OnBoundaryEnforced(ctx context.Context, scanID id.ScanID, boundaryName string) error
- func (e *Extension) OnInstinctTriggered(ctx context.Context, scanID id.ScanID, instinctName string, score float64) error
- func (e *Extension) OnJudgmentAssessed(ctx context.Context, scanID id.ScanID, assessorName, riskLevel string, ...) error
- func (e *Extension) OnPIIDetected(ctx context.Context, scanID id.ScanID, piiType string, count int) error
- func (e *Extension) OnPIIRedacted(ctx context.Context, scanID id.ScanID, piiType string, count int) error
- func (e *Extension) OnPolicyEvaluated(ctx context.Context, scanID id.ScanID, policyName, decision string) error
- func (e *Extension) OnReflexFired(ctx context.Context, scanID id.ScanID, reflexName, action string) error
- func (e *Extension) OnSafetyProfileResolved(ctx context.Context, scanID id.ScanID, profileName string) error
- func (e *Extension) OnScanBlocked(ctx context.Context, scanID id.ScanID, reason string) error
- func (e *Extension) OnScanCompleted(ctx context.Context, scanID id.ScanID, decision string, findingCount int, ...) error
- func (e *Extension) OnScanFailed(ctx context.Context, scanID id.ScanID, scanErr error) error
- func (e *Extension) OnScanStarted(ctx context.Context, scanID id.ScanID, direction, _ string) error
- func (e *Extension) OnValueViolated(ctx context.Context, scanID id.ScanID, valueName, severity string) error
- type Option
- type Recorder
- type RecorderFunc
Constants ¶
const ( SeverityInfo = "info" SeverityWarning = "warning" SeverityCritical = "critical" )
Severity levels for audit events.
const ( OutcomeSuccess = "success" OutcomeFailure = "failure" )
Outcome values for audit events.
const ( ActionScanStarted = "shield.scan.started" ActionScanCompleted = "shield.scan.completed" ActionScanBlocked = "shield.scan.blocked" ActionScanFailed = "shield.scan.failed" ActionInstinctTriggered = "shield.instinct.triggered" ActionAwarenessDetected = "shield.awareness.detected" ActionJudgmentAssessed = "shield.judgment.assessed" ActionValueViolated = "shield.value.violated" ActionReflexFired = "shield.reflex.fired" ActionBoundaryEnforced = "shield.boundary.enforced" ActionPIIDetected = "shield.pii.detected" ActionPIIRedacted = "shield.pii.redacted" ActionPolicyCreated = "shield.policy.created" ActionPolicyAssigned = "shield.policy.assigned" ActionComplianceReport = "shield.compliance.generated" ActionProfileResolved = "shield.profile.resolved" )
Action constants for Shield audit events.
const ( ResourceScan = "scan" ResourceInstinct = "instinct" ResourceAwareness = "awareness" ResourceJudgment = "judgment" ResourceValue = "value" ResourceReflex = "reflex" ResourceBoundary = "boundary" ResourcePII = "pii" ResourcePolicy = "policy" ResourceCompliance = "compliance" ResourceProfile = "profile" )
Resource constants for audit events.
const ( CategorySafety = "safety" CategoryPrivacy = "privacy" CategoryCompliance = "compliance" CategoryGovernance = "governance" )
Category constants for audit events.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AuditEvent ¶
type AuditEvent struct {
Action string `json:"action"`
Resource string `json:"resource"`
Category string `json:"category"`
ResourceID string `json:"resource_id,omitempty"`
Metadata map[string]any `json:"metadata,omitempty"`
Outcome string `json:"outcome"`
Severity string `json:"severity"`
Reason string `json:"reason,omitempty"`
}
AuditEvent is a local representation of an audit event. It mirrors chronicle/audit.Event but avoids a module dependency.
type Extension ¶
type Extension struct {
// contains filtered or unexported fields
}
Extension bridges Shield lifecycle events to an audit trail backend.
func (*Extension) OnAwarenessDetected ¶
func (e *Extension) OnAwarenessDetected(ctx context.Context, scanID id.ScanID, detectorName string, findingCount int) error
OnAwarenessDetected implements plugin.AwarenessDetected.
func (*Extension) OnBoundaryEnforced ¶
func (e *Extension) OnBoundaryEnforced(ctx context.Context, scanID id.ScanID, boundaryName string) error
OnBoundaryEnforced implements plugin.BoundaryEnforced.
func (*Extension) OnInstinctTriggered ¶
func (e *Extension) OnInstinctTriggered(ctx context.Context, scanID id.ScanID, instinctName string, score float64) error
OnInstinctTriggered implements plugin.InstinctTriggered.
func (*Extension) OnJudgmentAssessed ¶
func (e *Extension) OnJudgmentAssessed(ctx context.Context, scanID id.ScanID, assessorName, riskLevel string, confidence float64) error
OnJudgmentAssessed implements plugin.JudgmentAssessed.
func (*Extension) OnPIIDetected ¶
func (e *Extension) OnPIIDetected(ctx context.Context, scanID id.ScanID, piiType string, count int) error
OnPIIDetected implements plugin.PIIDetected.
func (*Extension) OnPIIRedacted ¶
func (e *Extension) OnPIIRedacted(ctx context.Context, scanID id.ScanID, piiType string, count int) error
OnPIIRedacted implements plugin.PIIRedacted.
func (*Extension) OnPolicyEvaluated ¶
func (e *Extension) OnPolicyEvaluated(ctx context.Context, scanID id.ScanID, policyName, decision string) error
OnPolicyEvaluated implements plugin.PolicyEvaluated.
func (*Extension) OnReflexFired ¶
func (e *Extension) OnReflexFired(ctx context.Context, scanID id.ScanID, reflexName, action string) error
OnReflexFired implements plugin.ReflexFired.
func (*Extension) OnSafetyProfileResolved ¶
func (e *Extension) OnSafetyProfileResolved(ctx context.Context, scanID id.ScanID, profileName string) error
OnSafetyProfileResolved implements plugin.SafetyProfileResolved.
func (*Extension) OnScanBlocked ¶
OnScanBlocked implements plugin.ScanBlocked.
func (*Extension) OnScanCompleted ¶
func (e *Extension) OnScanCompleted(ctx context.Context, scanID id.ScanID, decision string, findingCount int, elapsed time.Duration) error
OnScanCompleted implements plugin.ScanCompleted.
func (*Extension) OnScanFailed ¶
OnScanFailed implements plugin.ScanFailed.
func (*Extension) OnScanStarted ¶
OnScanStarted implements plugin.ScanStarted.
type Option ¶
type Option func(*Extension)
Option configures an audit hook Extension.
func WithActions ¶
WithActions limits audit emission to the specified actions only. By default all actions are enabled.
func WithLogger ¶
WithLogger sets a custom logger for the audit extension.
type Recorder ¶
type Recorder interface {
Record(ctx context.Context, event *AuditEvent) error
}
Recorder is the interface that audit backends must implement. This matches chronicle.Emitter but is defined locally so that the audit_hook package does not import Chronicle directly. Callers inject the concrete *chronicle.Chronicle at wiring time.
type RecorderFunc ¶
type RecorderFunc func(ctx context.Context, event *AuditEvent) error
RecorderFunc is an adapter to use a plain function as a Recorder.
func (RecorderFunc) Record ¶
func (f RecorderFunc) Record(ctx context.Context, event *AuditEvent) error
Record implements Recorder.