audit

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: AGPL-3.0 Imports: 15 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 is the writer of the Audit log (C-03.FR-14): it appends an entry to audit_log with the actor, the token used, the Transport, a stable action `<resource>.<verb>`, the resource, a before/after diff and details, and copies every entry to stdout as the log event audit_entry. The table is append-only; this package only inserts.

Index

Constants

View Source
const (
	ActionUserCreated     = "user.created"
	ActionSignedIn        = "session.signed_in"
	ActionSignInFailed    = "session.sign_in_failed"
	ActionSignedOut       = "session.signed_out"
	ActionSessionsEnded   = "session.ended_all"
	ActionProfileUpdated  = "user.profile_updated"
	ActionPasswordChanged = "user.password_changed"

	ActionUserUpdated       = "user.updated"
	ActionUserRoleChanged   = "user.role_changed"
	ActionUserDisabled      = "user.disabled"
	ActionUserEnabled       = "user.enabled"
	ActionUserDeleted       = "user.deleted"
	ActionPasswordSetupLink = "user.password_setup_link_created"
	ActionPasswordSet       = "user.password_set"
	ActionPasswordReset     = "user.password_reset"
)

The actions of C-03; each capability adds its own.

View Source
const (
	ActionAPITokenCreated        = "api_token.created"
	ActionAPITokenRevoked        = "api_token.revoked"
	ActionServiceAccountCreated  = "service_account.created"
	ActionServiceAccountUpdated  = "service_account.updated"
	ActionServiceAccountDisabled = "service_account.disabled"
	ActionServiceAccountEnabled  = "service_account.enabled"
	ActionServiceAccountDeleted  = "service_account.deleted"
	ResourceAPIToken             = "api_token"
	ResourceServiceAccount       = "service_account"
)

The actions of C-04: issuing and revoking tokens, and the lifecycle of Service accounts.

View Source
const (
	ResourceUser    = "user"
	ResourceSession = "session"
)

The resource types of C-03.

View Source
const (
	SystemName    = "Muster"
	BootstrapName = "bootstrap"
)

The names the Audit log shows for the actors that are not a user or a Service account.

View Source
const Erased = "[erased]"

Erased replaces, when the Audit log is read, a value that deleting a user erased (C-03.FR-13).

Variables

View Source
var Bootstrap = Actor{Kind: ActorBootstrap}

Bootstrap is the start-up step that creates the bootstrap Admin.

View Source
var System = Actor{Kind: ActorSystem}

System is Muster itself.

Functions

This section is empty.

Types

type Actor

type Actor struct {
	Kind ActorKind
	// ID and PublicID name the user or the Service account.
	ID        int64
	PublicID  string
	Name      string
	TokenID   int64
	TokenName string
}

Actor is who did it: a user or a Service account by id and public_id, Muster itself, the bootstrap step, or a CLI command with its --actor name. TokenID and TokenName name the Personal access token or Service account token used.

func CLI

func CLI(name string) Actor

CLI is a CLI command run by the person its --actor names; its entries take the Transport cli.

func ServiceAccount

func ServiceAccount(id int64, publicID string) Actor

ServiceAccount is the actor of a Service account; it acts only through one of its tokens (Via).

func User

func User(id int64, publicID string) Actor

User is the actor of a user.

func (Actor) Via

func (a Actor) Via(tokenID int64, name string) Actor

Via is the actor acting through the Personal access token or Service account token id named name; the Audit log shows it as "{user} via token {name}" or as the Service account and its token (C-04.FR-6).

type ActorKind

type ActorKind string

ActorKind is who did what an entry records.

const (
	ActorUser           ActorKind = "user"
	ActorServiceAccount ActorKind = "service_account"
	ActorSystem         ActorKind = "system"
	ActorBootstrap      ActorKind = "bootstrap"
	ActorCLI            ActorKind = "cli"
)

type Change

type Change struct {
	Pointer       string `json:"pointer"`
	Before        any    `json:"before,omitempty"`
	After         any    `json:"after,omitempty"`
	SecretChanged bool   `json:"secret_changed,omitempty"`
}

Change is one configured value that changed; a Secret shows only that it changed, never its value.

func Changed

func Changed[T comparable](pointer string, before, after T) []Change

Changed returns the change at pointer when before and after differ, and nothing otherwise.

func Created

func Created[T any](after T) []Change

Created returns the configured values of a resource that was just created, as the diff of its creation: each value that is set, with no value before.

func Diff

func Diff[T any](before, after T) []Change

Diff returns the configured values that differ between before and after, two views of the same resource, as the before/after diff of an Audit log entry (C-03.FR-14). Each exported field with a json name is one value at the JSON pointer of that name; a nested struct is walked field by field under its own name, and slices and maps are compared whole. A pointer is its value, nil being null; a pointer to a nested struct that is nil on one side is walked against an empty struct. A field tagged `audit:"secret"` is a Secret (C-03.FR-21): when it changes, the change says only that, with no value before or after.

type Cursor

type Cursor struct {
	At time.Time
	ID int64
}

Cursor is the sort key of the last entry of a page: the next page starts after it.

type Entry

type Entry struct {
	OrgID         int64
	Actor         Actor
	Transport     Transport
	Action        string
	Resource      Resource
	Diff          []Change
	Details       map[string]any
	SourceAddress netip.Addr
}

Entry is one Audit log entry. Details never carry a Secret.

type Filter

type Filter struct {
	From         *time.Time
	To           *time.Time
	Actor        string
	Action       string
	ResourceType string
	ResourceID   string
	After        *Cursor
	Limit        int
}

Filter selects entries (C-03.FR-15). From is inclusive and To exclusive; Actor is the public_id of a user or a Service account; empty fields do not filter. The list has no default time range: without From and To it starts with the newest entry.

type ListQueries

type ListQueries interface {
	FindUserActor(ctx context.Context, arg dbgen.FindUserActorParams) (int64, error)
	FindServiceAccountActor(ctx context.Context, arg dbgen.FindServiceAccountActorParams) (int64, error)
	ListAuditEntries(ctx context.Context, arg dbgen.ListAuditEntriesParams) ([]dbgen.ListAuditEntriesRow, error)
}

ListQueries are the reads of the list.

func NewListQueries

func NewListQueries(db dbgen.DBTX) ListQueries

NewListQueries are the reads of the list over a pool.

type Listed

type Listed struct {
	PublicID      string
	At            time.Time
	Actor         ListedActor
	TokenPublicID string
	TokenName     string
	Transport     Transport
	Action        string
	ResourceType  string
	ResourceID    string
	ResourceName  string
	Diff          []Change
	Details       map[string]any
}

Listed is one entry as the Audit log lists it.

type ListedActor

type ListedActor struct {
	Kind     ActorKind
	PublicID string
	Name     string
}

ListedActor is the actor of a listed entry with its current name: a deleted user shows as deleted-user-<id>.

type Page

type Page struct {
	Entries []Listed
	Next    *Cursor
}

Page is a page of entries, newest first; Next is nil on the last page.

type Reader

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

Reader lists the Audit log of the Organization.

func NewReader

func NewReader(orgID int64, q ListQueries) *Reader

NewReader returns the Reader of the Organization orgID.

func (*Reader) List

func (r *Reader) List(ctx context.Context, f Filter) (Page, error)

List returns a page of at most f.Limit entries, newest first by time and then id, that match f. An actor that is neither a user nor a Service account of the Organization matches nothing.

type Resource

type Resource struct {
	Type     string
	PublicID string
	Name     string
}

Resource is what an entry is about.

type Store

type Store interface {
	InsertAuditEntry(ctx context.Context, arg dbgen.InsertAuditEntryParams) error
}

Store inserts entries; it runs over a pool or inside the transaction of the change it records.

func NewStore

func NewStore(db dbgen.DBTX) Store

NewStore is the Store over a pool, a connection or a transaction.

type Transport

type Transport string

Transport is the way the action reached Muster.

const (
	TransportUI         Transport = "ui"
	TransportAPI        Transport = "api"
	TransportMattermost Transport = "mattermost"
	TransportTelegram   Transport = "telegram"
	TransportBridge     Transport = "bridge"
	TransportSlack      Transport = "slack"
	TransportCLI        Transport = "cli"
	TransportSystem     Transport = "system"
)

type Writer

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

Writer records entries on the business clock and copies each to the log.

func NewWriter

func NewWriter(log *logging.Logger, business clock.Clock) *Writer

NewWriter returns a Writer that dates entries with the business clock.

func (*Writer) Record

func (w *Writer) Record(ctx context.Context, s Store, e Entry) error

Record appends e through s and logs it as audit_entry; an entry that breaks the rules of the table is an error before anything is written.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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