-
Notifications
You must be signed in to change notification settings - Fork 9
Document audit log search and export #416
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+281
−0
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
92af4fa
Document audit logs API
yummybomb 6392fd8
Add Go audit log examples
yummybomb 3b91857
Clarify audit log filter wording and show paging headers
yummybomb e4dbf8b
Clarify audit log date range limit
yummybomb 1ac1f19
Document audit log search and export workflows
yummybomb 0bb6b42
Restructure audit log guide for parallel transport sections
yummybomb 85eb462
Drop Before you start section from audit log guide
yummybomb 8ffb09c
Show complete SDK exporter loop for audit log chunks
yummybomb ea3c521
Move CLI usage out of audit log guide to CLI reference
yummybomb 5433c1b
Move raw HTTP examples out of audit log guide to API reference
yummybomb c58722a
docs(audit-logs): align SDK, CLI, and API descriptions with existing …
yummybomb e706b47
Clarify audit log export safety
yummybomb 8a3300c
Write complete audit log export chunks
yummybomb 1467268
Polish audit logs description
yummybomb 291dc28
Simplify audit log search examples
yummybomb e876655
Clarify audit log method filters
yummybomb 4c96d64
Clarify audit log API filters
yummybomb 0afb910
Simplify audit log exclusion wording
yummybomb f03b0e3
Clarify audit log user search
yummybomb a217e20
Simplify audit log download behavior
yummybomb f831769
Merge branch 'main' into hypeship/document-audit-logs-api
yummybomb 5472320
Show accepted audit log time formats
yummybomb 8fa8062
Condense audit log time guidance
yummybomb e6754da
Make export safeguards scannable
yummybomb bb5c6b6
Use SDK audit log download helpers
yummybomb 7010f3d
Clarify SDK audit log download behavior
yummybomb fa09cc0
Use default audit log export format
yummybomb 1497fae
Clarify default audit log export output
yummybomb 1a6991c
Remove CLI behavior from SDK guide
yummybomb 7f4637f
Keep partial export guidance SDK-focused
yummybomb a793746
Remove partial export warning
yummybomb 485de11
Simplify audit log export fields
yummybomb db51f69
Clarify audit log search matching
yummybomb fb3c3ae
Rename workflow to endpoint and link table rows to sections
yummybomb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| --- | ||
| title: "Audit Logs" | ||
| description: "Search and export audit logs for API requests across your organization" | ||
| --- | ||
|
|
||
| Audit logs record authenticated API requests across your entire organization. Use them to review who called Kernel, which endpoint they called, when the request happened, and how the request completed. | ||
|
|
||
| Choose the endpoint that matches the amount of data you need: | ||
|
|
||
| | Endpoint | Best for | Output | | ||
| |----------|----------|--------| | ||
| | [Search](#search-audit-logs) | Interactive investigation and recent activity | Paginated JSON events | | ||
| | [Export](#export-audit-logs) | Archival, compliance, and offline analysis | Gzip-compressed JSON Lines (`.jsonl.gz`) | | ||
|
|
||
| Audit logs are ordered newest first. Time windows use an inclusive `start` and exclusive `end`: `[start, end)`. A search or export can cover up to 30 days. Split longer periods into multiple time windows. | ||
|
|
||
| Both endpoints are also available from the [CLI](/reference/cli/audit-logs). For the underlying HTTP API, see [search](https://kernel.sh/docs/api-reference/audit-logs/list-audit-logs) and [export](https://kernel.sh/docs/api-reference/audit-logs/download-an-audit-log-export-chunk) in the API reference. | ||
|
|
||
| ## Filter audit logs | ||
|
|
||
| The API and SDKs use the same filters for search and export: | ||
|
|
||
| - `auth_strategy` filters by authentication method, such as `api_key`, `dashboard`, or `oauth`. | ||
| - `service` filters by the service that emitted the audit event. | ||
| - `method` returns only requests that use the specified HTTP method. | ||
| - `exclude_method` omits requests that use any of the specified HTTP methods. | ||
| - `search` matches path, user ID, email, client IP, or status. | ||
| - `search_user_id` matches requests from the specified user IDs in addition to any free-text matches. | ||
|
|
||
| ## Search audit logs | ||
|
|
||
| Each API page contains up to 100 events. The SDK pagination helpers request older pages as you iterate. | ||
|
|
||
| <CodeGroup> | ||
| ```typescript TypeScript | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const kernel = new Kernel({ | ||
| apiKey: process.env.KERNEL_API_KEY, | ||
| }); | ||
|
|
||
| for await (const event of kernel.auditLogs.list({ | ||
| start: '2026-06-01T00:00:00Z', | ||
| end: '2026-06-02T00:00:00Z', | ||
| method: 'POST', | ||
| })) { | ||
| console.log(event.timestamp, event.method, event.path, event.status); | ||
| } | ||
|
yummybomb marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| ```python Python | ||
| import os | ||
| from kernel import Kernel | ||
|
|
||
| client = Kernel(api_key=os.environ["KERNEL_API_KEY"]) | ||
|
|
||
| for event in client.audit_logs.list( | ||
| start="2026-06-01T00:00:00Z", | ||
| end="2026-06-02T00:00:00Z", | ||
| method="POST", | ||
| ): | ||
| print(event.timestamp, event.method, event.path, event.status) | ||
|
yummybomb marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| ```go Go | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "time" | ||
|
|
||
| "github.com/kernel/kernel-go-sdk" | ||
| ) | ||
|
|
||
| func main() { | ||
| ctx := context.Background() | ||
| client := kernel.NewClient() | ||
|
|
||
| pager := client.AuditLogs.ListAutoPaging(ctx, kernel.AuditLogListParams{ | ||
| Start: time.Date(2026, time.June, 1, 0, 0, 0, 0, time.UTC), | ||
| End: time.Date(2026, time.June, 2, 0, 0, 0, 0, time.UTC), | ||
| Method: kernel.String("POST"), | ||
| }) | ||
| for pager.Next() { | ||
| event := pager.Current() | ||
| fmt.Println(event.Timestamp, event.Method, event.Path, event.Status) | ||
| } | ||
| if err := pager.Err(); err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| See the [API reference](https://kernel.sh/docs/api-reference/audit-logs/list-audit-logs) for the full request and response schema. | ||
|
|
||
| ## Export audit logs | ||
|
|
||
| The SDK download helpers default to `jsonl.gz` and write a complete export to a destination you provide. They: | ||
|
|
||
| - request every chunk until the export is complete | ||
| - validate pagination metadata and each chunk's SHA-256 checksum before writing | ||
| - retry transient HTTP and transfer failures | ||
| - append verified chunks in order | ||
|
|
||
| The helpers don't close the destination. Python provides equivalent sync and async methods; both accept a synchronous binary destination. | ||
|
cursor[bot] marked this conversation as resolved.
|
||
|
|
||
| <CodeGroup> | ||
| ```typescript TypeScript | ||
| import { open } from 'node:fs/promises'; | ||
| import Kernel from '@onkernel/sdk'; | ||
|
|
||
| const kernel = new Kernel({ | ||
| apiKey: process.env.KERNEL_API_KEY, | ||
| }); | ||
|
|
||
| const file = await open('audit-logs.jsonl.gz', 'w'); | ||
| try { | ||
| await kernel.auditLogs.download( | ||
| { | ||
| start: '2026-06-01T00:00:00Z', | ||
| end: '2026-06-02T00:00:00Z', | ||
| exclude_method: ['GET'], | ||
| }, | ||
| file, | ||
| ); | ||
| } finally { | ||
| await file.close(); | ||
| } | ||
| ``` | ||
|
|
||
| ```python Python | ||
| import os | ||
| from kernel import Kernel | ||
|
|
||
| client = Kernel(api_key=os.environ["KERNEL_API_KEY"]) | ||
|
|
||
| with open("audit-logs.jsonl.gz", "wb") as file: | ||
| client.audit_logs.download( | ||
| to=file, | ||
| start="2026-06-01T00:00:00Z", | ||
| end="2026-06-02T00:00:00Z", | ||
| exclude_method=["GET"], | ||
| ) | ||
| ``` | ||
|
|
||
| ```go Go | ||
| package main | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "time" | ||
|
|
||
| "github.com/kernel/kernel-go-sdk" | ||
| ) | ||
|
|
||
| func main() { | ||
| ctx := context.Background() | ||
| client := kernel.NewClient() | ||
|
|
||
| file, err := os.Create("audit-logs.jsonl.gz") | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer file.Close() | ||
|
|
||
| _, err = client.AuditLogs.Download(ctx, kernel.AuditLogDownloadParams{ | ||
| Start: time.Date(2026, time.June, 1, 0, 0, 0, 0, time.UTC), | ||
| End: time.Date(2026, time.June, 2, 0, 0, 0, 0, time.UTC), | ||
| ExcludeMethod: []string{"GET"}, | ||
| }, file) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| } | ||
| ``` | ||
| </CodeGroup> | ||
|
|
||
| Export chunks contain one JSON object per line. They use the same fields as search results and add `event_id`. | ||
|
|
||
| For direct HTTP integrations, see the [API reference](https://kernel.sh/docs/api-reference/audit-logs/download-an-audit-log-export-chunk) for pagination headers, formats, and the full request and response schema. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| --- | ||
| title: "Audit Logs" | ||
| --- | ||
|
|
||
| Search and download [organization audit logs](/info/audit-logs) from the CLI. | ||
|
|
||
| Time values can be dates (`2026-06-01`) or timestamps (`2026-06-01T15:04:05Z`). Dates begin at midnight UTC. | ||
|
|
||
| ## `kernel audit-logs search` | ||
|
|
||
| Search audit logs within a time window. Results are ordered newest first. | ||
|
|
||
| ```bash | ||
| kernel audit-logs search \ | ||
| --start 2026-06-01 \ | ||
| --end 2026-06-08 \ | ||
| --search /browsers \ | ||
| --limit 500 \ | ||
| --output json | ||
| ``` | ||
|
|
||
| If you omit the time flags, the command searches from 24 hours ago through now. The start is inclusive and the end is exclusive. Each time window can cover up to 30 days. | ||
|
|
||
| | Flag | Description | | ||
| |------|-------------| | ||
| | `--start <time>` | Inclusive start. Defaults to 24 hours ago. | | ||
| | `--end <time>` | Exclusive end. Defaults to now. | | ||
| | `--search <text>` | Search path, user ID, email, client IP, and status. | | ||
| | `--method <method>` | Return only requests that use this HTTP method. | | ||
| | `--exclude-method <method>` | Exclude requests that use this HTTP method. GET remains excluded unless you pass `--include-get`. | | ||
| | `--include-get` | Remove the default GET exclusion when `--method` is not set. | | ||
| | `--service <service>` | Filter by service. | | ||
| | `--auth-strategy <strategy>` | Filter by authentication strategy. | | ||
| | `--user-id <id>` | Add a user ID to the search. Repeat the flag for multiple IDs. | | ||
| | `--limit <n>` | Maximum total number of results. Defaults to `100`. | | ||
| | `--output json`, `-o json` | Output raw JSON array. | | ||
|
|
||
| <Note> | ||
| `--limit` controls the total number of CLI results. The CLI automatically requests API pages of up to 100 records until it reaches that limit or runs out of results. | ||
| </Note> | ||
|
|
||
| ### Include GET requests | ||
|
|
||
| By default, the CLI returns matching requests for every HTTP method except GET. `--include-get` removes that default exclusion. `--method` selects exactly one method, so `--method GET` returns only GET requests. | ||
|
|
||
| ```bash | ||
| # Return all matching methods, including GET | ||
| kernel audit-logs search --include-get | ||
|
|
||
| # Return only GET requests | ||
| kernel audit-logs search --method GET | ||
| ``` | ||
|
|
||
| ## `kernel audit-logs download` | ||
|
|
||
| Download matching audit logs in a time window as one gzip-compressed JSONL file. | ||
|
|
||
| ```bash | ||
| kernel audit-logs download \ | ||
| --start 2026-06-01 \ | ||
| --end 2026-07-01 \ | ||
| --to audit-june.jsonl.gz | ||
| ``` | ||
|
|
||
| `--start` and `--end` are required. The start is inclusive and the end is exclusive, and the time window can cover up to 30 days. | ||
|
|
||
| | Flag | Description | | ||
| |------|-------------| | ||
| | `--start <time>` | Inclusive start. Required. | | ||
| | `--end <time>` | Exclusive end. Required. | | ||
| | `--search <text>` | Search path, user ID, email, client IP, and status. | | ||
| | `--method <method>` | Return only requests that use this HTTP method. | | ||
| | `--exclude-method <method>` | Exclude requests that use this HTTP method. GET remains excluded unless you pass `--include-get`. | | ||
| | `--include-get` | Remove the default GET exclusion when `--method` is not set. | | ||
| | `--service <service>` | Filter by service. | | ||
| | `--auth-strategy <strategy>` | Filter by authentication strategy. | | ||
| | `--user-id <id>` | Add a user ID to the search. Repeat the flag for multiple IDs. | | ||
| | `--to <path>` | Output `.jsonl.gz` path. For the example above, the default is `audit-logs-20260601-20260701.jsonl.gz`. | | ||
| | `--force` | Replace an existing output file. | | ||
|
|
||
| For example, `--start 2026-06-01 --end 2026-07-01` covers all of June in UTC. | ||
|
|
||
| ### Download behavior | ||
|
|
||
| The CLI downloads up to 50,000 records per batch, verifies each batch's SHA-256 checksum, and automatically retries transient failures. | ||
|
|
||
| The requested output appears only after the full download succeeds. Failed downloads are removed, though a completed download may remain at `<output>.partial` if it can't be moved to the requested path. | ||
|
|
||
| Downloads don't resume: rerunning the command starts over. Existing files are replaced only when you pass `--force`. | ||
|
|
||
| ## Aliases | ||
|
|
||
| You can also use `kernel audit-log`, `kernel auditlogs`, or `kernel auditlog`. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.