audit

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action string

Action identifies the type of audit event.

const (
	ActionAppCreate         Action = "app.create"
	ActionAppUpdate         Action = "app.update"
	ActionAppDelete         Action = "app.delete"
	ActionAppStart          Action = "app.start"
	ActionAppStop           Action = "app.stop"
	ActionBundleUpload      Action = "bundle.upload"
	ActionBundleRestoreOK   Action = "bundle.restore.success"
	ActionBundleRestoreFail Action = "bundle.restore.fail"
	ActionAppRollback       Action = "app.rollback"
	ActionAppRestore        Action = "app.restore"
	ActionAccessGrant       Action = "access.grant"
	ActionAccessRevoke      Action = "access.revoke"
	ActionCredentialEnroll  Action = "credential.enroll" //nolint:gosec // G101: audit action name, not a credential
	ActionUserLogin         Action = "user.login"
	ActionUserLogout        Action = "user.logout"
	ActionUserUpdate        Action = "user.update"
	ActionTokenCreate       Action = "token.create"
	ActionTokenRevoke       Action = "token.revoke"
	ActionTokenRevokeAll    Action = "token.revoke_all"
	ActionAppRename         Action = "app.rename"
)

type Entry

type Entry struct {
	Timestamp string         `json:"ts"`
	Action    Action         `json:"action"`
	Actor     string         `json:"actor"`
	Target    string         `json:"target,omitempty"`
	Detail    map[string]any `json:"detail,omitempty"`
	SourceIP  string         `json:"source_ip,omitempty"`
}

Entry is a single audit log record.

type Log

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

Log is an append-only audit log backed by a JSON Lines file. Writes are buffered via a channel and flushed by a background goroutine.

func New

func New(path string, metrics *telemetry.Metrics) *Log

New creates an audit log. The background writer must be started with Run(). If path is empty, returns nil. metrics may be nil in tests that do not care about observability; production callers should always pass the server's telemetry.Metrics instance.

func (*Log) Emit

func (l *Log) Emit(entry Entry)

Emit sends an entry to the background writer. Non-blocking — if the buffer is full, the entry is dropped and a warning is logged.

func (*Log) Run

func (l *Log) Run(ctx context.Context, path string)

Run is the background goroutine that appends entries to the log file. Blocks until ctx is cancelled. Drains remaining entries before exit.

Jump to

Keyboard shortcuts

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