activity

package
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: AGPL-3.0 Imports: 19 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

Package activity records who changed what: every changing API call and every sign-in, with its result. The newest entries are kept in memory for the UI; all of them are appended to a JSON-lines file (rotated at MaxFileSize) for auditing and SIEM import. Entries are cryptographically chained with SHA-256 hashes to guarantee tamper evidence.

Index

Constants

View Source
const (
	// Keep is how many entries stay in memory.
	Keep = 1000
	// MaxFileSize rotates the log to <file>.1 (older ones shift up, see OldFiles).
	MaxFileSize = 10 << 20
)
View Source
const GenesisHash = "0000000000000000000000000000000000000000000000000000000000000000"

GenesisHash is the SHA-256 prevHash anchor for the first entry in an audit chain.

View Source
const OldFiles = 5

OldFiles is how many rotated files (<file>.1 newest … <file>.N oldest) are kept.

Variables

This section is empty.

Functions

func ComputeHash added in v0.9.0

func ComputeHash(e Entry) string

ComputeHash computes the canonical SHA-256 hash for an activity entry.

func FormatRFC5424 added in v0.7.1

func FormatRFC5424(e Entry, cfg SIEMConfig) string

FormatRFC5424 formats an audit entry into a standard RFC 5424 syslog frame.

func SaveSIEMConfig added in v0.7.2

func SaveSIEMConfig(path string, cfg SIEMConfig) error

SaveSIEMConfig writes the settings so forwarding survives a restart.

Types

type Entry

type Entry struct {
	Seq      int64     `json:"seq,omitempty"`
	PrevHash string    `json:"prevHash,omitempty"`
	Hash     string    `json:"hash,omitempty"`
	Time     time.Time `json:"time"`
	User     string    `json:"user"`
	Token    string    `json:"token,omitempty"` // API token name, if one was used
	Remote   string    `json:"remote,omitempty"`
	Method   string    `json:"method"`
	Path     string    `json:"path"`
	Status   int       `json:"status"`
	Error    string    `json:"error,omitempty"`
}

func (Entry) OK

func (e Entry) OK() bool

OK reports whether the request succeeded.

type Filter

type Filter struct {
	User   string
	Target string // substring of the path, e.g. a machine UUID
	Failed bool   // only failed requests
}

Filter narrows List. Zero values match everything.

type Forwarder added in v0.7.1

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

Forwarder streams audit logs to a remote syslog / SIEM receiver.

func NewForwarder added in v0.7.1

func NewForwarder(cfg SIEMConfig) *Forwarder

NewForwarder initializes a background SIEM forwarder.

func (*Forwarder) Close added in v0.7.1

func (f *Forwarder) Close()

Close terminates the background forwarder worker.

func (*Forwarder) Config added in v0.7.1

func (f *Forwarder) Config() SIEMConfig

Config returns a copy of current SIEM configuration.

func (*Forwarder) Send added in v0.7.1

func (f *Forwarder) Send(e Entry)

Send queues an entry for remote SIEM forwarding without blocking.

func (*Forwarder) SetConfig added in v0.7.1

func (f *Forwarder) SetConfig(cfg SIEMConfig)

SetConfig updates the SIEM forwarding configuration.

type Log

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

func Open

func Open(path string) (*Log, error)

Open loads the newest entries of path. A missing file is fine. It scans the existing file (and rotated path+".1" if present) to discover the last valid Hash and Seq on disk, resuming the chain seamlessly across restarts.

func (*Log) Add

func (l *Log) Add(e Entry) error

Add records an entry (and appends it to the file; write errors are returned but the entry is kept in memory either way). Each entry receives a strictly increasing Seq, PrevHash pointing to the previous entry (or GenesisHash), and a cryptographic Hash.

func (*Log) AttachSIEM added in v0.7.1

func (l *Log) AttachSIEM(f *Forwarder)

AttachSIEM connects an asynchronous RFC 5424 forwarder to the activity log.

func (*Log) Export added in v0.9.0

func (l *Log) Export(w io.Writer, format string) error

Export streams all disk entries in either "jsonl" or "csv" format with full Seq, PrevHash, Hash fields, and header comments/metadata indicating chain status.

func (*Log) List

func (l *Log) List(limit int, f Filter) []Entry

List returns up to limit entries, newest first.

func (*Log) SIEM added in v0.7.1

func (l *Log) SIEM() *Forwarder

SIEM returns the current forwarder, if any.

func (*Log) Verify added in v0.9.0

func (l *Log) Verify() (VerificationResult, error)

Verify opens the log file(s) from disk and verifies the full cryptographic chain.

type SIEMConfig added in v0.7.1

type SIEMConfig struct {
	Enabled     bool   `json:"enabled"`
	Target      string `json:"target"`      // e.g. "udp://siem.example.com:514", "tcp://...", "tls://..."
	Facility    int    `json:"facility"`    // 1 = user-level, 16 = local0
	Tag         string `json:"tag"`         // e.g. "virtomir"
	Hostname    string `json:"hostname"`    // host name or empty for os.Hostname
	TLSInsecure bool   `json:"tlsInsecure"` // skip cert verification if self-signed
	// LastError is the outcome of the latest delivery ("" when it worked); set on reads only.
	LastError string `json:"lastError,omitempty"`
}

SIEMConfig configures remote syslog / SIEM log forwarding.

func LoadSIEMConfig added in v0.7.2

func LoadSIEMConfig(path string) (cfg SIEMConfig, ok bool, err error)

LoadSIEMConfig reads the saved forwarding settings; ok is false when none were saved.

func (SIEMConfig) Validate added in v0.7.2

func (c SIEMConfig) Validate() error

Validate checks the target is udp://, tcp:// or tls:// with a host and port.

type VerificationResult added in v0.9.0

type VerificationResult struct {
	Valid         bool   `json:"valid"`
	VerifiedCount int    `json:"verifiedCount"`
	FirstSeq      int64  `json:"firstSeq,omitempty"`
	LastSeq       int64  `json:"lastSeq,omitempty"`
	HeadHash      string `json:"headHash,omitempty"`
	TamperedSeq   int64  `json:"tamperedSeq,omitempty"`
	TamperedIndex int    `json:"tamperedIndex,omitempty"`
	Reason        string `json:"reason,omitempty"`
}

VerificationResult describes the outcome of verifying an audit log's cryptographic chain.

Jump to

Keyboard shortcuts

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