Overview
Theaudit command retrieves and displays audit logs from a Cerbos server. It supports both access logs and decision logs, with flexible filtering options and output formats.
Audit logging must be enabled on the Cerbos server for this command to work. The server must be configured to capture the type of logs you want to view (access or decision).
Syntax
Log Types
The--kind flag specifies which type of audit log to view:
- access: Access logs showing API calls and metadata (default)
- decision: Decision logs with detailed authorization results
Usage Examples
View decision logs from a time range
View logs from a start time to now
View logs from the last N hours
h=hours, m=minutes, s=seconds.Flags
Required Flags
| Flag | Description | Default | Values |
|---|---|---|---|
--kind | Type of log entry | access | access, decision |
Filter Flags
Only one filter can be used at a time:| Flag | Description | Example |
|---|---|---|
--tail <n> | View the last N records | --tail=50 |
--between <time1>[,<time2>] | View records between timestamps (ISO-8601 format) | --between=2021-07-01T00:00:00Z,2021-07-02T00:00:00Z |
--since <duration> | View records from X ago to now (h=hours, m=minutes, s=seconds) | --since=2h30m |
--lookup <call-id> | View a specific record by Cerbos Call ID | --lookup=01F9Y5MFYTX7Y87A30CTJ2FB0S |
If no filter is specified, the command defaults to
--tail=30 (showing the last 30 records).Output Flags
| Flag | Description |
|---|---|
--raw | Output newline-delimited JSON without formatting or colors |
Output Formats
Formatted Output (Default)
By default, logs are displayed with:- Colored headers with Call IDs
- Syntax-highlighted JSON
- Organized by log entry
Raw Output
With--raw, logs are output as newline-delimited JSON (NDJSON), suitable for piping to other tools:
Access Log Structure
Access logs capture metadata about API calls:callId: Unique identifier for the API calltimestamp: When the call was receivedpeer.address: Client IP address and portpeer.userAgent: Client SDK or application identifierpeer.forwardedFor: Original client IP if behind a proxymethod: gRPC method that was calledmetadata: Request metadata/headers
Decision Log Structure
Decision logs contain detailed authorization information:checkResources: Authorization check detailsplanResources: Query plan details (for PlanResources calls)inputs: Request parameters (principals, resources, actions)outputs: Authorization results for each inputeffectiveDerivedRoles: Derived roles that applied
Common Use Cases
Audit Trail
Capture all access logs for compliance:Debug Authorization Issues
Find recent authorization decisions:Monitor API Usage
View recent API calls:Export for Analysis
Export logs in JSON format for analysis with other tools:Investigate Specific Call
When you have a Call ID from application logs:Advanced Filtering with jq
Combine--raw output with jq for powerful filtering:
Find all denied actions
Extract specific fields
Count calls by method
Find calls from specific IP
Time Formats
The--between flag requires ISO-8601 formatted timestamps:
Performance Considerations
- Large Result Sets: Fetching many records (e.g.,
--tail=100000) may take time and use significant memory - Network Transfer: Decision logs are larger than access logs due to detailed authorization data
- Time Ranges: Narrow time ranges query faster than broad ranges
- Raw Output: Using
--rawis faster than formatted output for large datasets
Troubleshooting
No logs returned
Problem: The command returns no results. Solutions:- Verify audit logging is enabled on the Cerbos server
- Check the correct log type:
--kind=accessor--kind=decision - Verify the server has captured logs in the specified time range
- Try a wider time range or higher
--tailvalue
Connection errors
Problem: Cannot connect to the Cerbos server. Solutions:- Verify server address:
--server=localhost:3593 - Check authentication credentials (
--username,--password) - Ensure Admin API is enabled on the server
- Verify network connectivity and firewall rules
Invalid timestamp format
Problem: Error about invalid timestamp. Solutions:- Use ISO-8601 format:
2021-07-01T00:00:00Z - Include timezone (Z for UTC or offset like +02:00)
- Ensure time format is exactly as specified
Memory issues
Problem: Command uses too much memory or runs slowly. Solutions:- Reduce the number of records: use smaller
--tailvalue - Use narrower time ranges with
--betweenor--since - Use
--rawoutput instead of formatted output - Process in smaller batches
Differences from decisions Command
Theaudit command differs from decisions in several ways:
| Feature | audit | decisions |
|---|---|---|
| Output | Text/JSON | Interactive TUI |
| Log Types | Access and Decision | Decision only |
| Format Options | Formatted or raw | Interactive UI |
| Piping | Supports piping | No piping |
| Analysis | External tools (jq) | Built-in viewer |
| Use Case | Export, scripting, automation | Interactive exploration |