mirror of
https://github.com/rcourtman/Pulse.git
synced 2026-11-28 16:58:31 +01:00
Align Audit Logging and Audit API Help with runtime
Document all nine additional live emitted audit event types (config_exported, config_imported, config_auto_import, node_added, node_updated, node_deleted, websocket_multitenant_access_denied, websocket_org_access_denied, and audit_cleanup), SQLite 90-day default retention and 24-hour cleanup cadence, audit export format/verification and CSV formula-neutralisation bounds, and HTTP 400/404/501/503 store contention and unavailability responses across docs/AUDIT_LOGGING.md, docs/API.md, their shipped mirrors, and source-bound doc tests. Contract-Neutral: Documentation and documentation-test alignment with existing audit runtime behaviour; no runtime, API, schema, or UI contract changes. Change-source: pulse-maintainer
This commit is contained in:
23
docs/API.md
23
docs/API.md
@@ -1490,11 +1490,13 @@ Returns the new raw token (shown once) and updates stored hashes:
|
||||
|
||||
## 🧾 Audit Log (Pro)
|
||||
|
||||
These endpoints require admin access and the `audit:read` scope. On Community (no `audit_logging` license), these endpoints return HTTP 402 Payment Required with `error: "license_required"` and `feature: "audit_logging"` before any events are read.
|
||||
These endpoints require admin access, audit-log read permission, and the `audit:read` scope. On Community (no `audit_logging` license), these endpoints return HTTP 402 Payment Required with `error: "license_required"` and `feature: "audit_logging"` before any events are read.
|
||||
|
||||
### List Audit Events
|
||||
`GET /api/audit?limit=100&event=login&user=admin&success=true&startTime=2024-01-01T00:00:00Z&endTime=2024-01-31T23:59:59Z`
|
||||
|
||||
Query parameters: `limit` (positive integer, default `100`, capped at `1000`), `offset` (non-negative integer, default `0`), `event`, `user`, `success` (`true` or `false`), and RFC3339 `startTime`/`endTime` (`startTime` must be strictly before `endTime`). Malformed query encoding returns HTTP 400 (`invalid_query`), and repeating any query parameter returns HTTP 400 (`ambiguous_query`). When SQLite storage is busy after internal retries, this endpoint returns HTTP 503 (`audit_store_busy`) with `Retry-After: 2`. When persistent audit storage is unavailable, it returns HTTP 503 (`audit_store_unavailable`).
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
@@ -1519,6 +1521,8 @@ Response:
|
||||
### Verify Audit Event Signature
|
||||
`GET /api/audit/<id>/verify`
|
||||
|
||||
Event IDs must match `[a-zA-Z0-9_-]` and be at most 64 characters (otherwise HTTP 400 `invalid_id`). Returns HTTP 404 (`not_found`) when the event ID does not exist, HTTP 200 with `"available": false` if persistent audit storage is not active, and HTTP 503 (`audit_store_busy` with `Retry-After: 2` or `audit_store_unavailable`) on storage contention or failure.
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
@@ -1528,6 +1532,23 @@ Response:
|
||||
}
|
||||
```
|
||||
|
||||
### Export Audit Events
|
||||
`GET /api/audit/export?format=json&verify=true&event=login&startTime=2024-01-01T00:00:00Z&endTime=2024-01-31T23:59:59Z`
|
||||
|
||||
Accepts `event`, `user`, `success`, `startTime`, `endTime`, `format` (`json` default or `csv`), and `verify=true`. Ignores list pagination (`limit`/`offset`). Rejects malformed query encoding (`invalid_query`), repeated query parameters (`ambiguous_query`), invalid filters, or selections above `10000` events (`400 export_too_large`). Returns `Content-Disposition: attachment; filename=audit-log-<timestamp>.<ext>` and `X-Event-Count`. JSON is lossless, while CSV prefixes text fields starting with leading spreadsheet formula or control characters with `'`. Returns HTTP 501 (`export_unavailable`) when persistent audit storage is unavailable.
|
||||
|
||||
### Audit Summary
|
||||
`GET /api/audit/summary?verify=true&event=login&startTime=2024-01-01T00:00:00Z&endTime=2024-01-31T23:59:59Z`
|
||||
|
||||
Accepts `event`, `user`, `startTime`, `endTime`, and `verify=true` (adds `invalid_signature_count` for signed events whose signature fails verification). Ignores `success` and list pagination, enforces the same `10000`-event cap (`400 export_too_large`), and returns HTTP 501 (`summary_unavailable`) when persistent audit storage is unavailable.
|
||||
|
||||
### Unified Resource Audit History
|
||||
- `GET /api/audit/actions` (optional `resourceId`, `since`/`startTime` RFC3339, `limit` default `100`, cap `1000`): lists canonical unified-resource action audits.
|
||||
- `GET /api/audit/actions/{id}/events` (`id` matching `[a-zA-Z0-9_-]`, max 64 chars, optional `since`/`startTime`, `limit` default `100`, cap `1000`): lists lifecycle events for one action.
|
||||
- `GET /api/audit/exports` (optional `since`/`startTime`, `limit` default `100`, cap `1000`): lists unified-resource export audit records.
|
||||
|
||||
These routes return HTTP 503 (`audit_unavailable`) when the unified resource audit store is unavailable. See [Audit Logging](AUDIT_LOGGING.md) for safe querying, storage paths, and signature recovery.
|
||||
|
||||
### Bootstrap Token Validation (Public)
|
||||
`POST /api/security/validate-bootstrap-token`
|
||||
|
||||
|
||||
@@ -67,6 +67,15 @@ Pulse automatically captures the following events:
|
||||
| `user_deprovisioned` | User removed and active sessions revoked | Removed user jane and revoked active sessions |
|
||||
| `user_deprovision_failed` | Sessions revoked but user removal failed | Revoked sessions but failed to remove user jane |
|
||||
| `user_deprovision_self_denied` | Blocked attempt to deprovision own identity | Attempted to deprovision own identity |
|
||||
| `config_exported` | Configuration backup export attempts | Configuration exported |
|
||||
| `config_imported` | Configuration backup imports, including tenant-limit refusals and reload failures | Configuration imported |
|
||||
| `config_auto_import` | Startup auto-import attempts from `PULSE_INIT_CONFIG_*` (global, not tenant-scoped) | `source=file` |
|
||||
| `node_added` | Monitoring connection created | Added PVE node `pve1` |
|
||||
| `node_updated` | Monitoring connection modified | Updated PVE node `pve1` |
|
||||
| `node_deleted` | Monitoring connection removed | Deleted PVE node `pve1` |
|
||||
| `websocket_multitenant_access_denied` | Blocked WebSocket connection for a disabled or unlicensed non-default organisation (global, not tenant-scoped) | `org_id=team-a reason=unlicensed` |
|
||||
| `websocket_org_access_denied` | Blocked WebSocket connection for an unauthorised organisation (global, not tenant-scoped) | `org_id=team-a` |
|
||||
| `audit_cleanup` | Retention cleanup recorded by `system` when expired audit rows are deleted | Deleted 42 events older than 90 days |
|
||||
| `agent_config_fetch` | Every failed agent configuration fetch. A successful fetch is normally recorded on the agent's first delivery after Pulse starts, when its token or delivered configuration changes, and otherwise once a day; unchanged minute polls are suppressed while the agent is remembered (see below) | `agent_id=… token_id=… config=sha256:… reason=config_changed` |
|
||||
|
||||
Config-fetch suppression remembers up to 4,096 organisation/agent pairs per
|
||||
@@ -156,12 +165,19 @@ rather than looping, resetting the store or changing a licence to make it pass.
|
||||
| `endTime` | RFC3339 | End of date range, strictly after `startTime` |
|
||||
|
||||
These parameters describe **the event list**, not every audit endpoint. Its
|
||||
response contains an `events` page and `total` matching events; fewer rows than
|
||||
response contains an `events` page and `total` matching events. Fewer rows than
|
||||
`total` do not establish missing history. Keep the same filters when reading
|
||||
another page. New events can shift offsets; a sequence of pages is not a
|
||||
consistent archival snapshot. Malformed list filters return HTTP 400, not an
|
||||
empty result. URL-encode query values; do not put private usernames or other
|
||||
identifiers into a shared command or report.
|
||||
another page. New events can shift offsets, so a sequence of pages is not a
|
||||
consistent archival snapshot. Malformed query encoding returns HTTP 400
|
||||
(`invalid_query`), duplicate query parameters (`event`, `user`, `startTime`,
|
||||
`endTime`, `success`, `limit`, `offset`, `format`, `verify`) return HTTP 400
|
||||
(`ambiguous_query`), and malformed list filters return HTTP 400 rather than an
|
||||
empty result. When SQLite storage stays locked after internal retries (25 ms
|
||||
and 75 ms), `GET /api/audit` returns HTTP 503 (`audit_store_busy`) with
|
||||
`Retry-After: 2`. When persistent audit storage is unavailable or unreadable,
|
||||
`GET /api/audit` returns HTTP 503 (`audit_store_unavailable`). URL-encode query
|
||||
values and do not put private usernames or other identifiers into a shared
|
||||
command or report.
|
||||
|
||||
---
|
||||
|
||||
@@ -177,18 +193,34 @@ pulse_api GET '/api/audit/export?event=login&startTime=2026-01-01T00:00:00Z&endT
|
||||
|
||||
The new owner-only response file is created in the helper's private directory.
|
||||
It does not reuse filters selected in the UI. Export accepts `event`, `user`,
|
||||
`success`, `startTime` and `endTime`, but **not list pagination**: adding `limit`
|
||||
or `offset` does not bound an export. With no filters it requests the full
|
||||
`success`, `startTime`, `endTime`, `format` (`json` by default, or `csv`), and
|
||||
`verify=true`, but **not list pagination**: adding `limit`
|
||||
or `offset` does not bound an export. The response includes the `X-Event-Count`
|
||||
header and downloads as `audit-log-<timestamp>.json` or
|
||||
`audit-log-<timestamp>.csv`. JSON is the lossless evidence export. CSV is a
|
||||
spreadsheet projection that prefixes text fields starting with leading formula
|
||||
or control characters (`=`, `+`, `-`, `@`, their full-width equivalents, tab,
|
||||
carriage return, or newline) with a single leading `'` so spreadsheet
|
||||
applications treat them as literal text. When `verify=true` is supplied, Pulse
|
||||
verifies each signed event against its original stored bytes before rendering
|
||||
and includes `signature_valid` in JSON or the `Signature Valid` column in CSV.
|
||||
With no filters it requests the full
|
||||
available history, subject to the selection limit below. List, export and summary
|
||||
reject malformed or empty supplied `startTime`/`endTime` values and ranges whose
|
||||
end is not after their start with HTTP 400, before reading events. List and
|
||||
reject malformed or empty supplied `startTime`/`endTime` values, ranges whose
|
||||
end is not after their start, malformed query encoding (`invalid_query`), and
|
||||
repeated query parameters (`ambiguous_query`) with HTTP 400, before reading events. List and
|
||||
export also reject a supplied `success`
|
||||
other than exactly `true` or `false`, including an empty value. Omit a filter to
|
||||
leave it unset; HTTP 200 alone does not establish complete archival coverage.
|
||||
leave it unset. HTTP 200 alone does not establish complete archival coverage.
|
||||
|
||||
Summary accepts `event`, `user`, `startTime` and `endTime`, not `success` or list
|
||||
pagination. These unsupported parameters do not narrow a summary; omit them
|
||||
rather than relying on them to bound the read.
|
||||
Summary accepts `event`, `user`, `startTime`, `endTime`, and `verify=true`,
|
||||
not `success` or list pagination. Passing `verify=true` counts signed events
|
||||
whose verification fails in `invalid_signature_count` (unsigned events are not
|
||||
counted as invalid signatures). Unsupported parameters do not narrow a summary,
|
||||
so omit them rather than relying on them to bound the read. When no persistent
|
||||
audit store is active, `GET /api/audit/export` returns HTTP 501
|
||||
(`export_unavailable`) and `GET /api/audit/summary` returns HTTP 501
|
||||
(`summary_unavailable`).
|
||||
|
||||
Exports and summaries accept at most **10,000 matching events**. A larger
|
||||
selection returns HTTP 400 with code `export_too_large`, not a partial download
|
||||
@@ -228,7 +260,11 @@ shape (HTTP 200 alone is not signature verification):
|
||||
`verified: true` means the signature matches the verifier's key and supported
|
||||
signature format. It does not prove that the history is complete or that no
|
||||
events were deleted. `verified: false` means the check failed, not that Pulse
|
||||
has established why it failed. Keep that result as evidence.
|
||||
has established why it failed. Keep that result as evidence. The verification
|
||||
endpoint rejects IDs longer than 64 characters or outside `[a-zA-Z0-9_-]` with
|
||||
HTTP 400 (`invalid_id`), returns HTTP 404 (`not_found`) when no stored event
|
||||
matches that ID, and returns HTTP 503 (`audit_store_busy` with `Retry-After: 2`
|
||||
or `audit_store_unavailable`) if the SQLite store is locked or unavailable.
|
||||
|
||||
### Verification failures and safe recovery
|
||||
|
||||
@@ -276,7 +312,7 @@ new key or successful check on a different event authenticated that history.
|
||||
In multi-tenant deployments, most events are scoped to the active organization:
|
||||
|
||||
- Tenant-aware events (logins, role changes, config updates) are stored per-organization.
|
||||
- Some auth lifecycle events (e.g., `oidc_token_refresh`) are global and not tenant-scoped.
|
||||
- Global events (`oidc_token_refresh`, `config_auto_import`, `websocket_multitenant_access_denied`, and `websocket_org_access_denied`) are written to the global audit logger rather than a tenant-specific database.
|
||||
- Switching organizations shows only that organization's tenant-scoped events.
|
||||
- The tenant context is determined by `X-Pulse-Org-ID` header or session cookie.
|
||||
|
||||
@@ -293,14 +329,17 @@ See [Multi-Tenant Organizations](MULTI_TENANT.md) for details.
|
||||
| Query/filter API | License-gated (402) | Full access |
|
||||
| Signature verification | License-gated (402) | Available |
|
||||
| Export | License-gated (402) | Available |
|
||||
| `persistentLogging` API flag | `false` | `true` |
|
||||
| `persistentLogging` in `GET /api/audit` | License-gated (402) | `true` when persistent storage is active (otherwise HTTP 503 `audit_store_unavailable`) |
|
||||
|
||||
Pulse attempts SQLite-backed capture on all plans; failure to initialise the
|
||||
Pulse attempts SQLite-backed capture on all plans. Failure to initialise the
|
||||
store can leave console-only logging. The query, verify and export endpoints
|
||||
also require the `audit_logging` capability and a compatible runtime. A
|
||||
licence/runtime gate is not proof that events were never captured. For an
|
||||
authorised query, `persistentLogging` describes the active logger, not a count
|
||||
of historical events or proof that their signatures are valid.
|
||||
authorised `GET /api/audit` query, `persistentLogging` is `true` when the
|
||||
persistent SQLite logger is active, and the endpoint returns HTTP 503
|
||||
(`audit_store_unavailable`) rather than an empty list when persistent storage
|
||||
is unavailable. That flag does not establish a count of historical events or
|
||||
proof that their signatures are valid.
|
||||
|
||||
---
|
||||
|
||||
@@ -317,6 +356,15 @@ directory for a non-default organisation). Keep both with the corresponding
|
||||
history. A runtime may supply a different audit directory or managed signing
|
||||
key; use that deployment's actual configuration rather than guessing a path.
|
||||
|
||||
### Retention and cleanup
|
||||
|
||||
Persistent SQLite audit stores retain events for **90 days** by default (or
|
||||
indefinitely when retention is explicitly configured to `0` days). When
|
||||
retention is enabled, cleanup runs **5 minutes after startup** and every
|
||||
**24 hours** thereafter. Whenever expired rows are deleted, Pulse records a
|
||||
signed `audit_cleanup` event as `system` in the same transaction and reclaims
|
||||
free SQLite pages incrementally with a WAL checkpoint.
|
||||
|
||||
Data directory locations:
|
||||
- systemd: `/etc/pulse/`
|
||||
- Docker/Kubernetes: `/data/`
|
||||
|
||||
@@ -1490,11 +1490,13 @@ Returns the new raw token (shown once) and updates stored hashes:
|
||||
|
||||
## 🧾 Audit Log (Pro)
|
||||
|
||||
These endpoints require admin access and the `audit:read` scope. On Community (no `audit_logging` license), these endpoints return HTTP 402 Payment Required with `error: "license_required"` and `feature: "audit_logging"` before any events are read.
|
||||
These endpoints require admin access, audit-log read permission, and the `audit:read` scope. On Community (no `audit_logging` license), these endpoints return HTTP 402 Payment Required with `error: "license_required"` and `feature: "audit_logging"` before any events are read.
|
||||
|
||||
### List Audit Events
|
||||
`GET /api/audit?limit=100&event=login&user=admin&success=true&startTime=2024-01-01T00:00:00Z&endTime=2024-01-31T23:59:59Z`
|
||||
|
||||
Query parameters: `limit` (positive integer, default `100`, capped at `1000`), `offset` (non-negative integer, default `0`), `event`, `user`, `success` (`true` or `false`), and RFC3339 `startTime`/`endTime` (`startTime` must be strictly before `endTime`). Malformed query encoding returns HTTP 400 (`invalid_query`), and repeating any query parameter returns HTTP 400 (`ambiguous_query`). When SQLite storage is busy after internal retries, this endpoint returns HTTP 503 (`audit_store_busy`) with `Retry-After: 2`. When persistent audit storage is unavailable, it returns HTTP 503 (`audit_store_unavailable`).
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
@@ -1519,6 +1521,8 @@ Response:
|
||||
### Verify Audit Event Signature
|
||||
`GET /api/audit/<id>/verify`
|
||||
|
||||
Event IDs must match `[a-zA-Z0-9_-]` and be at most 64 characters (otherwise HTTP 400 `invalid_id`). Returns HTTP 404 (`not_found`) when the event ID does not exist, HTTP 200 with `"available": false` if persistent audit storage is not active, and HTTP 503 (`audit_store_busy` with `Retry-After: 2` or `audit_store_unavailable`) on storage contention or failure.
|
||||
|
||||
Response:
|
||||
```json
|
||||
{
|
||||
@@ -1528,6 +1532,23 @@ Response:
|
||||
}
|
||||
```
|
||||
|
||||
### Export Audit Events
|
||||
`GET /api/audit/export?format=json&verify=true&event=login&startTime=2024-01-01T00:00:00Z&endTime=2024-01-31T23:59:59Z`
|
||||
|
||||
Accepts `event`, `user`, `success`, `startTime`, `endTime`, `format` (`json` default or `csv`), and `verify=true`. Ignores list pagination (`limit`/`offset`). Rejects malformed query encoding (`invalid_query`), repeated query parameters (`ambiguous_query`), invalid filters, or selections above `10000` events (`400 export_too_large`). Returns `Content-Disposition: attachment; filename=audit-log-<timestamp>.<ext>` and `X-Event-Count`. JSON is lossless, while CSV prefixes text fields starting with leading spreadsheet formula or control characters with `'`. Returns HTTP 501 (`export_unavailable`) when persistent audit storage is unavailable.
|
||||
|
||||
### Audit Summary
|
||||
`GET /api/audit/summary?verify=true&event=login&startTime=2024-01-01T00:00:00Z&endTime=2024-01-31T23:59:59Z`
|
||||
|
||||
Accepts `event`, `user`, `startTime`, `endTime`, and `verify=true` (adds `invalid_signature_count` for signed events whose signature fails verification). Ignores `success` and list pagination, enforces the same `10000`-event cap (`400 export_too_large`), and returns HTTP 501 (`summary_unavailable`) when persistent audit storage is unavailable.
|
||||
|
||||
### Unified Resource Audit History
|
||||
- `GET /api/audit/actions` (optional `resourceId`, `since`/`startTime` RFC3339, `limit` default `100`, cap `1000`): lists canonical unified-resource action audits.
|
||||
- `GET /api/audit/actions/{id}/events` (`id` matching `[a-zA-Z0-9_-]`, max 64 chars, optional `since`/`startTime`, `limit` default `100`, cap `1000`): lists lifecycle events for one action.
|
||||
- `GET /api/audit/exports` (optional `since`/`startTime`, `limit` default `100`, cap `1000`): lists unified-resource export audit records.
|
||||
|
||||
These routes return HTTP 503 (`audit_unavailable`) when the unified resource audit store is unavailable. See [Audit Logging](AUDIT_LOGGING.md) for safe querying, storage paths, and signature recovery.
|
||||
|
||||
### Bootstrap Token Validation (Public)
|
||||
`POST /api/security/validate-bootstrap-token`
|
||||
|
||||
|
||||
@@ -67,6 +67,15 @@ Pulse automatically captures the following events:
|
||||
| `user_deprovisioned` | User removed and active sessions revoked | Removed user jane and revoked active sessions |
|
||||
| `user_deprovision_failed` | Sessions revoked but user removal failed | Revoked sessions but failed to remove user jane |
|
||||
| `user_deprovision_self_denied` | Blocked attempt to deprovision own identity | Attempted to deprovision own identity |
|
||||
| `config_exported` | Configuration backup export attempts | Configuration exported |
|
||||
| `config_imported` | Configuration backup imports, including tenant-limit refusals and reload failures | Configuration imported |
|
||||
| `config_auto_import` | Startup auto-import attempts from `PULSE_INIT_CONFIG_*` (global, not tenant-scoped) | `source=file` |
|
||||
| `node_added` | Monitoring connection created | Added PVE node `pve1` |
|
||||
| `node_updated` | Monitoring connection modified | Updated PVE node `pve1` |
|
||||
| `node_deleted` | Monitoring connection removed | Deleted PVE node `pve1` |
|
||||
| `websocket_multitenant_access_denied` | Blocked WebSocket connection for a disabled or unlicensed non-default organisation (global, not tenant-scoped) | `org_id=team-a reason=unlicensed` |
|
||||
| `websocket_org_access_denied` | Blocked WebSocket connection for an unauthorised organisation (global, not tenant-scoped) | `org_id=team-a` |
|
||||
| `audit_cleanup` | Retention cleanup recorded by `system` when expired audit rows are deleted | Deleted 42 events older than 90 days |
|
||||
| `agent_config_fetch` | Every failed agent configuration fetch. A successful fetch is normally recorded on the agent's first delivery after Pulse starts, when its token or delivered configuration changes, and otherwise once a day; unchanged minute polls are suppressed while the agent is remembered (see below) | `agent_id=… token_id=… config=sha256:… reason=config_changed` |
|
||||
|
||||
Config-fetch suppression remembers up to 4,096 organisation/agent pairs per
|
||||
@@ -156,12 +165,19 @@ rather than looping, resetting the store or changing a licence to make it pass.
|
||||
| `endTime` | RFC3339 | End of date range, strictly after `startTime` |
|
||||
|
||||
These parameters describe **the event list**, not every audit endpoint. Its
|
||||
response contains an `events` page and `total` matching events; fewer rows than
|
||||
response contains an `events` page and `total` matching events. Fewer rows than
|
||||
`total` do not establish missing history. Keep the same filters when reading
|
||||
another page. New events can shift offsets; a sequence of pages is not a
|
||||
consistent archival snapshot. Malformed list filters return HTTP 400, not an
|
||||
empty result. URL-encode query values; do not put private usernames or other
|
||||
identifiers into a shared command or report.
|
||||
another page. New events can shift offsets, so a sequence of pages is not a
|
||||
consistent archival snapshot. Malformed query encoding returns HTTP 400
|
||||
(`invalid_query`), duplicate query parameters (`event`, `user`, `startTime`,
|
||||
`endTime`, `success`, `limit`, `offset`, `format`, `verify`) return HTTP 400
|
||||
(`ambiguous_query`), and malformed list filters return HTTP 400 rather than an
|
||||
empty result. When SQLite storage stays locked after internal retries (25 ms
|
||||
and 75 ms), `GET /api/audit` returns HTTP 503 (`audit_store_busy`) with
|
||||
`Retry-After: 2`. When persistent audit storage is unavailable or unreadable,
|
||||
`GET /api/audit` returns HTTP 503 (`audit_store_unavailable`). URL-encode query
|
||||
values and do not put private usernames or other identifiers into a shared
|
||||
command or report.
|
||||
|
||||
---
|
||||
|
||||
@@ -177,18 +193,34 @@ pulse_api GET '/api/audit/export?event=login&startTime=2026-01-01T00:00:00Z&endT
|
||||
|
||||
The new owner-only response file is created in the helper's private directory.
|
||||
It does not reuse filters selected in the UI. Export accepts `event`, `user`,
|
||||
`success`, `startTime` and `endTime`, but **not list pagination**: adding `limit`
|
||||
or `offset` does not bound an export. With no filters it requests the full
|
||||
`success`, `startTime`, `endTime`, `format` (`json` by default, or `csv`), and
|
||||
`verify=true`, but **not list pagination**: adding `limit`
|
||||
or `offset` does not bound an export. The response includes the `X-Event-Count`
|
||||
header and downloads as `audit-log-<timestamp>.json` or
|
||||
`audit-log-<timestamp>.csv`. JSON is the lossless evidence export. CSV is a
|
||||
spreadsheet projection that prefixes text fields starting with leading formula
|
||||
or control characters (`=`, `+`, `-`, `@`, their full-width equivalents, tab,
|
||||
carriage return, or newline) with a single leading `'` so spreadsheet
|
||||
applications treat them as literal text. When `verify=true` is supplied, Pulse
|
||||
verifies each signed event against its original stored bytes before rendering
|
||||
and includes `signature_valid` in JSON or the `Signature Valid` column in CSV.
|
||||
With no filters it requests the full
|
||||
available history, subject to the selection limit below. List, export and summary
|
||||
reject malformed or empty supplied `startTime`/`endTime` values and ranges whose
|
||||
end is not after their start with HTTP 400, before reading events. List and
|
||||
reject malformed or empty supplied `startTime`/`endTime` values, ranges whose
|
||||
end is not after their start, malformed query encoding (`invalid_query`), and
|
||||
repeated query parameters (`ambiguous_query`) with HTTP 400, before reading events. List and
|
||||
export also reject a supplied `success`
|
||||
other than exactly `true` or `false`, including an empty value. Omit a filter to
|
||||
leave it unset; HTTP 200 alone does not establish complete archival coverage.
|
||||
leave it unset. HTTP 200 alone does not establish complete archival coverage.
|
||||
|
||||
Summary accepts `event`, `user`, `startTime` and `endTime`, not `success` or list
|
||||
pagination. These unsupported parameters do not narrow a summary; omit them
|
||||
rather than relying on them to bound the read.
|
||||
Summary accepts `event`, `user`, `startTime`, `endTime`, and `verify=true`,
|
||||
not `success` or list pagination. Passing `verify=true` counts signed events
|
||||
whose verification fails in `invalid_signature_count` (unsigned events are not
|
||||
counted as invalid signatures). Unsupported parameters do not narrow a summary,
|
||||
so omit them rather than relying on them to bound the read. When no persistent
|
||||
audit store is active, `GET /api/audit/export` returns HTTP 501
|
||||
(`export_unavailable`) and `GET /api/audit/summary` returns HTTP 501
|
||||
(`summary_unavailable`).
|
||||
|
||||
Exports and summaries accept at most **10,000 matching events**. A larger
|
||||
selection returns HTTP 400 with code `export_too_large`, not a partial download
|
||||
@@ -228,7 +260,11 @@ shape (HTTP 200 alone is not signature verification):
|
||||
`verified: true` means the signature matches the verifier's key and supported
|
||||
signature format. It does not prove that the history is complete or that no
|
||||
events were deleted. `verified: false` means the check failed, not that Pulse
|
||||
has established why it failed. Keep that result as evidence.
|
||||
has established why it failed. Keep that result as evidence. The verification
|
||||
endpoint rejects IDs longer than 64 characters or outside `[a-zA-Z0-9_-]` with
|
||||
HTTP 400 (`invalid_id`), returns HTTP 404 (`not_found`) when no stored event
|
||||
matches that ID, and returns HTTP 503 (`audit_store_busy` with `Retry-After: 2`
|
||||
or `audit_store_unavailable`) if the SQLite store is locked or unavailable.
|
||||
|
||||
### Verification failures and safe recovery
|
||||
|
||||
@@ -276,7 +312,7 @@ new key or successful check on a different event authenticated that history.
|
||||
In multi-tenant deployments, most events are scoped to the active organization:
|
||||
|
||||
- Tenant-aware events (logins, role changes, config updates) are stored per-organization.
|
||||
- Some auth lifecycle events (e.g., `oidc_token_refresh`) are global and not tenant-scoped.
|
||||
- Global events (`oidc_token_refresh`, `config_auto_import`, `websocket_multitenant_access_denied`, and `websocket_org_access_denied`) are written to the global audit logger rather than a tenant-specific database.
|
||||
- Switching organizations shows only that organization's tenant-scoped events.
|
||||
- The tenant context is determined by `X-Pulse-Org-ID` header or session cookie.
|
||||
|
||||
@@ -293,14 +329,17 @@ See [Multi-Tenant Organizations](MULTI_TENANT.md) for details.
|
||||
| Query/filter API | License-gated (402) | Full access |
|
||||
| Signature verification | License-gated (402) | Available |
|
||||
| Export | License-gated (402) | Available |
|
||||
| `persistentLogging` API flag | `false` | `true` |
|
||||
| `persistentLogging` in `GET /api/audit` | License-gated (402) | `true` when persistent storage is active (otherwise HTTP 503 `audit_store_unavailable`) |
|
||||
|
||||
Pulse attempts SQLite-backed capture on all plans; failure to initialise the
|
||||
Pulse attempts SQLite-backed capture on all plans. Failure to initialise the
|
||||
store can leave console-only logging. The query, verify and export endpoints
|
||||
also require the `audit_logging` capability and a compatible runtime. A
|
||||
licence/runtime gate is not proof that events were never captured. For an
|
||||
authorised query, `persistentLogging` describes the active logger, not a count
|
||||
of historical events or proof that their signatures are valid.
|
||||
authorised `GET /api/audit` query, `persistentLogging` is `true` when the
|
||||
persistent SQLite logger is active, and the endpoint returns HTTP 503
|
||||
(`audit_store_unavailable`) rather than an empty list when persistent storage
|
||||
is unavailable. That flag does not establish a count of historical events or
|
||||
proof that their signatures are valid.
|
||||
|
||||
---
|
||||
|
||||
@@ -317,6 +356,15 @@ directory for a non-default organisation). Keep both with the corresponding
|
||||
history. A runtime may supply a different audit directory or managed signing
|
||||
key; use that deployment's actual configuration rather than guessing a path.
|
||||
|
||||
### Retention and cleanup
|
||||
|
||||
Persistent SQLite audit stores retain events for **90 days** by default (or
|
||||
indefinitely when retention is explicitly configured to `0` days). When
|
||||
retention is enabled, cleanup runs **5 minutes after startup** and every
|
||||
**24 hours** thereafter. Whenever expired rows are deleted, Pulse records a
|
||||
signed `audit_cleanup` event as `system` in the same transaction and reclaims
|
||||
free SQLite pages incrementally with a WAL checkpoint.
|
||||
|
||||
Data directory locations:
|
||||
- systemd: `/etc/pulse/`
|
||||
- Docker/Kubernetes: `/data/`
|
||||
|
||||
@@ -113,19 +113,100 @@ class AuditRecoveryDocsTest(unittest.TestCase):
|
||||
def test_what_gets_logged_covers_live_api_audit_event_types(self):
|
||||
guide = (ROOT / "docs/AUDIT_LOGGING.md").read_text(encoding="utf-8")
|
||||
logged = set()
|
||||
for path in sorted((ROOT / "internal/api").glob("*.go")):
|
||||
if path.name.endswith("_test.go"):
|
||||
continue
|
||||
source = path.read_text(encoding="utf-8")
|
||||
for pattern in (
|
||||
r'LogAuditEventForTenant\s*\([^,\n]+,\s*"([a-z0-9_]+)"',
|
||||
r'LogAuditEvent\s*\(\s*"([a-z0-9_]+)"',
|
||||
r'auditTokenEvent\s*\([^,\n]+,\s*"([a-z0-9_]+)"',
|
||||
):
|
||||
logged.update(re.findall(pattern, source))
|
||||
self.assertGreaterEqual(len(logged), 40, "expected to discover live API audit event literals")
|
||||
scan_globs = (
|
||||
(ROOT / "internal/api").glob("*.go"),
|
||||
(ROOT / "internal/api/configapi").glob("*.go"),
|
||||
(ROOT / "internal/websocket").glob("*.go"),
|
||||
(ROOT / "pkg/server").glob("*.go"),
|
||||
(ROOT / "pkg/audit").glob("sqlite_logger.go"),
|
||||
)
|
||||
for paths in scan_globs:
|
||||
for path in sorted(paths):
|
||||
if path.name.endswith("_test.go"):
|
||||
continue
|
||||
source = path.read_text(encoding="utf-8")
|
||||
for pattern in (
|
||||
r'LogAuditEventForTenant\s*\([^,\n]+,\s*"([a-z0-9_]+)"',
|
||||
r'LogAuditEvent\s*\(\s*"([a-z0-9_]+)"',
|
||||
r'auditTokenEvent\s*\([^,\n]+,\s*"([a-z0-9_]+)"',
|
||||
r'\.AuditEvent\s*\([^,\n]+,\s*"([a-z0-9_]+)"',
|
||||
r'audit\.Log\s*\(\s*"([a-z0-9_]+)"',
|
||||
r'EventType:\s*"([a-z0-9_]+)"',
|
||||
):
|
||||
logged.update(re.findall(pattern, source))
|
||||
self.assertGreaterEqual(len(logged), 50, "expected to discover live audit event literals")
|
||||
missing = sorted(event for event in logged if f"`{event}`" not in guide)
|
||||
self.assertEqual(missing, [], f"AUDIT_LOGGING.md is missing live API audit events: {missing}")
|
||||
self.assertEqual(missing, [], f"AUDIT_LOGGING.md is missing live audit events: {missing}")
|
||||
|
||||
def test_audit_export_summary_retention_and_error_bounds_match_runtime(self):
|
||||
guide = read_guide("AUDIT_LOGGING")
|
||||
api_doc = read_guide("API")
|
||||
handlers = (ROOT / "internal/api/activity_audit_handlers.go").read_text(encoding="utf-8")
|
||||
exporter = (ROOT / "pkg/audit/export.go").read_text(encoding="utf-8")
|
||||
logger = (ROOT / "pkg/audit/sqlite_logger.go").read_text(encoding="utf-8")
|
||||
|
||||
for source, token in (
|
||||
(handlers, "auditStoreBusyRetryAfterSeconds = 2"),
|
||||
(handlers, '"ambiguous_query"'),
|
||||
(handlers, '"invalid_query"'),
|
||||
(handlers, '"audit_store_busy"'),
|
||||
(handlers, '"audit_store_unavailable"'),
|
||||
(handlers, '"export_unavailable"'),
|
||||
(handlers, '"summary_unavailable"'),
|
||||
(handlers, '"invalid_id"'),
|
||||
(handlers, '"not_found"'),
|
||||
(handlers, 'w.Header().Set("X-Event-Count"'),
|
||||
(exporter, 'ExportFormatCSV ExportFormat = "csv"'),
|
||||
(exporter, 'ExportFormatJSON ExportFormat = "json"'),
|
||||
(exporter, 'InvalidSigCount int `json:"invalid_signature_count,omitempty"`'),
|
||||
(logger, "retentionStartupCleanupDelay = 5 * time.Minute"),
|
||||
(logger, "defaultAuditCleanupInterval = 24 * time.Hour"),
|
||||
(logger, "retentionDays = 90"),
|
||||
(logger, 'EventType: "audit_cleanup"'),
|
||||
):
|
||||
with self.subTest(runtime_token=token):
|
||||
self.assertIn(token, source)
|
||||
|
||||
for marker in (
|
||||
"`invalid_query`",
|
||||
"`ambiguous_query`",
|
||||
"`audit_store_busy`",
|
||||
"`Retry-After: 2`",
|
||||
"`audit_store_unavailable`",
|
||||
"`format` (`json` by default, or `csv`)",
|
||||
"`verify=true`",
|
||||
"`X-Event-Count`",
|
||||
"JSON is the lossless evidence export",
|
||||
"`invalid_signature_count`",
|
||||
"`export_unavailable`",
|
||||
"`summary_unavailable`",
|
||||
"`invalid_id`",
|
||||
"`not_found`",
|
||||
"**90 days** by default",
|
||||
"**5 minutes after startup**",
|
||||
"**24 hours**",
|
||||
"`audit_cleanup`",
|
||||
):
|
||||
with self.subTest(audit_doc_marker=marker):
|
||||
self.assertIn(marker, guide)
|
||||
|
||||
for marker in (
|
||||
"### Export Audit Events",
|
||||
"GET /api/audit/export",
|
||||
"### Audit Summary",
|
||||
"GET /api/audit/summary",
|
||||
"GET /api/audit/exports",
|
||||
"`ambiguous_query`",
|
||||
"`audit_store_busy`",
|
||||
"`Retry-After: 2`",
|
||||
"`audit_store_unavailable`",
|
||||
"`export_unavailable`",
|
||||
"`summary_unavailable`",
|
||||
"`invalid_signature_count`",
|
||||
"`X-Event-Count`",
|
||||
):
|
||||
with self.subTest(api_doc_marker=marker):
|
||||
self.assertIn(marker, api_doc)
|
||||
|
||||
|
||||
class AuditWebhookDocsTest(unittest.TestCase):
|
||||
|
||||
Reference in New Issue
Block a user