loki-mode 5.42.2 → 5.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@
2
2
 
3
3
  The flagship product of [Autonomi](https://www.autonomi.dev/). Complete installation instructions for all platforms and use cases.
4
4
 
5
- **Version:** v5.42.2
5
+ **Version:** v5.46.0
6
6
 
7
7
  ---
8
8
 
@@ -0,0 +1,600 @@
1
+ # Audit Logging
2
+
3
+ Compliance-ready audit trails for Loki Mode operations.
4
+
5
+ ## Overview
6
+
7
+ Audit logging captures all significant events for compliance requirements (SOC2, HIPAA), security monitoring, debugging, and usage analytics. Audit logging is **enabled by default** as of v5.37.0.
8
+
9
+ ## Configuration
10
+
11
+ ### Enable/Disable Audit Logging
12
+
13
+ Audit logging is on by default. To disable:
14
+
15
+ ```bash
16
+ export LOKI_AUDIT_DISABLED=true
17
+ ```
18
+
19
+ The legacy variable `LOKI_ENTERPRISE_AUDIT=true` still works and will force audit logging on regardless of `LOKI_AUDIT_DISABLED`.
20
+
21
+ ### Configuration File
22
+
23
+ ```yaml
24
+ # .loki/config.yaml
25
+ enterprise:
26
+ audit:
27
+ enabled: true # Audit logging enabled (default)
28
+ level: info # Minimum level: debug, info, warning, error
29
+ retention_days: 90 # Days to keep logs
30
+ max_file_size: 100 # MB per file before rotation
31
+ compress: true # Compress rotated files
32
+ integrity_check: true # Enable SHA-256 chain hashing (v5.38.0)
33
+ syslog_enabled: false # Forward to external syslog
34
+ exclude_events: # Events to exclude
35
+ - api.request
36
+ include_metadata: # Additional metadata fields
37
+ - environment
38
+ - deployment_id
39
+ ```
40
+
41
+ ### Environment Variables
42
+
43
+ | Variable | Default | Description |
44
+ |----------|---------|-------------|
45
+ | `LOKI_AUDIT_DISABLED` | `false` | Set to `true` to disable audit logging |
46
+ | `LOKI_ENTERPRISE_AUDIT` | `false` | Force audit on (legacy, audit is now on by default) |
47
+ | `LOKI_AUDIT_LEVEL` | `info` | Minimum log level: debug, info, warning, error |
48
+ | `LOKI_AUDIT_RETENTION` | `90` | Retention period in days |
49
+ | `LOKI_AUDIT_SYSLOG_HOST` | - | Syslog server hostname for forwarding |
50
+ | `LOKI_AUDIT_SYSLOG_PORT` | `514` | Syslog server port |
51
+ | `LOKI_AUDIT_SYSLOG_PROTO` | `udp` | Syslog protocol: `udp` or `tcp` |
52
+ | `LOKI_AUDIT_NO_INTEGRITY` | `false` | Disable SHA-256 chain hashing |
53
+
54
+ ## Logged Events
55
+
56
+ ### Session Events
57
+
58
+ | Event | Description |
59
+ |-------|-------------|
60
+ | `session.start` | Session started with PRD |
61
+ | `session.stop` | Session stopped (manual or automatic) |
62
+ | `session.pause` | Session paused |
63
+ | `session.resume` | Session resumed |
64
+ | `session.complete` | Session completed successfully |
65
+ | `session.fail` | Session failed with error |
66
+
67
+ ### API Events
68
+
69
+ | Event | Description |
70
+ |-------|-------------|
71
+ | `api.request` | API request received |
72
+ | `api.response` | API response sent |
73
+ | `api.error` | API error occurred |
74
+
75
+ ### Authentication Events
76
+
77
+ | Event | Description |
78
+ |-------|-------------|
79
+ | `auth.token.create` | Token created |
80
+ | `auth.token.use` | Token used for authentication |
81
+ | `auth.token.revoke` | Token revoked |
82
+ | `auth.fail` | Authentication failed |
83
+ | `auth.oidc.success` | OIDC authentication succeeded |
84
+ | `auth.oidc.fail` | OIDC authentication failed |
85
+
86
+ ### Task Events
87
+
88
+ | Event | Description |
89
+ |-------|-------------|
90
+ | `task.create` | Task created in queue |
91
+ | `task.start` | Task started by agent |
92
+ | `task.complete` | Task completed successfully |
93
+ | `task.fail` | Task failed with error |
94
+
95
+ ### Agent Events
96
+
97
+ | Event | Description |
98
+ |-------|-------------|
99
+ | `agent.spawn` | Agent spawned |
100
+ | `agent.action` | Agent performed action |
101
+ | `agent.complete` | Agent completed work |
102
+ | `agent.fail` | Agent encountered error |
103
+
104
+ ## Log Format
105
+
106
+ ### JSONL Format
107
+
108
+ Audit logs use JSON Lines format (one JSON object per line):
109
+
110
+ ```json
111
+ {
112
+ "timestamp": "2026-02-15T14:30:00.000Z",
113
+ "event": "session.start",
114
+ "level": "info",
115
+ "actor": "user",
116
+ "details": {
117
+ "prd": "./prd.md",
118
+ "provider": "claude",
119
+ "parallel": false
120
+ },
121
+ "metadata": {
122
+ "hostname": "dev-machine",
123
+ "pid": 12345,
124
+ "version": "5.42.2"
125
+ }
126
+ }
127
+ ```
128
+
129
+ ### Fields
130
+
131
+ | Field | Type | Description |
132
+ |-------|------|-------------|
133
+ | `timestamp` | ISO 8601 | Event timestamp in UTC |
134
+ | `event` | string | Event type (e.g., `session.start`) |
135
+ | `level` | string | Log level: debug, info, warning, error |
136
+ | `actor` | string | Who performed the action (user, token:name, agent:type) |
137
+ | `resource` | string | Resource affected (optional) |
138
+ | `details` | object | Event-specific details |
139
+ | `metadata` | object | System metadata (hostname, PID, version) |
140
+ | `chain_hash` | string | SHA-256 chain hash for integrity (v5.38.0) |
141
+
142
+ ## Log Location
143
+
144
+ ```bash
145
+ # Audit log directory
146
+ ~/.loki/dashboard/audit/
147
+
148
+ # Daily rotation
149
+ audit-2026-02-15.jsonl
150
+ audit-2026-02-14.jsonl
151
+ audit-2026-02-13.jsonl
152
+
153
+ # Compressed archives (after rotation)
154
+ audit-2026-02-12.jsonl.gz
155
+ audit-2026-02-11.jsonl.gz
156
+ ```
157
+
158
+ ## CLI Commands
159
+
160
+ ### View Summary
161
+
162
+ ```bash
163
+ loki enterprise audit summary
164
+ ```
165
+
166
+ Output:
167
+
168
+ ```
169
+ Audit Log Summary (Last 24 Hours)
170
+
171
+ Events by Type:
172
+ session.start: 5
173
+ session.complete: 4
174
+ session.fail: 1
175
+ api.request: 42
176
+ auth.token.use: 15
177
+
178
+ Events by Level:
179
+ info: 58
180
+ warning: 3
181
+ error: 1
182
+
183
+ Events by Actor:
184
+ user: 10
185
+ token:ci-bot: 35
186
+ agent:dev: 13
187
+ ```
188
+
189
+ ### Tail Recent Entries
190
+
191
+ ```bash
192
+ # Last 20 entries
193
+ loki enterprise audit tail
194
+
195
+ # Follow new entries in real-time
196
+ loki enterprise audit tail --follow
197
+
198
+ # Filter by event type
199
+ loki enterprise audit tail --event session.start
200
+
201
+ # Filter by level
202
+ loki enterprise audit tail --level error
203
+ ```
204
+
205
+ ### Search Logs
206
+
207
+ ```bash
208
+ # Search by event
209
+ loki enterprise audit search --event auth.fail
210
+
211
+ # Search by date range
212
+ loki enterprise audit search --from 2026-02-01 --to 2026-02-15
213
+
214
+ # Search by actor
215
+ loki enterprise audit search --actor ci-bot
216
+
217
+ # Combined filters
218
+ loki enterprise audit search --event task.fail --from 2026-02-15 --level error
219
+ ```
220
+
221
+ ### Export Logs
222
+
223
+ ```bash
224
+ # Export to file
225
+ loki enterprise audit export --output audit-export.json
226
+
227
+ # Export with filters
228
+ loki enterprise audit export --from 2026-01-01 --level error --output errors.json
229
+
230
+ # Export as CSV
231
+ loki enterprise audit export --format csv --output audit.csv
232
+ ```
233
+
234
+ ## API Endpoints
235
+
236
+ ### Get Audit Entries
237
+
238
+ ```bash
239
+ # Recent entries
240
+ curl "http://localhost:57374/api/audit?limit=50"
241
+
242
+ # With filters
243
+ curl "http://localhost:57374/api/audit?event=session.start&limit=100"
244
+
245
+ # Date range
246
+ curl "http://localhost:57374/api/audit?start=2026-02-01&end=2026-02-15"
247
+ ```
248
+
249
+ ### Query Parameters
250
+
251
+ | Parameter | Type | Description |
252
+ |-----------|------|-------------|
253
+ | `start` | ISO date | Start timestamp |
254
+ | `end` | ISO date | End timestamp |
255
+ | `event` | string | Filter by event type |
256
+ | `level` | string | Filter by level (debug, info, warning, error) |
257
+ | `actor` | string | Filter by actor |
258
+ | `limit` | number | Max results (default: 100) |
259
+ | `offset` | number | Pagination offset |
260
+
261
+ ### Get Summary
262
+
263
+ ```bash
264
+ curl http://localhost:57374/api/audit/summary
265
+ ```
266
+
267
+ Response:
268
+
269
+ ```json
270
+ {
271
+ "period": "24h",
272
+ "total_events": 62,
273
+ "by_type": {
274
+ "session.start": 5,
275
+ "session.complete": 4,
276
+ "api.request": 42
277
+ },
278
+ "by_level": {
279
+ "info": 58,
280
+ "warning": 3,
281
+ "error": 1
282
+ }
283
+ }
284
+ ```
285
+
286
+ ## Log Integrity (v5.38.0)
287
+
288
+ Audit entries are chain-hashed with SHA-256 for tamper detection.
289
+
290
+ ### How It Works
291
+
292
+ Each audit entry includes a `chain_hash` field:
293
+
294
+ 1. First entry hashes against a genesis hash (`0` * 64)
295
+ 2. Each subsequent entry hashes: `SHA256(previous_hash + current_entry_json)`
296
+ 3. Any modification to a past entry invalidates all subsequent hashes
297
+
298
+ ### Verification
299
+
300
+ ```bash
301
+ # Verify integrity via CLI
302
+ loki audit verify
303
+
304
+ # Python verification
305
+ from dashboard.audit import verify_log_integrity
306
+
307
+ result = verify_log_integrity("~/.loki/dashboard/audit/audit-2026-02-15.jsonl")
308
+ print(f"Valid: {result['valid']}")
309
+ print(f"Entries checked: {result['entries_checked']}")
310
+ if not result['valid']:
311
+ print(f"First tampered line: {result['first_tampered_line']}")
312
+ ```
313
+
314
+ ### Disabling Chain Hashing
315
+
316
+ ```bash
317
+ export LOKI_AUDIT_NO_INTEGRITY=true
318
+ ```
319
+
320
+ ## SIEM Integration (v5.38.0)
321
+
322
+ ### Syslog Forwarding
323
+
324
+ Forward audit events to external syslog servers for SIEM integration:
325
+
326
+ ```bash
327
+ export LOKI_AUDIT_SYSLOG_HOST=syslog.example.com
328
+ export LOKI_AUDIT_SYSLOG_PORT=514
329
+ export LOKI_AUDIT_SYSLOG_PROTO=udp
330
+ ```
331
+
332
+ Details:
333
+ - Uses Python stdlib `logging.handlers.SysLogHandler`
334
+ - Facility: `LOG_LOCAL0`
335
+ - Security actions forwarded at `WARNING` level
336
+ - Fire-and-forget: syslog failures do not block audit writes
337
+ - Supports both UDP and TCP protocols
338
+
339
+ ### Splunk
340
+
341
+ ```bash
342
+ # Configure Splunk Universal Forwarder
343
+ /opt/splunkforwarder/bin/splunk add monitor ~/.loki/dashboard/audit/ \
344
+ -sourcetype loki:audit \
345
+ -index security
346
+
347
+ # Or use HTTP Event Collector
348
+ curl -H "Authorization: Splunk YOUR-HEC-TOKEN" \
349
+ -d "$(cat ~/.loki/dashboard/audit/audit-2026-02-15.jsonl)" \
350
+ https://splunk.example.com:8088/services/collector/raw
351
+ ```
352
+
353
+ ### Datadog
354
+
355
+ ```yaml
356
+ # datadog.yaml
357
+ logs:
358
+ - type: file
359
+ path: /home/user/.loki/dashboard/audit/*.jsonl
360
+ source: loki-mode
361
+ service: loki-mode
362
+ tags:
363
+ - env:production
364
+ - team:devops
365
+ ```
366
+
367
+ ### Elastic SIEM
368
+
369
+ ```bash
370
+ # Filebeat configuration
371
+ cat > /etc/filebeat/inputs.d/loki-audit.yml <<EOF
372
+ - type: log
373
+ enabled: true
374
+ paths:
375
+ - /home/user/.loki/dashboard/audit/*.jsonl
376
+ json.keys_under_root: true
377
+ fields:
378
+ log_type: audit
379
+ application: loki-mode
380
+ tags: ["loki", "audit"]
381
+ EOF
382
+
383
+ # Restart Filebeat
384
+ systemctl restart filebeat
385
+ ```
386
+
387
+ ## Agent Action Audit (v5.38.0)
388
+
389
+ In addition to dashboard audit logs, agent actions are tracked separately.
390
+
391
+ ### Location
392
+
393
+ `.loki/logs/agent-audit.jsonl`
394
+
395
+ ### Tracked Actions
396
+
397
+ | Action | Description |
398
+ |--------|-------------|
399
+ | `cli_invoke` | CLI command executed by agent |
400
+ | `git_commit` | Git commit performed by agent |
401
+ | `file_write` | File write operation |
402
+ | `file_delete` | File delete operation |
403
+ | `session_start` | Agent session started |
404
+ | `session_stop` | Agent session stopped |
405
+
406
+ ### Entry Format
407
+
408
+ ```json
409
+ {
410
+ "timestamp": "2026-02-15T14:30:00Z",
411
+ "action": "git_commit",
412
+ "agent": "development",
413
+ "branch": "loki/session-20260215-143022-12345",
414
+ "details": {
415
+ "message": "Add authentication module",
416
+ "files_changed": 3,
417
+ "insertions": 150,
418
+ "deletions": 20
419
+ }
420
+ }
421
+ ```
422
+
423
+ ### CLI Commands
424
+
425
+ ```bash
426
+ # View recent agent actions
427
+ loki audit log
428
+
429
+ # Count total agent actions
430
+ loki audit count
431
+
432
+ # Filter by action type
433
+ loki audit log --action git_commit
434
+
435
+ # Show help
436
+ loki audit help
437
+ ```
438
+
439
+ ## Compliance
440
+
441
+ ### SOC2
442
+
443
+ Audit logging supports SOC2 requirements:
444
+
445
+ - **CC6.1** - Logical access security (auth events)
446
+ - **CC7.2** - System monitoring (session and task events)
447
+ - **CC7.3** - Incident response (error events)
448
+
449
+ Configuration:
450
+
451
+ ```yaml
452
+ enterprise:
453
+ audit:
454
+ enabled: true
455
+ retention_days: 365 # 1 year minimum for SOC2
456
+ integrity_check: true
457
+ syslog_enabled: true
458
+ ```
459
+
460
+ ### HIPAA
461
+
462
+ For healthcare applications:
463
+
464
+ - Enable all authentication events
465
+ - Set retention to minimum 6 years
466
+ - Enable log encryption
467
+ - Forward to SIEM for monitoring
468
+
469
+ Configuration:
470
+
471
+ ```yaml
472
+ enterprise:
473
+ audit:
474
+ enabled: true
475
+ retention_days: 2190 # 6 years
476
+ encrypt: true
477
+ integrity_check: true
478
+ syslog_enabled: true
479
+ ```
480
+
481
+ ### GDPR
482
+
483
+ For European deployments:
484
+
485
+ - Log access to personal data
486
+ - Provide data export capability
487
+ - Support right to deletion
488
+ - Enable audit trail for data access
489
+
490
+ Configuration:
491
+
492
+ ```yaml
493
+ enterprise:
494
+ audit:
495
+ enabled: true
496
+ retention_days: 365
497
+ gdpr_compliance: true
498
+ log_data_access: true
499
+ ```
500
+
501
+ ## Troubleshooting
502
+
503
+ ### Logs Not Being Created
504
+
505
+ ```bash
506
+ # Check if audit logging is enabled
507
+ loki enterprise status
508
+
509
+ # Verify directory exists and is writable
510
+ ls -la ~/.loki/dashboard/audit/
511
+ mkdir -p ~/.loki/dashboard/audit/
512
+ chmod 700 ~/.loki/dashboard/audit/
513
+
514
+ # Check disk space
515
+ df -h ~/.loki/
516
+
517
+ # Test log write
518
+ echo '{"test": "entry"}' >> ~/.loki/dashboard/audit/test.jsonl
519
+ ```
520
+
521
+ ### Missing Events
522
+
523
+ ```bash
524
+ # Check minimum level configuration
525
+ loki enterprise audit summary
526
+
527
+ # Lower level to capture more events
528
+ export LOKI_AUDIT_LEVEL=debug
529
+
530
+ # Check exclude_events in config
531
+ cat .loki/config.yaml | grep -A 5 exclude_events
532
+ ```
533
+
534
+ ### Disk Space Issues
535
+
536
+ ```bash
537
+ # Check current usage
538
+ du -sh ~/.loki/dashboard/audit/
539
+
540
+ # Find large log files
541
+ find ~/.loki/dashboard/audit/ -type f -size +100M
542
+
543
+ # Manually clean old logs
544
+ find ~/.loki/dashboard/audit/ -name "*.jsonl" -mtime +30 -delete
545
+
546
+ # Enable compression
547
+ export LOKI_AUDIT_COMPRESS=true
548
+ ```
549
+
550
+ ### Syslog Not Forwarding
551
+
552
+ ```bash
553
+ # Test syslog connectivity
554
+ nc -zv syslog.example.com 514
555
+
556
+ # Check syslog configuration
557
+ echo $LOKI_AUDIT_SYSLOG_HOST
558
+ echo $LOKI_AUDIT_SYSLOG_PORT
559
+
560
+ # View syslog errors in audit log
561
+ loki enterprise audit tail --event syslog.error
562
+
563
+ # Test manual syslog send
564
+ logger -n syslog.example.com -P 514 "Test from Loki Mode"
565
+ ```
566
+
567
+ ## Best Practices
568
+
569
+ ### Security
570
+
571
+ 1. Enable audit logging in production (enabled by default)
572
+ 2. Set appropriate retention period for compliance
573
+ 3. Enable integrity checking (SHA-256 chain hashing)
574
+ 4. Forward logs to external SIEM
575
+ 5. Restrict access to audit logs (file permissions 600)
576
+ 6. Encrypt audit logs at rest
577
+ 7. Monitor for suspicious patterns
578
+
579
+ ### Performance
580
+
581
+ 1. Use async logging to avoid blocking
582
+ 2. Rotate logs daily
583
+ 3. Compress rotated logs
584
+ 4. Set reasonable retention period
585
+ 5. Exclude high-volume low-value events (e.g., api.request)
586
+
587
+ ### Compliance
588
+
589
+ 1. Document audit logging configuration
590
+ 2. Test log integrity verification regularly
591
+ 3. Perform quarterly audit log reviews
592
+ 4. Export logs for long-term archival
593
+ 5. Integrate with compliance monitoring tools
594
+
595
+ ## See Also
596
+
597
+ - [Authentication Guide](authentication.md) - Token and OIDC setup
598
+ - [Authorization Guide](authorization.md) - RBAC permissions
599
+ - [Enterprise Features](../wiki/Enterprise-Features.md) - Complete enterprise guide
600
+ - [Network Security](network-security.md) - Security controls