Documentation
¶
Overview ¶
SPDX-License-Identifier: MPL-2.0
SPDX-License-Identifier: MPL-2.0 Package audit owns retained accountability records. Domains choose accountable actions; operational logs and repeated public denials are not Audit events.
SPDX-License-Identifier: MPL-2.0
SPDX-License-Identifier: MPL-2.0
SPDX-License-Identifier: MPL-2.0
Index ¶
- Constants
- Variables
- func AppendInTx(parent context.Context, tx pgx.Tx, prepared Prepared) error
- func Migrate(ctx context.Context, dsn string) error
- func MigrateWithDiagnostics(ctx context.Context, dsn string, logger *slog.Logger, ...) error
- func Version() string
- func WithAttribution(ctx context.Context, actor achrix.Principal, value Attribution) (context.Context, error)
- type Attribution
- type Config
- type Event
- type InputError
- type Module
- type Page
- type Prepared
- type Record
- type Service
- func (s *Service) Append(parent context.Context, actor achrix.Principal, event Event) (Record, error)
- func (s *Service) CheckDatabase(dsn string) error
- func (s *Service) Export(ctx context.Context, actor achrix.Principal, target, cursor string, limit int) (Page, error)
- func (s *Service) Prepare(ctx context.Context, actor achrix.Principal, event Event) (Prepared, error)
- func (s *Service) Query(ctx context.Context, actor achrix.Principal, target, cursor string, limit int) (Page, error)
Constants ¶
const ( Append = "achrix.audit.append" Query = "achrix.audit.query" Export = "achrix.audit.export" )
const ModuleVersion = "0.2.0-development"
ModuleVersion is the unpublished source-line label, not the packaged build version. Deprecated: use Module.Descriptor().Version for component/update/recovery identity.
Variables ¶
Functions ¶
func AppendInTx ¶
AppendInTx owns Audit SQL while the caller owns the native PostgreSQL transaction and commit. The domain must roll back if this call fails. A successful return alone does not prove either write has committed.
func Migrate ¶
Migrate explicitly installs or advances an exact immutable ledger prefix under one transactional advisory lock. Startup never changes schema. Source rollback does not downgrade retained records or the migration ledger. Existing callers use the default logger. Products needing protected original causes should call MigrateWithDiagnostics with their configured sink.
func MigrateWithDiagnostics ¶ added in v0.2.0
func MigrateWithDiagnostics(ctx context.Context, dsn string, logger *slog.Logger, diagnostic func(context.Context, string, string, error)) error
MigrateWithDiagnostics adds product-owned diagnostics without changing the public error chain or immutable migration. The hook receives original causes; it must apply provider-aware redaction before protected retention/export.
func Version ¶
func Version() string
Version identifies this Module's actual packaged source dependency. Local and replacement builds report explicit development categories.
func WithAttribution ¶ added in v0.3.0
func WithAttribution(ctx context.Context, actor achrix.Principal, value Attribution) (context.Context, error)
WithAttribution validates and copies verifier-bound attribution for one actor. Trusted entry-point composition supplies this value after authentication; it must never be decoded from public operation arguments or identity headers. It grants no access and preserves the original cancellation/deadline. Prepare checks the actor binding and captures its own immutable value snapshot. Existing direct calls need not attach attribution; absence stays explicit.
Types ¶
type Attribution ¶ added in v0.3.0
type Attribution struct {
ClientID string
ConnectionID string
Channel string
RequestID string
Operation string
}
Attribution is trusted product-bound request provenance, not authorization. Actor remains Record.Actor. Client and connection IDs are non-secret opaque identifiers, never access tokens, credentials, headers or arbitrary payloads. A missing connection ID is permitted; every other field is required.
type Config ¶
type Config struct {
// Diagnostic receives the original cause only at this component's protected
// owner boundary. The product must redact provider secrets before retention
// or export, keep access restricted, and return promptly. It must not log
// the raw error to ordinary output. The original request context is retained.
// It sees every operational cause before ordinary-log suppression; the
// product owns its diagnostic sink's volume policy.
Diagnostic func(context.Context, string, string, error)
// MaxConns bounds this instance's pool. Zero uses four; negatives are invalid.
MaxConns int32
// MaxOperations bounds active owned leases, including nested AppendInTx work.
// Zero uses 16; explicit values must be at least two.
MaxOperations int
Now func() time.Time
}
Config.Now is a trusted, concurrent-safe product time source. Records store UTC microsecond instants; it conveys no trusted timestamp or clock attestation.
type Event ¶
type Event struct{ Action, Target, Authority, Outcome string }
Event deliberately has no caller-selected actor, time, ID or arbitrary payload. Authority identifies the owning domain capability, not an authorization grant.
type InputError ¶ added in v0.2.0
type InputError struct{ Field, Reason string }
InputError identifies a malformed field without echoing caller values.
func (*InputError) Error ¶ added in v0.2.0
func (e *InputError) Error() string
func (*InputError) Unwrap ¶ added in v0.2.0
func (e *InputError) Unwrap() error
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module owns only Audit storage, pool, admission and lifecycle. Identity's declared dependency orders its shutdown drain before this Module is stopped.
func NewPostgres ¶
func (*Module) Descriptor ¶
func (m *Module) Descriptor() achrix.Descriptor
func (*Module) FailureCount ¶
FailureCount counts bounded operational failures, not durable accountability.
type Prepared ¶
type Prepared struct {
// contains filtered or unexported fields
}
Prepared is opaque, single-use and bound to the original live operation and Audit Module. It cannot extend a deadline or be retained as an access grant.
type Record ¶
type Record struct {
ID string
Actor achrix.Principal
Action string
Target string
Authority string
Outcome string
OccurredAt time.Time
// Nil means no request provenance was retained; historical/direct records
// must not acquire a guessed channel, client or request identity.
Attribution *Attribution
}
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
func NewService ¶
func NewService(app *achrix.Application, module *Module) (*Service, error)
func (*Service) Append ¶
func (s *Service) Append(parent context.Context, actor achrix.Principal, event Event) (Record, error)
Append commits an authorized standalone record. Atomic domain actions instead use Prepare/AppendInTx within their owning transaction.
func (*Service) CheckDatabase ¶
CheckDatabase prevents a same-transaction consumer from silently composing different database profiles. Equivalent parsed connection settings match; passwords, TLS trust and fallback settings are compared without being exposed.