Skip to main content

Audit

c.Audit calls the API's Audit group. Audit log endpoints for viewing API activity.

Methods​

MethodReturnsPermissionDescription
List(ctx, params)*Response[ListAuditResponse]audit:readList audit log entries.
Export(ctx)*Response[ListAuditResponse]audit:readExport all audit log entries.
Get(ctx, id)*Response[AuditEntryResponse]audit:readGet a single audit log entry.

List​

func (s *AuditService) List(
ctx context.Context,
params AuditListParams,
) (*Response[ListAuditResponse], error)

List audit log entries.

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.

It sends GET /api/audit, and needs the permission audit:read.

The examples of the method's definition:

List audit log entries, go run audit.go list:

resp, err := c.Audit.List(ctx, client.AuditListParams{})

List audit log entries, with --limit 10 --offset 20, go run audit.go list-2:

resp, err := c.Audit.List(ctx, client.AuditListParams{
Limit: 10,
Offset: 20,
})

List audit log entries, with --writes --user ops@example.com, go run audit.go list-3:

resp, err := c.Audit.List(ctx, client.AuditListParams{
User: "ops@example.com",
Writes: true,
})

List audit log entries, with --operation hostname --status 403, go run audit.go list-4:

resp, err := c.Audit.List(ctx, client.AuditListParams{
Operation: "hostname",
Status: 403,
})

Export​

func (s *AuditService) Export(
ctx context.Context,
) (*Response[ListAuditResponse], error)

Export all audit log entries.

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.

It sends GET /api/audit/export, and needs the permission audit:read.

The examples of the method's definition:

Export all audit log entries, go run audit.go export:

resp, err := c.Audit.Export(ctx)

Get​

func (s *AuditService) Get(
ctx context.Context,
id string,
) (*Response[AuditEntryResponse], error)

Get a single audit log entry.

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.

It sends GET /api/audit/{id}, and needs the permission audit:read.

The examples of the method's definition:

Get a single audit log entry, go run audit.go get:

resp, err := c.Audit.Get(ctx, "550e8400-e29b-41d4-a716-446655440000")

Types​

The fields of each type are the properties of its schema in the API's spec.

AuditEntry​

FieldTypeDescription
ActionstringWhat a change that did not go through the API did, such as agent.admit or jointoken.create.
ActorstringThe kind of who made a change that did not go through the API: system, join-token, agent or local. Absent for a request through the API.
Chain[]stringThe steps on one line for each host, such as web-01: managedfile update (changed).
DurationMSint64Request duration in milliseconds.
IDstringUnique identifier for the audit entry.
JobIDstringThe job this request created, absent when it created none. Joins the entry to that job's own status timeline.
MethodstringHTTP method.
OperationIDstringOpenAPI operation ID.
PathstringRequest URL path.
RequestSummarystringWhat the request asked for, with sensitive values replaced. Recorded for methods that change something.
ResponseCodeintHTTP response status code.
Roles[]stringRoles from the JWT token.
SourceIPstringClient IP address.
Steps[]AuditEntryStepsItemThe calls of other behaviors that the method of the job made, for each host that answered before the request returned, also when one failed. Absent when no host made a call.
TargetstringWhat the action was on, such as a machine ID or a join token's ID.
Targets[]stringThe target scope of the JWT token, absent when the token acts on each host.
Timestamptime.TimeWhen the request was processed.
TraceIDstringOpenTelemetry trace ID for correlation.
UserstringWho did it: the authenticated user (JWT subject), or the name of another actor.

AuditEntryResponse​

FieldTypeDescription
EntryAuditEntry

AuditEntryStepsItem​

FieldTypeDescription
HostnamestringThe host that answered the job.
Steps[]StepThe calls, in the order that the method made them.

ListAuditResponse​

FieldTypeDescription
Items[]AuditEntryThe audit entries for this page.
TotalItemsintTotal number of audit entries.

Step​

FieldTypeDescription
Behaviorstring
Changedbool
DurationMSint64
Errorstring
Methodstring
Steps[]Step

Example​

examples/sdk/client/audit.go runs each example of this page. With no argument, it lists them.