auditanchor

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Package auditanchor publishes the signed audit chain head to storage the operator controls, so a rewrite of the whole chain on this box is detectable.

Index

Constants

View Source
const (
	EnvDir      = "APP_AUDIT_ANCHOR_DIR"
	EnvURL      = "APP_AUDIT_ANCHOR_URL"
	EnvInterval = "APP_AUDIT_ANCHOR_INTERVAL"
	EnvTimeout  = "APP_AUDIT_ANCHOR_TIMEOUT"

	// FileName is the append-only export inside EnvDir.
	FileName = "audit-anchors.jsonl"
)

Environment variables that turn the anchor on and tune it.

View Source
const (
	EnvQueue      = "APP_AUDIT_ANCHOR_QUEUE"
	EnvAttempts   = "APP_AUDIT_ANCHOR_ATTEMPTS"
	EnvBackoff    = "APP_AUDIT_ANCHOR_BACKOFF"
	EnvBackoffMax = "APP_AUDIT_ANCHOR_BACKOFF_MAX"

	// SignatureHeader carries "sha256=" plus the hex HMAC of the request body.
	SignatureHeader = "X-Levelrail-Signature"
)

Tunables for the webhook exporter; the destination itself is a runtime setting.

Variables

This section is empty.

Functions

func Sign

func Sign(secret string, body []byte) string

Sign returns the header value for body under secret.

Types

type Config

type Config struct {
	Dir      string
	URL      string
	Interval time.Duration
	Timeout  time.Duration
}

Config says where anchors go. Both sinks are optional; with neither set the feature is off.

func ConfigFromEnv

func ConfigFromEnv(lookup func(string) (string, bool)) Config

ConfigFromEnv reads the APP_AUDIT_ANCHOR_* variables; bad durations fall back to the defaults.

func (Config) Enabled

func (c Config) Enabled() bool

Enabled reports whether any sink is configured.

type ExportConfig

type ExportConfig struct {
	Queue      int
	Attempts   int
	Backoff    time.Duration
	BackoffMax time.Duration
	Timeout    time.Duration
}

ExportConfig bounds the queue and the retry schedule.

func ExportConfigFromEnv

func ExportConfigFromEnv(lookup func(string) (string, bool)) ExportConfig

ExportConfigFromEnv reads the APP_AUDIT_ANCHOR_* tunables; bad values fall back to defaults.

type Exporter

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

Exporter sends each new checkpoint to the configured webhook from a bounded queue, so a slow or dead sink never reaches the audit write path.

func NewExporter

func NewExporter(cfg ExportConfig, interval time.Duration, src HeadSource, set Settings, log *slog.Logger) *Exporter

NewExporter builds an Exporter; call Run to start it.

func (*Exporter) Run

func (e *Exporter) Run(ctx context.Context)

Run polls the chain head and drains the queue until ctx ends.

func (*Exporter) Status

func (e *Exporter) Status(ctx context.Context) Status

Status returns a snapshot for the API and CLI.

func (*Exporter) Tick

func (e *Exporter) Tick(ctx context.Context)

Tick queues the head when it moved. With no URL set it makes no request and queues nothing.

type HeadSource

type HeadSource interface {
	LatestAuditAnchor(ctx context.Context) (store.AuditAnchor, bool, error)
}

HeadSource yields the signed chain head; *store.DB satisfies it.

type Publisher

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

Publisher pushes new heads to the configured sinks.

func New

func New(cfg Config, src HeadSource, log *slog.Logger) *Publisher

New builds a Publisher; call Run to start it.

func (*Publisher) Run

func (p *Publisher) Run(ctx context.Context)

Run publishes on every interval until ctx ends. Sink errors are logged and retried next tick; they never reach the audit write path.

func (*Publisher) Tick

func (p *Publisher) Tick(ctx context.Context)

Tick publishes the head once when it moved since the last success.

type Settings

type Settings interface {
	String(ctx context.Context, key string) string
}

Settings reads the live runtime settings; *runtimesettings.Service satisfies it.

type Status

type Status struct {
	Enabled         bool   `json:"enabled"`
	LastExportedSeq int64  `json:"last_exported_seq"`
	LastExportedAt  string `json:"last_exported_at,omitempty"`
	LastError       string `json:"last_error,omitempty"`
	LastErrorAt     string `json:"last_error_at,omitempty"`
	Exported        int64  `json:"exported"`
	Failed          int64  `json:"failed"`
	Dropped         int64  `json:"dropped"`
	Queued          int    `json:"queued"`
}

Status is the operator view of the webhook export. It holds no secret and no URL.

Jump to

Keyboard shortcuts

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