Audit
c.Audit calls the API's Audit group. Audit log endpoints for viewing API
activity.
Methods
| Method | Returns | Permission | Description |
|---|---|---|---|
List(ctx, params) | *Response[ListAuditResponse] | audit:read | List audit log entries. |
Export(ctx) | *Response[ListAuditResponse] | audit:read | Export all audit log entries. |
Get(ctx, id) | *Response[AuditEntryResponse] | audit:read | Get 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
| Field | Type | Description |
|---|---|---|
Action | string | What a change that did not go through the API did, such as agent.admit or jointoken.create. |
Actor | string | The 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 | []string | The steps on one line for each host, such as web-01: managedfile update (changed). |
DurationMS | int64 | Request duration in milliseconds. |
ID | string | Unique identifier for the audit entry. |
JobID | string | The job this request created, absent when it created none. Joins the entry to that job's own status timeline. |
Method | string | HTTP method. |
OperationID | string | OpenAPI operation ID. |
Path | string | Request URL path. |
RequestSummary | string | What the request asked for, with sensitive values replaced. Recorded for methods that change something. |
ResponseCode | int | HTTP response status code. |
Roles | []string | Roles from the JWT token. |
SourceIP | string | Client IP address. |
Steps | []AuditEntryStepsItem | The 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. |
Target | string | What the action was on, such as a machine ID or a join token's ID. |
Targets | []string | The target scope of the JWT token, absent when the token acts on each host. |
Timestamp | time.Time | When the request was processed. |
TraceID | string | OpenTelemetry trace ID for correlation. |
User | string | Who did it: the authenticated user (JWT subject), or the name of another actor. |
AuditEntryResponse
| Field | Type | Description |
|---|---|---|
Entry | AuditEntry |
AuditEntryStepsItem
| Field | Type | Description |
|---|---|---|
Hostname | string | The host that answered the job. |
Steps | []Step | The calls, in the order that the method made them. |
ListAuditResponse
| Field | Type | Description |
|---|---|---|
Items | []AuditEntry | The audit entries for this page. |
TotalItems | int | Total number of audit entries. |
Step
| Field | Type | Description |
|---|---|---|
Behavior | string | |
Changed | bool | |
DurationMS | int64 | |
Error | string | |
Method | string | |
Steps | []Step |
Example
examples/sdk/client/audit.go
runs each example of this page. With no argument, it lists them.