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 ¶
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 )
const GenesisHash = "0000000000000000000000000000000000000000000000000000000000000000"
GenesisHash is the SHA-256 prevHash anchor for the first entry in an audit chain.
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
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"`
}
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
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 ¶
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 ¶
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
AttachSIEM connects an asynchronous RFC 5424 forwarder to the activity log.
func (*Log) Export ¶ added in v0.9.0
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) 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.