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 ¶
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.
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.
const ( ResourceUser = "user" ResourceSession = "session" )
The resource types of C-03.
const ( SystemName = "Muster" BootstrapName = "bootstrap" )
The names the Audit log shows for the actors that are not a user or a Service account.
const Erased = "[erased]"
Erased replaces, when the Audit log is read, a value that deleting a user erased (C-03.FR-13).
Variables ¶
var Bootstrap = Actor{Kind: ActorBootstrap}
Bootstrap is the start-up step that creates the bootstrap Admin.
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 ¶
CLI is a CLI command run by the person its --actor names; its entries take the Transport cli.
func ServiceAccount ¶
ServiceAccount is the actor of a Service account; it acts only through one of its tokens (Via).
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 ¶
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 ¶
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 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 ¶
ListedActor is the actor of a listed entry with its current name: a deleted user shows as deleted-user-<id>.
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.
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.