Documentation
¶
Overview ¶
Package audit records who changed what (#79, ADR-0036): state-changing API requests, terminal sessions, authorization denials and authentication. Request bodies are never stored: they can hold passwords, tokens and environment values.
Index ¶
- Constants
- func ClientIP(r *http.Request) string
- func WriteCSV(w io.Writer, entries []Entry) error
- type Entry
- type Filter
- type Recorder
- func (rec *Recorder) Audit(r *http.Request, a authz.AuditRecord)
- func (rec *Recorder) Auth(r *http.Request, action, username string, ok bool, msg string)
- func (rec *Recorder) JobFinished(j jobs.Job)
- func (rec *Recorder) List(ctx context.Context, f Filter) ([]Entry, error)
- func (rec *Recorder) Run(ctx context.Context)
- type Store
Constants ¶
const ( ResultOK = "ok" ResultFailed = "failed" ResultDenied = "denied" ResultAccepted = "accepted" // a background job runs; set to ok or failed when it ends )
Results.
const ( ActionSetup = "auth:setup" ActionLogin = "auth:login" ActionLogout = "auth:logout" )
Authentication actions, recorded by the auth service.
const DefaultRetention = 90 * 24 * time.Hour
DefaultRetention keeps 90 days.
const (
// MaxRows bounds one page of the log.
MaxRows = 500
)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Entry ¶
type Entry struct {
ID int64 `json:"id"`
At time.Time `json:"at"`
User string `json:"user,omitempty"`
APIKey bool `json:"apiKey,omitempty"`
// APIKeyName is "<name> (<prefix>…)" of the key that made the request (#80).
APIKeyName string `json:"apiKeyName,omitempty"`
Action string `json:"action"`
Method string `json:"method,omitempty"`
Path string `json:"path,omitempty"`
Environment string `json:"environment,omitempty"`
Namespace string `json:"namespace,omitempty"`
Object string `json:"object,omitempty"`
Status int `json:"status,omitempty"`
Result string `json:"result"`
Message string `json:"message,omitempty"`
JobID string `json:"jobId,omitempty"`
ClientIP string `json:"clientIp,omitempty"`
UserAgent string `json:"userAgent,omitempty"`
}
Entry is one log entry. Keep in sync with api/openapi.yaml.
type Filter ¶
type Filter struct {
User string
Result string
Query string
Since time.Time
Until time.Time
Before int64 // entries with smaller IDs, for paging
Limit int
}
Filter selects log entries.
type Recorder ¶
type Recorder struct {
Store Store
// Retention is how long entries are kept; 0 keeps them forever.
Retention time.Duration
Logger *slog.Logger
Now func() time.Time
// contains filtered or unexported fields
}
Recorder writes the audit log. It implements authz.Auditor.
func (*Recorder) Audit ¶
func (rec *Recorder) Audit(r *http.Request, a authz.AuditRecord)
Audit implements authz.Auditor.
func (*Recorder) Auth ¶
Auth records an authentication event; username is who tried, also when it failed.
func (*Recorder) JobFinished ¶
JobFinished completes the entry of a request that started a job; use as jobs.Manager.OnFinish.
type Store ¶
type Store interface {
InsertAudit(ctx context.Context, arg db.InsertAuditParams) error
SetAuditJobResult(ctx context.Context, arg db.SetAuditJobResultParams) error
ListAudit(ctx context.Context, arg db.ListAuditParams) ([]db.AuditLog, error)
PruneAudit(ctx context.Context, before int64) (int64, error)
}
Store is the database of the log; *db.Queries of the write connection implements it.