Overview
Audit logs capture:- API request metadata (URI, method, user, timestamp)
- Request headers and response headers
- Request body and response body (at higher audit levels)
- Authentication information
- Response status codes
Configuration Methods
Via CLI Flags
Configure audit logging using command-line flags when starting Rancher:Via Environment Variables
Set audit logging configuration using environment variables:Via Helm Chart
Configure audit logging in your Helm values file:Configuration Options
Enable Audit Log
CLI Flag:--enable-audit-logEnvironment Variable:
AUDIT_LOG_ENABLEDHelm Value:
auditLog.enabledDefault:
falseSource: main.go:144 Enables the Rancher audit log system.
Audit Log Path
CLI Flag:--audit-log-pathEnvironment Variable:
AUDIT_LOG_PATHHelm Value:
auditLog.hostPathDefault:
/var/log/auditlog/rancher-api-audit.logSource: main.go:110 Specifies the file path where audit logs will be written.
Audit Level
CLI Flag:--audit-levelEnvironment Variable:
AUDIT_LEVELHelm Value:
auditLog.levelDefault:
0Source: main.go:138 Controls the verbosity of audit logs. Higher levels include more information.
Level 0 - Metadata Only
Logs only request metadata:- Request URI
- HTTP method
- User identity
- Timestamp
- Response status
Level 1 - Metadata and Headers
Includes Level 0 plus:- Request headers
- Response headers
Level 2 - Headers and Request Body
Includes Level 1 plus:- Request body
Level 3 - Full Logging
Includes Level 2 plus:- Response body
Log Rotation Options
Max Age
CLI Flag:--audit-log-maxageEnvironment Variable:
AUDIT_LOG_MAXAGEHelm Value:
auditLog.maxAgeDefault:
10Source: main.go:117 Maximum number of days to retain old audit log files.
Max Backup
CLI Flag:--audit-log-maxbackupEnvironment Variable:
AUDIT_LOG_MAXBACKUPHelm Value:
auditLog.maxBackupDefault:
10Source: main.go:124 Maximum number of audit log files to retain.
Max Size
CLI Flag:--audit-log-maxsizeEnvironment Variable:
AUDIT_LOG_MAXSIZEHelm Value:
auditLog.maxSizeDefault:
100 (megabytes)Source: main.go:131 Maximum size in megabytes of the audit log file before it gets rotated.
Audit Log Destinations
Sidecar Container (Recommended)
When using the sidecar destination, audit logs are written to a sidecar container that runs alongside Rancher.auditLog.destination: sidecarauditLog.image.repository: rancher/mirrored-bci-microauditLog.image.tag: 15.6.24.2auditLog.resources: {}- Set resource requests/limits for the sidecar
- Logs are accessible via kubectl
- No host filesystem dependencies
- Works on any Kubernetes platform
- Easy to integrate with logging systems
Host Path Volume
When using the hostPath destination, audit logs are written directly to the host filesystem.- Direct filesystem access
- Can use host-based log rotation tools
- Persistent across pod restarts
- Requires host filesystem access
- Node affinity may be needed for log persistence
- May not work on all Kubernetes platforms
Audit Log Format
Audit logs are written in JSON format with the following structure:Key Fields
| Field | Description |
|---|---|
auditID | Unique identifier for the audit event |
requestURI | The API endpoint that was accessed |
verb | HTTP method (GET, POST, PUT, DELETE, etc.) |
user | Information about the authenticated user |
sourceIPs | IP addresses of the client |
userAgent | Client user agent string |
objectRef | Details about the Kubernetes resource |
responseStatus | HTTP response status code |
requestReceivedTimestamp | When the request was received |
stageTimestamp | When the audit event was generated |
Audit Policy
Rancher uses an internal audit policy to determine what gets logged. The policy is configured based on the audit level:- Level 0: Metadata stage only
- Level 1: Metadata stage with headers
- Level 2: RequestResponse stage without response body
- Level 3: Full RequestResponse stage
Common Use Cases
Compliance Auditing
For compliance requirements, use Level 1 with long retention:Security Investigation
For security investigations, temporarily enable Level 2 or 3:Production Monitoring
For ongoing production monitoring, use Level 1:Integration with Log Management
Forwarding to Splunk
Use a log forwarder to send audit logs to Splunk:Forwarding to Elasticsearch
Forward logs using Filebeat or Fluentd:Performance Considerations
Log Volume
Audit log volume varies significantly by level:| Level | Typical Size per Request | Daily Volume (1000 req/min) |
|---|---|---|
| 0 | ~500 bytes | ~720 MB |
| 1 | ~2 KB | ~2.8 GB |
| 2 | ~10 KB | ~14 GB |
| 3 | ~50 KB | ~70 GB |
Resource Impact
- Level 0-1: Minimal impact (less than 1% CPU overhead)
- Level 2: Moderate impact (2-5% CPU overhead)
- Level 3: Significant impact (5-10% CPU overhead)
Sidecar Resources
Set appropriate resource limits for the audit log sidecar:Troubleshooting
Audit Logs Not Appearing
-
Check if audit logging is enabled:
-
Verify the audit log sidecar is running:
-
Check Rancher logs for errors:
Log Rotation Not Working
Log rotation only applies when using hostPath destination. For sidecar destination, use a log management solution to archive old logs.Disk Space Issues
If audit logs are consuming too much disk space:-
Reduce audit level:
-
Reduce retention:
-
Reduce max size:
Best Practices
- Start with Level 1: Provides good visibility without excessive overhead
- Use Sidecar Destination: Easier to manage in Kubernetes environments
- Configure Log Forwarding: Send logs to a centralized log management system
- Set Appropriate Retention: Balance compliance needs with storage costs
- Monitor Log Volume: Set up alerts for excessive log growth
- Secure Log Access: Restrict access to audit logs using RBAC
- Regular Review: Periodically review audit logs for suspicious activity
- Test Before Production: Verify audit logging in a test environment first
Next Steps
- Server Configuration - Configure Rancher server options
- SSL/TLS Configuration - Set up certificates
- Security Best Practices - Secure your Rancher deployment