audit

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: Apache-2.0 Imports: 7 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 audit appends rows to the audit_log table. Write runs inside the transaction of the change it records, so a change and its audit trail commit or roll back together.

Index

Constants

View Source
const (
	KindUser    = "user"
	KindConsole = "console"
	KindSystem  = "system"
	KindApp     = "app"
)

Actor kinds.

View Source
const (
	ActionSetup             = "setup.complete"
	ActionLoginSuccess      = "auth.login"
	ActionLoginFailure      = "auth.login_failed"
	ActionLogout            = "auth.logout"
	ActionPasswordChange    = "auth.password_change"
	ActionPasswordReset     = "auth.password_reset"
	ActionResetCreate       = "auth.reset_create"
	ActionInviteCreate      = "invite.create"
	ActionInviteAccept      = "invite.accept"
	ActionInviteRevoke      = "invite.revoke"
	ActionRegister          = "user.register"
	ActionSessionRevoke     = "session.revoke"
	ActionDeviceLogin       = "device.login"
	ActionDeviceRevoke      = "device.revoke"
	ActionHandoff           = "auth.handoff"
	ActionSettingsUpdated   = "settings.update"
	ActionUserCreate        = "user.create"
	ActionRegistrationOpen  = "registration.open"
	ActionRegistrationClose = "registration.close"
)

Actions recorded by the auth and settings code. Detail never carries passwords, tokens, invite or reset codes.

View Source
const (
	ActionUserUpdate   = "user.update"
	ActionTLSReissue   = "tls.reissue"
	ActionChannelAdmin = "channel.admin_update"
)

Further actions recorded by the admin endpoints.

View Source
const (
	DefaultListLimit = 50
	MaxListLimit     = 200
)

List limits.

Variables

View Source
var Console = Actor{Kind: KindConsole}

Console is the actor of the admin CLI (console access is the root of trust).

View Source
var ErrBadCursor = errors.New("audit: invalid cursor")

ErrBadCursor means a list cursor was not produced by List.

View Source
var System = Actor{Kind: KindSystem}

System is the actor of background work.

Functions

func HasRemoteActor

func HasRemoteActor(ctx context.Context, db *store.DB, actions ...string) (bool, error)

HasRemoteActor reports whether any row of the given actions was performed from an address other than loopback (the client-isolation hint of the admin overview).

func SetupTime

func SetupTime(ctx context.Context, db *store.DB) (at int64, ok bool, err error)

SetupTime returns when first-run setup completed (unix milliseconds); ok is false while no setup row exists.

func Write

func Write(tx *store.Tx, e Entry) (string, error)

Write inserts e into audit_log inside tx and returns the new row id.

Types

type Actor

type Actor struct {
	// ID is the user id; empty for the console and the system.
	ID string
	// Kind is one of the Kind* constants.
	Kind string
	// IP is the client address; empty when there is none.
	IP string
}

Actor identifies who performs an action.

func User

func User(id, ip string) Actor

User returns the actor for an authenticated user at ip.

func (Actor) Entry

func (a Actor) Entry(action, targetType, targetID string, detail any) Entry

Entry builds an Entry performed by a.

type Entry

type Entry struct {
	ActorID    string
	ActorKind  string
	ActorIP    string
	Action     string
	TargetType string
	TargetID   string
	// Detail is marshaled to JSON; nil stores {}.
	Detail any
}

Entry is one audit_log row.

type ListParams

type ListParams struct {
	// Cursor is the NextCursor of the previous page; empty starts at the newest row.
	Cursor string
	// Action keeps only rows with exactly this action.
	Action string
	// Limit is the page size; 0 means DefaultListLimit.
	Limit int
}

ListParams selects a page of the log, newest first.

type Record

type Record struct {
	ID         string
	At         int64 // unix ms
	ActorID    string
	ActorKind  string
	ActorIP    string
	Action     string
	TargetType string
	TargetID   string
	Detail     json.RawMessage
}

Record is one audit_log row as read back.

func List

func List(ctx context.Context, db *store.DB, p ListParams) ([]Record, string, error)

List returns one page of audit rows, newest first, and the cursor of the next page (empty at the end). A malformed cursor is ErrBadCursor.

Jump to

Keyboard shortcuts

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