diff --git a/docs/API.md b/docs/API.md index 06398bc02d..409ee3e3c5 100644 --- a/docs/API.md +++ b/docs/API.md @@ -242,6 +242,7 @@ Login body: Public endpoints include: - `GET /api/health` - `GET /api/version` +- `GET /api/server/info` (minimal version and development flag for installers) - `GET /api/agent/version` (agent update checks) - `GET /api/setup-script` (public; the generated script prompts for its setup token at runtime and skips auto-registration if none is supplied) @@ -371,8 +372,8 @@ capped at 30 entries. Powered-off workloads are neutral (`off`), and stale or missing telemetry is never reported as `ok`. ### Simple Stats (HTML) -`GET /simple-stats` -Lightweight HTML status page for quick checks. +`GET /simple-stats` (authenticated) +Lightweight HTML status page for quick checks. Requires an authenticated session or API token. ### Unified Resources `GET /api/resources` @@ -784,9 +785,9 @@ Version fields are returned as plain semantic versions (no leading `v`). ## 🖥️ Nodes & Config -### Public Config -`GET /api/config` -Returns a small public config payload (update channel, auto-update enabled). +### Runtime Config +`GET /api/config` (authenticated, `monitoring:read`) +Returns a small runtime config payload (`autoUpdateEnabled`, `updateChannel`, and `csrfProtection`). Requires authentication with `monitoring:read`. Non-GET methods return `405`. ### List Nodes `GET /api/config/nodes` (admin, `settings:read`) @@ -1653,21 +1654,22 @@ Applies auth changes by restarting the service on systemd deployments (non-syste ## ⚙️ System Settings ### Get Settings -`GET /api/system/settings` +`GET /api/system/settings` (instance admin, `settings:read`) Retrieve current system settings. ### Update Settings -`POST /api/system/settings/update` -Update system settings. Requires admin + `settings:write`. +`POST /api/system/settings/update` (instance admin, `settings:write`) +Update system settings. Requires instance admin + `settings:write`. ### Legacy System Settings (Read Only) -`GET /api/config/system` -Legacy system settings endpoint (read-only). +`GET /api/config/system` (instance admin, `settings:read`) +Legacy system settings endpoint (read-only, `GET` only). ### Toggle Mock Mode -`GET /api/system/mock-mode` -`POST /api/system/mock-mode` -`PUT /api/system/mock-mode` +- `GET /api/system/mock-mode` (instance admin, `settings:read`) +- `POST /api/system/mock-mode` (instance admin, `settings:write`) +- `PUT /api/system/mock-mode` (instance admin, `settings:write`) + Enable or disable mock data generation (dev/demo only). ### SSH Config (Temperature Monitoring) @@ -1858,9 +1860,9 @@ tenant-bound API tokens and non-admin proxy-auth callers): runtime, and persists it to `system.json` so `debug` stays active across restarts until set back to `info`. -### Server Info -`GET /api/server/info` -Returns minimal server info for installer scripts. +### Server Info (Public) +`GET /api/server/info` (also accepts `HEAD`) +Public endpoint returning minimal server info (`isDevelopment` and `version`) for installer scripts. Non-GET/HEAD methods return `405`. --- @@ -2085,27 +2087,27 @@ Returns current AI configuration (providers, models, patrol status). Requires ad Configure AI providers, API keys, and preferences. Requires admin + `settings:write`. Changing an OpenAI, Z.ai, or Ollama base URL to a different origin while retaining an existing stored API key or password returns `400` unless the credential is entered again or cleared, preventing a stored secret from being sent to a different server. ### List Models -`GET /api/ai/models` +`GET /api/ai/models` (`ai:chat`) Lists models available to the configured providers (queried live from provider APIs). ### Provider Tests (Admin) -- `POST /api/ai/test` -- `POST /api/ai/test/{provider}` +- `POST /api/ai/test` (`settings:write`, settings write permission) +- `POST /api/ai/test/{provider}` (`settings:write`, settings write permission) ### Legacy Anthropic OAuth Cleanup Anthropic subscription OAuth is unsupported. These routes remain only for fail-closed compatibility and token cleanup: -- `POST /api/ai/oauth/start` (admin): returns `501` with `unsupported_anthropic_oauth` -- `POST /api/ai/oauth/exchange` (admin): returns `501` with `unsupported_anthropic_oauth` +- `POST /api/ai/oauth/start` (instance admin, `settings:write`): returns `501` with `unsupported_anthropic_oauth` +- `POST /api/ai/oauth/exchange` (instance admin, `settings:write`): returns `501` with `unsupported_anthropic_oauth` - `GET /api/ai/oauth/callback` (public): redirects to settings with `ai_oauth_error=unsupported` unless the provider supplied a specific error -- `POST /api/ai/oauth/disconnect` (admin): clears stored legacy OAuth tokens +- `POST /api/ai/oauth/disconnect` (instance admin, `settings:write`): clears stored legacy OAuth tokens ### Execute (Chat + Tools) -`POST /api/ai/execute` +`POST /api/ai/execute` (instance admin, `ai:execute`) Runs an AI request which may return tool calls, findings, or suggested actions. ### Execute (Streaming) -`POST /api/ai/execute/stream` +`POST /api/ai/execute/stream` (instance admin, `ai:execute`) Streaming variant of execute. ### Chat Sessions (Pulse Mobile) @@ -2129,7 +2131,7 @@ actions see every session, including Patrol's background sessions and sessions s ownership was recorded. ### Kubernetes AI Analysis (Compatibility) -`POST /api/ai/kubernetes/analyze` +`POST /api/ai/kubernetes/analyze` (instance admin, `ai:execute`) ```json { "cluster_id": "cluster-id" } ``` @@ -2138,7 +2140,7 @@ available for compatibility, but current v6 Pulse Pro marketing does not treat Kubernetes-specific analysis as a standalone plan pillar. ### Alert Investigation (Pro) -`POST /api/ai/investigate-alert` +`POST /api/ai/investigate-alert` (instance admin, `ai:execute`) Runs a focused investigation for an alert payload (used by the UI). ### Patrol @@ -2199,9 +2201,13 @@ Runs a focused investigation for an alert payload (used by the UI). retain their existing action-specific scopes. - Attention IDs and evidence IDs are opaque and can contain slashes. Clients must path-escape each ID. -- `GET /api/ai/patrol/autonomy` -- `PUT /api/ai/patrol/autonomy` -- `GET /api/ai/patrol/status` +- `GET /api/ai/patrol/autonomy` (instance admin, `settings:write`) +- `PUT /api/ai/patrol/autonomy` (instance admin, `settings:write`) +- `POST /api/ai/patrol/autonomy/acknowledgements` (instance admin, `settings:write`) +- `DELETE /api/ai/patrol/autonomy/acknowledgements/{id}` (instance admin, `settings:write`) +- `POST /api/ai/patrol/preflight` (`settings:write`, settings write permission): one-shot verification that the configured Patrol provider and model support tool calling. +- `POST /api/ai/patrol/readiness` (`settings:write`, settings write permission): multi-scenario Patrol model readiness check. +- `GET /api/ai/patrol/status` (`ai:execute`) - `GET /api/ai/patrol/findings` - `DELETE /api/ai/patrol/findings` (clear all findings, in a session an administrator or organization manager) - `GET /api/ai/patrol/objectives` @@ -2284,7 +2290,7 @@ accepted on the acknowledge, dismiss and snooze routes. - `POST /api/ai/approvals/{id}/approve` - `POST /api/ai/approvals/{id}/deny` - `POST /api/ai/run-command` (retired: always returns `410 Gone` with error code `raw_command_retired`; raw command execution is no longer supported, so use advertised typed resource actions instead) -- `GET /api/ai/agents` (connected agents via `/api/agent/ws`) +- `GET /api/ai/agents` (`ai:execute`, connected agents via `/api/agent/ws`) ### Remediation Plans (Pro) - `GET /api/ai/remediation/plans` @@ -2325,14 +2331,14 @@ Patrol reads saved notes on runs that can run commands on hosts, so `save`, actions, as on the Actions routes. Reading and exporting notes needs `ai:chat`. ### Debug -- `GET /api/ai/debug/context` (admin) +- `GET /api/ai/debug/context` (instance admin, `settings:read`) ### Cost Tracking -- `GET /api/ai/cost/summary` -- `GET /api/ai/patrol/cost-preview` (optional `model` as `provider:model`, `interval_minutes`; projects Patrol's 30-day cost for a model and schedule from Pulse's price table and the install's run history, with the per-run token assumption, 30-day spend against budget, and a recommended schedule) -- `GET /api/ai/patrol/model-guidance` (recommended / suggested / caution markers for the Patrol model pickers, plus this install's cached readiness pass) -- `POST /api/ai/cost/reset` (admin) -- `GET /api/ai/cost/export` (admin) +- `GET /api/ai/cost/summary` (instance admin or `settings:read` token) +- `GET /api/ai/patrol/cost-preview` (`settings:read`): optional `model` as `provider:model` and `interval_minutes`. Projects Patrol's 30-day cost for a model and schedule from Pulse's price table and the install's run history, with the per-run token assumption, 30-day spend against budget, and a recommended schedule. +- `GET /api/ai/patrol/model-guidance` (`settings:read`): recommended, suggested, and caution markers for the Patrol model pickers, plus this install's cached readiness pass. +- `POST /api/ai/cost/reset` (instance admin, `settings:write`) +- `GET /api/ai/cost/export` (instance admin, `settings:read`) ## 📈 Metrics Store @@ -2380,9 +2386,9 @@ The unified agent combines host, Docker, and Kubernetes monitoring. Use `--enabl See [UNIFIED_AGENT.md](UNIFIED_AGENT.md) for installation instructions. -### Agent Version -`GET /api/agent/version` -Returns the current server version for agent update checks. +### Agent Version (Public) +`GET /api/agent/version` (also accepts `HEAD`) +Public, uncached (`Cache-Control: no-store`) endpoint returning the target agent binary version (including its `v` prefix matching `pulse-agent --version`) for agent update checks. ### Agent Fleet Diagnostics `GET /api/agents/diagnostics` (admin, `settings:read`) @@ -2397,9 +2403,9 @@ Serves the universal `install.sh` used to install `pulse-agent` on target machin Serves the PowerShell installer for Windows. ### Submit Reports -`POST /api/agents/agent/report` - Agent metrics -`POST /api/agents/docker/report` - Docker container metrics -`POST /api/agents/kubernetes/report` - Kubernetes cluster metrics +- `POST /api/agents/agent/report` (`agent:report` token, or org admin session) - Agent metrics +- `POST /api/agents/docker/report` (`docker:report` token, or org admin session) - Docker container metrics +- `POST /api/agents/kubernetes/report` (`kubernetes:report` token, or org admin session) - Kubernetes cluster metrics ### Agent Management `GET /api/agents/agent/lookup?id=` @@ -2444,7 +2450,7 @@ Clears the removal block left by `DELETE /api/agents/agent/{agent_id}` so the ag ### Agent Remote Config `GET /api/agents/agent/{agent_id}/config` -Returns the server-side config payload for an agent (used by remote config and debugging). Requires `agent:config:read`. +Returns the server-side config payload for an agent (used by remote config and debugging). Token callers need `agent:config:read` (or a compatible bound `agent:report` token) for their own agent, or `agent:manage` / `settings:write` for management reads. Browser and proxy sessions require organization administrator access. Assigned HTTP availability-check credentials and request bodies are returned only to the token that agent reports under. The `config` object includes the merged desired settings, command enablement decision, and desired-config metadata. When signing is configured, the signature remains backward-compatible with legacy agents: it covers @@ -2607,8 +2613,9 @@ TrueNAS connection management endpoints for adding, testing, and removing TrueNA - `POST /api/truenas/connections` (admin, `settings:write`) — Add a new TrueNAS connection. - `POST /api/truenas/connections/test` (admin, `settings:write`) — Test a TrueNAS connection before saving. - `POST /api/truenas/connections/{id}/test` (admin, `settings:write`) — Live-test a saved connection with its stored credentials. An optional JSON body overrides fields for this test only and is not saved. Returns `404` (`truenas_not_found`) for an unknown ID and `400` (`truenas_invalid_config` or `truenas_connection_failed`) on failure. The probe does not clear poll errors or advance poll freshness, so check the `poll` field from `GET /api/truenas/connections` to see whether ordinary polling has recovered. +- `POST /api/truenas/connections/preview` and `POST /api/truenas/connections/{id}/preview` (admin, `settings:write`): project the canonical monitored-system impact of adding or editing a TrueNAS connection without persisting changes. - `DELETE /api/truenas/connections/{id}` (admin, `settings:write`) — Remove a TrueNAS connection. -- `PUT /api/truenas/connections/{id}` (admin, `settings:write`) — Update a saved TrueNAS connection. Send only the fields to change in a private JSON file; omitted fields keep their stored values. A masked `apiKey` or `password` returned by a GET response is kept from the stored record, so never send a masked value as a new secret. Saving does not test the connection. Setting `monitorDatasets`, `monitorPools` and `monitorReplication` all to `false` is saved as all enabled. Returns 200 with the redacted connection, 400 `validation_error`, 404 `truenas_not_found`, or 403 `mock_mode_enabled` in mock mode. +- `PUT /api/truenas/connections/{id}` (admin, `settings:write`): update a saved TrueNAS connection. Send only the fields to change in a private JSON file. Omitted fields keep their stored values. A masked `apiKey` or `password` returned by a GET response is kept from the stored record, so never send a masked value as a new secret. Saving does not test the connection. Setting `monitorDatasets`, `monitorPools`, and `monitorReplication` all to `false` is preserved as all off, so Pulse skips dataset, snapshot, pool, and replication queries while keeping system, disk, and alert reads active (only legacy pre-provenance configs without a recorded scope default all-false to all enabled on load). Returns 200 with the redacted connection, 400 `validation_error`, 404 `truenas_not_found`, or 403 `mock_mode_enabled` in mock mode. TrueNAS resources (pools, datasets, disks, ZFS snapshots, replication tasks, alerts) are surfaced through the unified `/api/resources` endpoint with `source=truenas`. @@ -2637,21 +2644,21 @@ End-to-end encrypted relay protocol for mobile connectivity. > Relay pairing endpoints generate the QR code and deep link used by supported Pulse Mobile clients. -### Relay Configuration (Relay and Above; admin session or scoped token) -- `GET /api/settings/relay` (`settings:read` token scope, or admin session, Relay+) — Get current relay configuration. -- `PUT /api/settings/relay` (`settings:write` token scope, or admin session, Relay+) — Update relay configuration. -- `GET /api/settings/relay/status` (`settings:read` token scope, or admin session, Relay+) — Get relay connection status. +### Relay Configuration (Relay and Above, admin session or instance token) +- `GET /api/settings/relay` (instance admin session or instance token with `settings:read`, Relay+): get current relay configuration. +- `PUT /api/settings/relay` (instance admin session or instance token with `settings:write`, Relay+): update relay configuration. +- `GET /api/settings/relay/status` (instance admin session or instance token with `settings:read`, Relay+): get relay connection status. -### Mobile Onboarding -- `GET /api/onboarding/qr` (`settings:read`) — Generate QR code for Pulse Mobile pairing. -- `POST /api/onboarding/validate` (`settings:read`) — Validate a mobile onboarding connection. -- `GET /api/onboarding/deep-link` (`settings:read`) — Generate deep-link URL for mobile app. +### Mobile Onboarding (Relay and Above, admin session or scoped token) +- `GET /api/onboarding/qr` (admin session, or token with `relay:mobile:access` or `settings:read`, Relay+): generate QR code for Pulse Mobile pairing. +- `POST /api/onboarding/validate` (admin session, or token with `relay:mobile:access` or `settings:read`, Relay+): validate a mobile onboarding connection. +- `GET /api/onboarding/deep-link` (admin session, or token with `relay:mobile:access` or `settings:read`, Relay+): generate deep-link URL for mobile app. --- ## 🔌 WebSocket Endpoints -- `GET /ws` – Primary UI WebSocket (browser sessions). +- `GET /ws` (authenticated, `monitoring:read`) – Primary UI WebSocket. Requires authentication, `monitoring:read` scope for API tokens, and organization membership (rechecked every 10 seconds). - `GET /api/agent/ws` – Agent WebSocket used for AI command execution. --- diff --git a/frontend-modern/public/docs/API.md b/frontend-modern/public/docs/API.md index 06398bc02d..409ee3e3c5 100644 --- a/frontend-modern/public/docs/API.md +++ b/frontend-modern/public/docs/API.md @@ -242,6 +242,7 @@ Login body: Public endpoints include: - `GET /api/health` - `GET /api/version` +- `GET /api/server/info` (minimal version and development flag for installers) - `GET /api/agent/version` (agent update checks) - `GET /api/setup-script` (public; the generated script prompts for its setup token at runtime and skips auto-registration if none is supplied) @@ -371,8 +372,8 @@ capped at 30 entries. Powered-off workloads are neutral (`off`), and stale or missing telemetry is never reported as `ok`. ### Simple Stats (HTML) -`GET /simple-stats` -Lightweight HTML status page for quick checks. +`GET /simple-stats` (authenticated) +Lightweight HTML status page for quick checks. Requires an authenticated session or API token. ### Unified Resources `GET /api/resources` @@ -784,9 +785,9 @@ Version fields are returned as plain semantic versions (no leading `v`). ## 🖥️ Nodes & Config -### Public Config -`GET /api/config` -Returns a small public config payload (update channel, auto-update enabled). +### Runtime Config +`GET /api/config` (authenticated, `monitoring:read`) +Returns a small runtime config payload (`autoUpdateEnabled`, `updateChannel`, and `csrfProtection`). Requires authentication with `monitoring:read`. Non-GET methods return `405`. ### List Nodes `GET /api/config/nodes` (admin, `settings:read`) @@ -1653,21 +1654,22 @@ Applies auth changes by restarting the service on systemd deployments (non-syste ## ⚙️ System Settings ### Get Settings -`GET /api/system/settings` +`GET /api/system/settings` (instance admin, `settings:read`) Retrieve current system settings. ### Update Settings -`POST /api/system/settings/update` -Update system settings. Requires admin + `settings:write`. +`POST /api/system/settings/update` (instance admin, `settings:write`) +Update system settings. Requires instance admin + `settings:write`. ### Legacy System Settings (Read Only) -`GET /api/config/system` -Legacy system settings endpoint (read-only). +`GET /api/config/system` (instance admin, `settings:read`) +Legacy system settings endpoint (read-only, `GET` only). ### Toggle Mock Mode -`GET /api/system/mock-mode` -`POST /api/system/mock-mode` -`PUT /api/system/mock-mode` +- `GET /api/system/mock-mode` (instance admin, `settings:read`) +- `POST /api/system/mock-mode` (instance admin, `settings:write`) +- `PUT /api/system/mock-mode` (instance admin, `settings:write`) + Enable or disable mock data generation (dev/demo only). ### SSH Config (Temperature Monitoring) @@ -1858,9 +1860,9 @@ tenant-bound API tokens and non-admin proxy-auth callers): runtime, and persists it to `system.json` so `debug` stays active across restarts until set back to `info`. -### Server Info -`GET /api/server/info` -Returns minimal server info for installer scripts. +### Server Info (Public) +`GET /api/server/info` (also accepts `HEAD`) +Public endpoint returning minimal server info (`isDevelopment` and `version`) for installer scripts. Non-GET/HEAD methods return `405`. --- @@ -2085,27 +2087,27 @@ Returns current AI configuration (providers, models, patrol status). Requires ad Configure AI providers, API keys, and preferences. Requires admin + `settings:write`. Changing an OpenAI, Z.ai, or Ollama base URL to a different origin while retaining an existing stored API key or password returns `400` unless the credential is entered again or cleared, preventing a stored secret from being sent to a different server. ### List Models -`GET /api/ai/models` +`GET /api/ai/models` (`ai:chat`) Lists models available to the configured providers (queried live from provider APIs). ### Provider Tests (Admin) -- `POST /api/ai/test` -- `POST /api/ai/test/{provider}` +- `POST /api/ai/test` (`settings:write`, settings write permission) +- `POST /api/ai/test/{provider}` (`settings:write`, settings write permission) ### Legacy Anthropic OAuth Cleanup Anthropic subscription OAuth is unsupported. These routes remain only for fail-closed compatibility and token cleanup: -- `POST /api/ai/oauth/start` (admin): returns `501` with `unsupported_anthropic_oauth` -- `POST /api/ai/oauth/exchange` (admin): returns `501` with `unsupported_anthropic_oauth` +- `POST /api/ai/oauth/start` (instance admin, `settings:write`): returns `501` with `unsupported_anthropic_oauth` +- `POST /api/ai/oauth/exchange` (instance admin, `settings:write`): returns `501` with `unsupported_anthropic_oauth` - `GET /api/ai/oauth/callback` (public): redirects to settings with `ai_oauth_error=unsupported` unless the provider supplied a specific error -- `POST /api/ai/oauth/disconnect` (admin): clears stored legacy OAuth tokens +- `POST /api/ai/oauth/disconnect` (instance admin, `settings:write`): clears stored legacy OAuth tokens ### Execute (Chat + Tools) -`POST /api/ai/execute` +`POST /api/ai/execute` (instance admin, `ai:execute`) Runs an AI request which may return tool calls, findings, or suggested actions. ### Execute (Streaming) -`POST /api/ai/execute/stream` +`POST /api/ai/execute/stream` (instance admin, `ai:execute`) Streaming variant of execute. ### Chat Sessions (Pulse Mobile) @@ -2129,7 +2131,7 @@ actions see every session, including Patrol's background sessions and sessions s ownership was recorded. ### Kubernetes AI Analysis (Compatibility) -`POST /api/ai/kubernetes/analyze` +`POST /api/ai/kubernetes/analyze` (instance admin, `ai:execute`) ```json { "cluster_id": "cluster-id" } ``` @@ -2138,7 +2140,7 @@ available for compatibility, but current v6 Pulse Pro marketing does not treat Kubernetes-specific analysis as a standalone plan pillar. ### Alert Investigation (Pro) -`POST /api/ai/investigate-alert` +`POST /api/ai/investigate-alert` (instance admin, `ai:execute`) Runs a focused investigation for an alert payload (used by the UI). ### Patrol @@ -2199,9 +2201,13 @@ Runs a focused investigation for an alert payload (used by the UI). retain their existing action-specific scopes. - Attention IDs and evidence IDs are opaque and can contain slashes. Clients must path-escape each ID. -- `GET /api/ai/patrol/autonomy` -- `PUT /api/ai/patrol/autonomy` -- `GET /api/ai/patrol/status` +- `GET /api/ai/patrol/autonomy` (instance admin, `settings:write`) +- `PUT /api/ai/patrol/autonomy` (instance admin, `settings:write`) +- `POST /api/ai/patrol/autonomy/acknowledgements` (instance admin, `settings:write`) +- `DELETE /api/ai/patrol/autonomy/acknowledgements/{id}` (instance admin, `settings:write`) +- `POST /api/ai/patrol/preflight` (`settings:write`, settings write permission): one-shot verification that the configured Patrol provider and model support tool calling. +- `POST /api/ai/patrol/readiness` (`settings:write`, settings write permission): multi-scenario Patrol model readiness check. +- `GET /api/ai/patrol/status` (`ai:execute`) - `GET /api/ai/patrol/findings` - `DELETE /api/ai/patrol/findings` (clear all findings, in a session an administrator or organization manager) - `GET /api/ai/patrol/objectives` @@ -2284,7 +2290,7 @@ accepted on the acknowledge, dismiss and snooze routes. - `POST /api/ai/approvals/{id}/approve` - `POST /api/ai/approvals/{id}/deny` - `POST /api/ai/run-command` (retired: always returns `410 Gone` with error code `raw_command_retired`; raw command execution is no longer supported, so use advertised typed resource actions instead) -- `GET /api/ai/agents` (connected agents via `/api/agent/ws`) +- `GET /api/ai/agents` (`ai:execute`, connected agents via `/api/agent/ws`) ### Remediation Plans (Pro) - `GET /api/ai/remediation/plans` @@ -2325,14 +2331,14 @@ Patrol reads saved notes on runs that can run commands on hosts, so `save`, actions, as on the Actions routes. Reading and exporting notes needs `ai:chat`. ### Debug -- `GET /api/ai/debug/context` (admin) +- `GET /api/ai/debug/context` (instance admin, `settings:read`) ### Cost Tracking -- `GET /api/ai/cost/summary` -- `GET /api/ai/patrol/cost-preview` (optional `model` as `provider:model`, `interval_minutes`; projects Patrol's 30-day cost for a model and schedule from Pulse's price table and the install's run history, with the per-run token assumption, 30-day spend against budget, and a recommended schedule) -- `GET /api/ai/patrol/model-guidance` (recommended / suggested / caution markers for the Patrol model pickers, plus this install's cached readiness pass) -- `POST /api/ai/cost/reset` (admin) -- `GET /api/ai/cost/export` (admin) +- `GET /api/ai/cost/summary` (instance admin or `settings:read` token) +- `GET /api/ai/patrol/cost-preview` (`settings:read`): optional `model` as `provider:model` and `interval_minutes`. Projects Patrol's 30-day cost for a model and schedule from Pulse's price table and the install's run history, with the per-run token assumption, 30-day spend against budget, and a recommended schedule. +- `GET /api/ai/patrol/model-guidance` (`settings:read`): recommended, suggested, and caution markers for the Patrol model pickers, plus this install's cached readiness pass. +- `POST /api/ai/cost/reset` (instance admin, `settings:write`) +- `GET /api/ai/cost/export` (instance admin, `settings:read`) ## 📈 Metrics Store @@ -2380,9 +2386,9 @@ The unified agent combines host, Docker, and Kubernetes monitoring. Use `--enabl See [UNIFIED_AGENT.md](UNIFIED_AGENT.md) for installation instructions. -### Agent Version -`GET /api/agent/version` -Returns the current server version for agent update checks. +### Agent Version (Public) +`GET /api/agent/version` (also accepts `HEAD`) +Public, uncached (`Cache-Control: no-store`) endpoint returning the target agent binary version (including its `v` prefix matching `pulse-agent --version`) for agent update checks. ### Agent Fleet Diagnostics `GET /api/agents/diagnostics` (admin, `settings:read`) @@ -2397,9 +2403,9 @@ Serves the universal `install.sh` used to install `pulse-agent` on target machin Serves the PowerShell installer for Windows. ### Submit Reports -`POST /api/agents/agent/report` - Agent metrics -`POST /api/agents/docker/report` - Docker container metrics -`POST /api/agents/kubernetes/report` - Kubernetes cluster metrics +- `POST /api/agents/agent/report` (`agent:report` token, or org admin session) - Agent metrics +- `POST /api/agents/docker/report` (`docker:report` token, or org admin session) - Docker container metrics +- `POST /api/agents/kubernetes/report` (`kubernetes:report` token, or org admin session) - Kubernetes cluster metrics ### Agent Management `GET /api/agents/agent/lookup?id=` @@ -2444,7 +2450,7 @@ Clears the removal block left by `DELETE /api/agents/agent/{agent_id}` so the ag ### Agent Remote Config `GET /api/agents/agent/{agent_id}/config` -Returns the server-side config payload for an agent (used by remote config and debugging). Requires `agent:config:read`. +Returns the server-side config payload for an agent (used by remote config and debugging). Token callers need `agent:config:read` (or a compatible bound `agent:report` token) for their own agent, or `agent:manage` / `settings:write` for management reads. Browser and proxy sessions require organization administrator access. Assigned HTTP availability-check credentials and request bodies are returned only to the token that agent reports under. The `config` object includes the merged desired settings, command enablement decision, and desired-config metadata. When signing is configured, the signature remains backward-compatible with legacy agents: it covers @@ -2607,8 +2613,9 @@ TrueNAS connection management endpoints for adding, testing, and removing TrueNA - `POST /api/truenas/connections` (admin, `settings:write`) — Add a new TrueNAS connection. - `POST /api/truenas/connections/test` (admin, `settings:write`) — Test a TrueNAS connection before saving. - `POST /api/truenas/connections/{id}/test` (admin, `settings:write`) — Live-test a saved connection with its stored credentials. An optional JSON body overrides fields for this test only and is not saved. Returns `404` (`truenas_not_found`) for an unknown ID and `400` (`truenas_invalid_config` or `truenas_connection_failed`) on failure. The probe does not clear poll errors or advance poll freshness, so check the `poll` field from `GET /api/truenas/connections` to see whether ordinary polling has recovered. +- `POST /api/truenas/connections/preview` and `POST /api/truenas/connections/{id}/preview` (admin, `settings:write`): project the canonical monitored-system impact of adding or editing a TrueNAS connection without persisting changes. - `DELETE /api/truenas/connections/{id}` (admin, `settings:write`) — Remove a TrueNAS connection. -- `PUT /api/truenas/connections/{id}` (admin, `settings:write`) — Update a saved TrueNAS connection. Send only the fields to change in a private JSON file; omitted fields keep their stored values. A masked `apiKey` or `password` returned by a GET response is kept from the stored record, so never send a masked value as a new secret. Saving does not test the connection. Setting `monitorDatasets`, `monitorPools` and `monitorReplication` all to `false` is saved as all enabled. Returns 200 with the redacted connection, 400 `validation_error`, 404 `truenas_not_found`, or 403 `mock_mode_enabled` in mock mode. +- `PUT /api/truenas/connections/{id}` (admin, `settings:write`): update a saved TrueNAS connection. Send only the fields to change in a private JSON file. Omitted fields keep their stored values. A masked `apiKey` or `password` returned by a GET response is kept from the stored record, so never send a masked value as a new secret. Saving does not test the connection. Setting `monitorDatasets`, `monitorPools`, and `monitorReplication` all to `false` is preserved as all off, so Pulse skips dataset, snapshot, pool, and replication queries while keeping system, disk, and alert reads active (only legacy pre-provenance configs without a recorded scope default all-false to all enabled on load). Returns 200 with the redacted connection, 400 `validation_error`, 404 `truenas_not_found`, or 403 `mock_mode_enabled` in mock mode. TrueNAS resources (pools, datasets, disks, ZFS snapshots, replication tasks, alerts) are surfaced through the unified `/api/resources` endpoint with `source=truenas`. @@ -2637,21 +2644,21 @@ End-to-end encrypted relay protocol for mobile connectivity. > Relay pairing endpoints generate the QR code and deep link used by supported Pulse Mobile clients. -### Relay Configuration (Relay and Above; admin session or scoped token) -- `GET /api/settings/relay` (`settings:read` token scope, or admin session, Relay+) — Get current relay configuration. -- `PUT /api/settings/relay` (`settings:write` token scope, or admin session, Relay+) — Update relay configuration. -- `GET /api/settings/relay/status` (`settings:read` token scope, or admin session, Relay+) — Get relay connection status. +### Relay Configuration (Relay and Above, admin session or instance token) +- `GET /api/settings/relay` (instance admin session or instance token with `settings:read`, Relay+): get current relay configuration. +- `PUT /api/settings/relay` (instance admin session or instance token with `settings:write`, Relay+): update relay configuration. +- `GET /api/settings/relay/status` (instance admin session or instance token with `settings:read`, Relay+): get relay connection status. -### Mobile Onboarding -- `GET /api/onboarding/qr` (`settings:read`) — Generate QR code for Pulse Mobile pairing. -- `POST /api/onboarding/validate` (`settings:read`) — Validate a mobile onboarding connection. -- `GET /api/onboarding/deep-link` (`settings:read`) — Generate deep-link URL for mobile app. +### Mobile Onboarding (Relay and Above, admin session or scoped token) +- `GET /api/onboarding/qr` (admin session, or token with `relay:mobile:access` or `settings:read`, Relay+): generate QR code for Pulse Mobile pairing. +- `POST /api/onboarding/validate` (admin session, or token with `relay:mobile:access` or `settings:read`, Relay+): validate a mobile onboarding connection. +- `GET /api/onboarding/deep-link` (admin session, or token with `relay:mobile:access` or `settings:read`, Relay+): generate deep-link URL for mobile app. --- ## 🔌 WebSocket Endpoints -- `GET /ws` – Primary UI WebSocket (browser sessions). +- `GET /ws` (authenticated, `monitoring:read`) – Primary UI WebSocket. Requires authentication, `monitoring:read` scope for API tokens, and organization membership (rechecked every 10 seconds). - `GET /api/agent/ws` – Agent WebSocket used for AI command execution. --- diff --git a/scripts/tests/test_api_reference_routes.py b/scripts/tests/test_api_reference_routes.py index 5ddf039b0d..d23a4583d8 100644 --- a/scripts/tests/test_api_reference_routes.py +++ b/scripts/tests/test_api_reference_routes.py @@ -130,6 +130,69 @@ ROUTE_ANCHORS = [ ("`GET /api/agent/capabilities`", "internal/api/router_routes_monitoring.go", 'r.mux.HandleFunc("/api/agent/capabilities", HandleAgentCapabilitiesManifest)'), + ("`GET /api/config` (authenticated, `monitoring:read`)", + "internal/api/router_routes_registration.go", + 'r.mux.HandleFunc("/api/config", RequireAuth(r.config, RequireScope(config.ScopeMonitoringRead, r.handleConfig)))'), + ("`GET /simple-stats` (authenticated)", + "internal/api/router_routes_auth_security.go", + 'r.mux.HandleFunc("/simple-stats", RequireAuth(r.config, r.handleSimpleStats))'), + ("`GET /api/system/settings` (instance admin, `settings:read`)", + "internal/api/router_routes_registration.go", + 'r.mux.HandleFunc("/api/system/settings", RequireAdmin(r.config, RequireScope(config.ScopeSettingsRead, r.systemSettingsHandler.HandleGetSystemSettings)))'), + ("`POST /api/system/settings/update` (instance admin, `settings:write`)", + "internal/api/router_routes_registration.go", + 'r.mux.HandleFunc("/api/system/settings/update", RequireAdmin(r.config, RequireScope(config.ScopeSettingsWrite, r.systemSettingsHandler.HandleUpdateSystemSettings)))'), + ("`GET /api/config/system` (instance admin, `settings:read`)", + "internal/api/router_routes_registration.go", + 'r.mux.HandleFunc("/api/config/system", func(w http.ResponseWriter, req *http.Request) {'), + ("`GET /api/system/mock-mode` (instance admin, `settings:read`)", + "internal/api/router_routes_registration.go", + 'RequireAdmin(r.config, RequireScope(config.ScopeSettingsRead, r.configHandlers.HandleGetMockMode))(w, req)'), + ("`POST /api/system/mock-mode` (instance admin, `settings:write`)", + "internal/api/router_routes_registration.go", + 'RequireAdmin(r.config, RequireScope(config.ScopeSettingsWrite, r.configHandlers.HandleUpdateMockMode))(w, req)'), + ("`POST /api/truenas/connections/preview` and `POST /api/truenas/connections/{id}/preview` (admin, `settings:write`)", + "internal/api/router_routes_registration.go", + 'r.mux.HandleFunc("/api/truenas/connections/preview", func(w http.ResponseWriter, req *http.Request) {'), + ("`GET /api/onboarding/qr` (admin session, or token with `relay:mobile:access` or `settings:read`, Relay+)", + "internal/api/router_routes_ai_relay.go", + 'r.mux.HandleFunc("GET /api/onboarding/qr", RequireAuth(r.config, requireRelayMobileRuntimeRoute(relayMobileRouteOnboardingQR,'), + ("`POST /api/onboarding/validate` (admin session, or token with `relay:mobile:access` or `settings:read`, Relay+)", + "internal/api/router_routes_ai_relay.go", + 'r.mux.HandleFunc("POST /api/onboarding/validate", RequireAuth(r.config, requireRelayMobileRuntimeRoute(relayMobileRouteOnboardingValidate,'), + ("`GET /api/onboarding/deep-link` (admin session, or token with `relay:mobile:access` or `settings:read`, Relay+)", + "internal/api/router_routes_ai_relay.go", + 'r.mux.HandleFunc("GET /api/onboarding/deep-link", RequireAuth(r.config, requireRelayMobileRuntimeRoute(relayMobileRouteOnboardingDeepLink,'), + ("`GET /api/ai/patrol/autonomy` (instance admin, `settings:write`)", + "internal/api/router_routes_ai_relay.go", + 'r.mux.HandleFunc("/api/ai/patrol/autonomy", RequireAdmin(r.config, RequireScope(config.ScopeSettingsWrite,'), + ("`POST /api/ai/patrol/preflight` (`settings:write`, settings write permission)", + "internal/api/router_routes_ai_relay.go", + 'r.mux.HandleFunc("/api/ai/patrol/preflight", RequirePermission(r.config, r.authorizer, auth.ActionWrite, auth.ResourceSettings, RequireScope(config.ScopeSettingsWrite,'), + ("`POST /api/ai/patrol/readiness` (`settings:write`, settings write permission)", + "internal/api/router_routes_ai_relay.go", + 'r.mux.HandleFunc("/api/ai/patrol/readiness", RequirePermission(r.config, r.authorizer, auth.ActionWrite, auth.ResourceSettings, RequireScope(config.ScopeSettingsWrite,'), + ("`GET /api/ai/debug/context` (instance admin, `settings:read`)", + "internal/api/router_routes_ai_relay.go", + 'r.mux.HandleFunc("/api/ai/debug/context", RequireAdmin(r.config, RequireScope(config.ScopeSettingsRead, r.aiSettingsHandler.HandleDebugContext)))'), + ("`POST /api/ai/cost/reset` (instance admin, `settings:write`)", + "internal/api/router_routes_ai_relay.go", + 'r.mux.HandleFunc("/api/ai/cost/reset", RequireAdmin(r.config, RequireScope(config.ScopeSettingsWrite, r.aiSettingsHandler.HandleResetAICostHistory)))'), + ("`GET /api/ai/cost/export` (instance admin, `settings:read`)", + "internal/api/router_routes_ai_relay.go", + 'r.mux.HandleFunc("/api/ai/cost/export", RequireAdmin(r.config, RequireScope(config.ScopeSettingsRead, r.aiSettingsHandler.HandleExportAICostHistory)))'), + ("`POST /api/agents/agent/report` (`agent:report` token, or org admin session)", + "internal/api/router_routes_registration.go", + 'r.mux.HandleFunc("/api/agents/agent/report", RequireOrgAdmin(r.config, RequireScope(config.ScopeAgentReport, r.unifiedAgentHandlers.HandleReport)))'), + ("`POST /api/agents/docker/report` (`docker:report` token, or org admin session)", + "internal/api/router_routes_registration.go", + 'r.mux.HandleFunc("/api/agents/docker/report", RequireOrgAdmin(r.config, RequireScope(config.ScopeDockerReport, r.dockerAgentHandlers.HandleReport)))'), + ("`POST /api/agents/kubernetes/report` (`kubernetes:report` token, or org admin session)", + "internal/api/router_routes_registration.go", + 'r.mux.HandleFunc("/api/agents/kubernetes/report", RequireOrgAdmin(r.config, RequireScope(config.ScopeKubernetesReport, r.kubernetesAgentHandlers.HandleReport)))'), + ("`GET /ws` (authenticated, `monitoring:read`)", + "internal/api/router.go", + "if !ensureScope(w, req, config.ScopeMonitoringRead) {"), ] @@ -358,6 +421,35 @@ class APIReferenceRoutesTest(unittest.TestCase): self.assertEqual(read("frontend-modern/public/docs/API.md"), self.doc) self.assertEqual(read("frontend-modern/public/docs/AUTO_UPDATE.md"), auto_update_doc) + def test_runtime_config_truenas_scope_and_agent_config_match_code(self) -> None: + truenas_cfg = read("internal/config/truenas.go") + agent_ingest = read("internal/api/agent_ingest.go") + router = read("internal/api/router.go") + + self.assertNotIn("### Public Config", self.doc) + self.assertNotIn("all to `false` is saved as all enabled", self.doc) + self.assertIn("ScopeConfigured bool `json:\"collectionScopeConfigured,omitempty\"`", truenas_cfg) + self.assertIn("ApplyDefaults normalizes the poll interval without changing collection scope.", truenas_cfg) + self.assertIn("record.HasScope(config.ScopeAgentConfigRead)", agent_ingest) + self.assertIn("record.HasScope(config.ScopeAgentReport)", agent_ingest) + self.assertIn("record.HasScope(config.ScopeAgentManage)", agent_ingest) + self.assertIn("record.HasScope(config.ScopeSettingsWrite)", agent_ingest) + self.assertIn('w.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0")', router) + + prose = " ".join(self.doc.split()) + for phrase in ( + "Setting `monitorDatasets`, `monitorPools`, and `monitorReplication` all to `false` is preserved as all off", + "only legacy pre-provenance configs without a recorded scope default all-false to all enabled on load", + "Token callers need `agent:config:read` (or a compatible bound `agent:report` token) for their own agent, or `agent:manage` / `settings:write` for management reads.", + "Browser and proxy sessions require organization administrator access.", + "Assigned HTTP availability-check credentials and request bodies are returned only to the token that agent reports under.", + "Public, uncached (`Cache-Control: no-store`) endpoint returning the target agent binary version", + "Public endpoint returning minimal server info (`isDevelopment` and `version`) for installer scripts.", + "Requires authentication, `monitoring:read` scope for API tokens, and organization membership (rechecked every 10 seconds).", + ): + self.assertIn(phrase, prose) + self.assertEqual(read("frontend-modern/public/docs/API.md"), self.doc) + def test_negative_controls_fail_when_reference_or_code_drift(self) -> None: # An invented scope on a route line is reported. drifted = self.doc.replace("`POST /api/availability-history` (`monitoring:read`)",