Documentation
¶
Overview ¶
Package audit is the endpoint group for the audit log: the record of each request the controller served.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is an audit entry that is not there. ErrNotFound = errors.New("audit entry not found") // ErrNotConfigured is a controller with no audit stream configured. ErrNotConfigured = errors.New("the audit log is not configured") )
var Group = endpoint.Register(endpoint.Define( "audit", "Read the audit log", endpoint.Area(area.Audit), endpoint.Title("Audit Log API"), endpoint.Tag("audit", "Audit", "Audit log endpoints for viewing API activity."), endpoint.Uses[Deps](), endpoint.Example[Entry]( "request_summary", `{"command":"systemctl","args":["restart","nginx"]}`, ), endpoint.Get[ListInput, ListAuditResponse]("list"). AdminOnly(). Fails("a limit below 1", ListInput{Limit: -1}). Fails("a limit over 100", ListInput{Limit: 101}). Fails("a negative offset", ListInput{Offset: -1}). Fails("a user over 256 characters", ListInput{User: strings.Repeat("u", 257)}). Fails("an operation over 256 characters", ListInput{Operation: strings.Repeat("o", 257)}). Fails("a status below 100", ListInput{Status: 99}). Fails("a status over 599", ListInput{Status: 600}). Handle(List). ID("GetAuditLogs"). Describe("List audit log entries"). Explain("Returns a paginated list of audit log entries, newest first. A token with a "+ "target scope gets only the entries of requests to a target in its scope, and the "+ "total includes only those entries."). Returns("List of audit entries."). Command("List audit log entries", "The list shows recent API activity: the user, the HTTP method, the path,\n"+ "the response status and the duration. The filters narrow it: --writes\n"+ "for the requests that change something, --user, --operation for text of\n"+ "the operation ID or the path, and --status."). Example(""). Prints(sampleList). Example("--limit 10 --offset 20"). Example("--writes --user ops@example.com"). Example("--operation hostname --status 403"). Example("--json"). Errors(notConfigured503), endpoint.Get[ExportInput, ListAuditResponse]("export"). AdminOnly(). Handle(Export). Sub("export"). ID("GetAuditExport"). Describe("Export all audit log entries"). Explain("Returns all audit log entries without pagination for export. A token with a "+ "target scope gets only the entries of requests to a target in its scope."). Returns("All audit entries."). Command("Show all audit log entries, with no pages", "To save them, send the JSON to a file:\n"+ "osapi client audit export --json > audit.json"). Example(""). Prints(sampleList). Example("--json"). Errors(notConfigured503), endpoint.Get[GetInput, EntryResponse]("get"). AdminOnly(). Fails("an ID that is not a UUID", GetInput{ID: "not-a-uuid"}). Handle(Get). ID("GetAuditLogByID"). Describe("Get a single audit log entry"). Explain("Returns a single audit log entry by ID. An entry of a request to a target "+ "outside the target scope of the token is not found."). Returns("Audit entry found."). Command("Get a single audit log entry", ""). Example("--id 550e8400-e29b-41d4-a716-446655440000"). Prints(sampleGet). Example("--id 550e8400-e29b-41d4-a716-446655440000 --json"). Errors(endpoint.NotFound( ErrNotFound, "Audit entry not found, or its target is outside the token's target scope.", ), notConfigured503), ))
Group is the audit group's definition.
Functions ¶
This section is empty.
Types ¶
type Deps ¶
type Deps struct {
// Store reads the audit log. Nil when nats.audit.stream is not set; each
// method then answers 503.
Store Store
}
Deps is what the audit group's handlers use.
type Entry ¶
type Entry struct {
ID string `` /* 315-byte string literal not displayed */
Timestamp time.Time `` /* 283-byte string literal not displayed */
User string `` /* 278-byte string literal not displayed */
Actor string `` /* 269-byte string literal not displayed */
Action string `` /* 325-byte string literal not displayed */
Target string `` /* 325-byte string literal not displayed */
Roles []types.Role `` /* 325-byte string literal not displayed */
Targets []string `` /* 325-byte string literal not displayed */
Method string `` /* 266-byte string literal not displayed */
Path string `` /* 277-byte string literal not displayed */
ResponseCode int `` /* 340-byte string literal not displayed */
DurationMs int64 `` /* 364-byte string literal not displayed */
SourceIP string `` /* 325-byte string literal not displayed */
OperationID string `` /* 343-byte string literal not displayed */
TraceID string `` /* 361-byte string literal not displayed */
JobID string `` /* 325-byte string literal not displayed */
RequestSummary string `` /* 325-byte string literal not displayed */
Steps []HostSteps `` /* 354-byte string literal not displayed */
Chain []string `` /* 325-byte string literal not displayed */
// contains filtered or unexported fields
}
Entry is the record of one request.
type EntryResponse ¶
type EntryResponse struct {
Entry Entry `json:"entry"`
// contains filtered or unexported fields
}
EntryResponse is one audit entry.
type GetInput ¶
type GetInput struct {
ID string `json:"id" in:"path" validate:"uuid" doc:"The audit entry ID."`
}
GetInput names the audit entry to read.
type HostSteps ¶
type HostSteps = struct {
Hostname string `json:"hostname" doc:"The host that answered the job."`
Steps []types.Step `json:"steps" doc:"The calls, in the order that the method made them."`
}
HostSteps are the calls of other behaviors that the method of the job made on one host, in place in the spec.
type ListAuditResponse ¶
type ListAuditResponse struct {
TotalItems int ` json:"total_items" doc:"Total number of audit entries." example:"150"`
Items []Entry ` json:"items" doc:"The audit entries for this page."`
// contains filtered or unexported fields
}
ListAuditResponse is a page of the audit log, or all of it.
func Export ¶
func Export( ctx context.Context, d Deps, _ ExportInput, ) (ListAuditResponse, error)
Export is each entry of the audit log, without pages.
type ListInput ¶
type ListInput struct {
Limit int `json:"limit" in:"query" validate:"omitempty,min=1,max=100" default:"20" doc:"Maximum number of entries to return."`
Offset int `json:"offset" in:"query" validate:"omitempty,min=0" default:"0" doc:"Number of entries to skip."`
// The filters. An entry is listed when it matches each filter that is
// set. With a filter, the list reads the whole log and counts the
// entries that match.
Writes bool `` /* 142-byte string literal not displayed */
User string `` /* 137-byte string literal not displayed */
Operation string `` /* 157-byte string literal not displayed */
Status int `` /* 137-byte string literal not displayed */
}
ListInput is a page of the audit log.