events

package
v0.0.0-...-230ac96 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

internal/db/events/event.go

internal/db/events/redaction.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RuleMetadataFor

func RuleMetadataFor(engine *policy.Engine, ruleName string) (policy.RuleMetadata, bool)

Types

type AuditEmitter

type AuditEmitter interface {
	AppendEvent(ctx context.Context, ev types.Event) error
	Publish(ev types.Event)
}

AuditEmitter is the durable audit event surface used by bypass attempts.

type BypassAttempt

type BypassAttempt struct {
	Engine          *policy.Engine
	SessionID       string
	CommandID       string
	ProcessID       int
	ProcessIdentity string
	RuleName        string
	Reason          string
}

BypassAttempt carries the runtime denial context for a possible DB bypass.

type BypassEmitter

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

func NewBypassEmitter

func NewBypassEmitter(emit AuditEmitter, opts ...BypassEmitterOption) *BypassEmitter

func (*BypassEmitter) EmitIfDBUnavoidabilityDeny

func (b *BypassEmitter) EmitIfDBUnavoidabilityDeny(ctx context.Context, in BypassAttempt) bool

type BypassEmitterOption

type BypassEmitterOption func(*BypassEmitter)

func WithBypassNow

func WithBypassNow(now func() time.Time) BypassEmitterOption

type DBEvent

type DBEvent struct {
	EventID   string    `json:"event_id"`
	SessionID string    `json:"session_id"`
	CommandID string    `json:"command_id,omitempty"`
	Timestamp time.Time `json:"ts"`

	DBService       string `json:"db_service"`
	DBFamily        string `json:"db_family"`
	DBDialect       string `json:"db_dialect"`
	DBUser          string `json:"db_user,omitempty"`
	Database        string `json:"database,omitempty"`
	ApplicationName string `json:"application_name,omitempty"`
	ClientIdentity  string `json:"client_identity,omitempty"`

	Effects []effects.Effect `json:"effects"`

	OperationGroup         string `json:"operation_group,omitempty"`
	OperationGroupID       uint8  `json:"operation_group_id,omitempty"`
	OperationSubtype       string `json:"operation_subtype,omitempty"`
	RawVerb                string `json:"raw_verb,omitempty"`
	ObjectResolution       string `json:"object_resolution,omitempty"`
	ObjectResolutionReason string `json:"object_resolution_reason,omitempty"`

	StatementDigest    string    `json:"statement_digest,omitempty"`
	StatementText      string    `json:"statement_text,omitempty"`
	StatementRedaction Redaction `json:"statement_redaction"`

	Redirected               bool   `json:"redirected,omitempty"`
	RedirectRule             string `json:"redirect_rule,omitempty"`
	RewrittenStatementDigest string `json:"rewritten_statement_digest,omitempty"`
	RedirectSourceRelation   string `json:"redirect_source_relation,omitempty"`
	RedirectTargetRelation   string `json:"redirect_target_relation,omitempty"`
	RedirectRuntimeStatus    string `json:"redirect_runtime_status,omitempty"`
	RedirectRejectionReason  string `json:"redirect_rejection_reason,omitempty"`

	ParserBackend effects.ParserBackend `json:"parser_backend,omitempty"`

	TLS        EventTLS        `json:"tls"`
	Decision   EventDecision   `json:"decision"`
	Result     EventResult     `json:"result"`
	TxContext  EventTxContext  `json:"tx_context"`
	Predicates EventPredicates `json:"predicates,omitempty"`
}

DBEvent is the normalized audit event emitted per database statement, per §8. This is the skeleton; emission lands in Plan 04. Fields here are the v0.8 schema; additional sub-structs (decision, result, tx_context) ship in Plan 04. Cancel governance events also use DBEvent with decision.rule_kind="cancel", operation_group="session", and operation_subtype="cancel_request"; they include mapped database metadata when available and intentionally carry no statement text or digest.

type EventDecision

type EventDecision struct {
	Verb                   string   `json:"verb"`
	RuleKind               string   `json:"rule_kind"`
	RuleName               string   `json:"rule_name,omitempty"`
	MatchingEffectIndex    int      `json:"matching_effect_index"`
	MatchingEffectGroup    string   `json:"matching_effect_group,omitempty"`
	Reason                 string   `json:"reason,omitempty"`
	ContributingAuditRules []string `json:"contributing_audit_rules,omitempty"`
}

EventDecision mirrors spec §8 decision{}. Verb is one of "allow"|"deny"| "approve"|"audit"|"redirect".

type EventPredicates

type EventPredicates struct {
	HasFilter bool `json:"has_filter"`
}

EventPredicates mirrors spec §8 predicates{}.

type EventResult

type EventResult struct {
	RowsReturned *int64 `json:"rows_returned"`
	RowsAffected *int64 `json:"rows_affected"`
	BytesIn      int64  `json:"bytes_in"`
	BytesOut     int64  `json:"bytes_out"`
	LatencyMs    int64  `json:"latency_ms"`
	ErrorCode    string `json:"error_code,omitempty"`
}

EventResult mirrors spec §8 result{}. RowsReturned / RowsAffected are pointers so JSON wire form carries null for "not applicable".

type EventTLS

type EventTLS struct {
	Mode                string `json:"mode"`
	ClientSNI           string `json:"client_sni,omitempty"`
	UpstreamCertSubject string `json:"upstream_cert_subject,omitempty"`
}

EventTLS mirrors spec §8 tls{}. UpstreamCertSubject is unpopulated in 04c.

type EventTxContext

type EventTxContext struct {
	InTransaction bool      `json:"in_transaction"`
	TxStartedAt   time.Time `json:"tx_started_at,omitempty"`
	DenyAction    string    `json:"deny_action"`
}

EventTxContext mirrors spec §8 tx_context{}. DenyAction is one of "none", "connection_terminated", "rollback_injected", "approval_timeout", "approval_denied", or "cancelled_during_approval".

type LifecycleEvent

type LifecycleEvent struct {
	EventID        string    `json:"event_id"`
	SessionID      string    `json:"session_id,omitempty"`
	Timestamp      time.Time `json:"ts"`
	DBService      string    `json:"db_service,omitempty"`
	ClientIdentity string    `json:"client_identity,omitempty"`

	Kind   string `json:"kind"`
	Reason string `json:"reason,omitempty"`

	// Listener-auth specific (Plan 04a). Zero when not applicable.
	PeerUID       uint32 `json:"peer_uid,omitempty"`
	PeerPID       int32  `json:"peer_pid,omitempty"`
	PeerSessionID string `json:"peer_session_id,omitempty"`

	RuleName        string `json:"rule_name,omitempty"`
	BypassMode      string `json:"bypass_mode,omitempty"`
	Destination     string `json:"destination,omitempty"`
	ProcessID       int    `json:"process_id,omitempty"`
	ProcessIdentity string `json:"process_identity,omitempty"`
	SuppressedCount int    `json:"suppressed_count,omitempty"`

	// Handshake/error specific (Plan 04b). Zero when not applicable.
	ErrorCode string `json:"error_code,omitempty"`

	// TLS SNI extracted from the inbound ClientHello. Empty when the client
	// omitted SNI or the connection is not TLS. Spec §13.2 footnote: SNI
	// is advisory; do not gate access decisions on it.
	SNIHostname string `json:"sni_hostname,omitempty"`

	// DegradedReason classifies a degraded_visibility_warning event. Values:
	// "replication_passthrough" (Plan 04b₂), "gssenc_passthrough" (Plan 05).
	// "tls_passthrough" is reserved but never set in 04b₂ — spec §11.1 says
	// no per-connection DVW under tls_mode: passthrough; the value is kept
	// for symmetry with the future GSSENC enum.
	DegradedReason string `json:"degraded_reason,omitempty"`
}

LifecycleEvent is a non-statement DB-proxy event: listener-auth failures, handshake failures (Plan 04b), degraded-visibility warnings (Plan 04b), and cancel side-channel lifecycle outcomes. Carries less data than DBEvent because there is no statement to redact.

Kind is a small enumerated string: "db_listener_auth_fail", "db_handshake_fail", "degraded_visibility_warning", "db_cancel_unmatched", "db_cancel_after_disconnect", "db_cancel_forward_failed", "db_cancel_mapping_fail". Each plan that emits a new kind is responsible for documenting the value in plan release notes.

type NopSink

type NopSink struct{}

NopSink discards every event. Useful when the proxy is wired into a runtime that does not care about audit (tests of unrelated code).

func (NopSink) EmitLifecycle

func (NopSink) EmitLifecycle(context.Context, LifecycleEvent) error

func (NopSink) EmitStatement

func (NopSink) EmitStatement(context.Context, DBEvent) error

type Redaction

type Redaction uint8

Redaction is the statement-text redaction tier per §10.3 (R4: enum form). Default for new events is RedactionParametersRedacted.

const (
	RedactionNone Redaction = iota
	RedactionParametersRedacted
	RedactionFull
)

func ParseRedaction

func ParseRedaction(s string) (Redaction, bool)

func (Redaction) MarshalJSON

func (r Redaction) MarshalJSON() ([]byte, error)

MarshalJSON / UnmarshalJSON: emit/parse the canonical lowercase string form.

func (Redaction) String

func (r Redaction) String() string

func (*Redaction) UnmarshalJSON

func (r *Redaction) UnmarshalJSON(b []byte) error

type Sink

type Sink interface {
	EmitStatement(ctx context.Context, ev DBEvent) error
	EmitLifecycle(ctx context.Context, ev LifecycleEvent) error
}

Sink is the event emission surface for the DB proxy. Implementations may fan out to a real audit pipeline (production), to nothing (tests that do not care about events), or to an in-memory buffer (unit tests asserting emission). Sinks must be safe for concurrent use.

Errors from Emit* are advisory: the proxy logs them at warn but does not fail the connection. Spec §8 is silent on emission durability; Plan 04a adopts best-effort semantics, leaving durability concerns to the audit- pipeline implementation a later plan provides.

type SyncSink

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

SyncSink buffers every emitted event in memory. Tests call DrainStatements or DrainLifecycle to inspect what was emitted. Concurrent use is safe.

Drain* returns the buffered events in emission order and resets the buffer. The returned slice is owned by the caller; subsequent Emit calls do not write into it. Callers must not append to the returned slice.

func (*SyncSink) DrainLifecycle

func (s *SyncSink) DrainLifecycle() []LifecycleEvent

func (*SyncSink) DrainStatements

func (s *SyncSink) DrainStatements() []DBEvent

func (*SyncSink) EmitLifecycle

func (s *SyncSink) EmitLifecycle(ctx context.Context, ev LifecycleEvent) error

func (*SyncSink) EmitStatement

func (s *SyncSink) EmitStatement(ctx context.Context, ev DBEvent) error

Jump to

Keyboard shortcuts

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