Commit Graph

613 Commits

Author SHA1 Message Date
rcourtman 0c4b19ddf4 Add SSH security regression coverage 2026-02-04 11:36:11 +00:00
rcourtman 06df067cd7 Cover apply-restart auth guards 2026-02-04 11:30:37 +00:00
rcourtman a9dc469de7 Add permission denial regression tests 2026-02-04 11:28:09 +00:00
rcourtman a2b8b21ada Fix rate limit flake in config export/import tests 2026-02-04 11:23:12 +00:00
rcourtman ee5931ac7d test: extend admin proxy and reset lockout auth coverage 2026-02-04 11:16:53 +00:00
rcourtman df4ae9d639 test: deny non-admin proxy users on admin endpoints 2026-02-04 11:14:53 +00:00
rcourtman 65a0b7a0e4 test: cover change-password and public export/import guards 2026-02-04 11:12:54 +00:00
rcourtman 5553214256 test: require auth for license status 2026-02-04 11:08:21 +00:00
rcourtman ed0f85149d test: require auth for logs and update status 2026-02-04 11:00:46 +00:00
rcourtman ae58e16525 test: include /api/config in monitoring read coverage 2026-02-04 11:00:03 +00:00
rcourtman 764805b0b9 test: require auth for auto-register 2026-02-04 10:59:24 +00:00
rcourtman d6172b9a86 test: require auth for config export/import in api mode 2026-02-04 10:57:14 +00:00
rcourtman 47a4dc01cf test: require auth for ai status, license features, scheduler health 2026-02-04 10:56:17 +00:00
rcourtman 5850ddf584 test: enforce proxy admin for config export/import and notifications 2026-02-04 10:54:51 +00:00
rcourtman 83311cdf8c test: require settings:write for ai patrol autonomy update 2026-02-04 10:48:56 +00:00
rcourtman 32426aa6ca test: license gate audit verify endpoint 2026-02-04 10:48:11 +00:00
rcourtman f8b495c54c test: enforce scope on security token endpoints 2026-02-04 10:47:36 +00:00
rcourtman 0a26ef622a test: license gate audit webhook endpoint 2026-02-04 10:46:53 +00:00
rcourtman 1fdb96db1f test: require settings scopes for config export/import 2026-02-04 10:46:19 +00:00
rcourtman f8a8affe26 test: enforce license gating for enterprise endpoints 2026-02-04 10:42:44 +00:00
rcourtman a6e1b7f6ee test: require license for audit and reporting 2026-02-04 10:42:00 +00:00
rcourtman 71440c9521 test: require host:manage for host config patch 2026-02-04 10:40:58 +00:00
rcourtman ac006ff5b9 test: require ai:chat scope for chat endpoints 2026-02-04 10:40:19 +00:00
rcourtman 563f4893fb test: guard ai settings endpoints by scope 2026-02-04 10:39:28 +00:00
rcourtman 86b75c9e7c test: enforce monitoring:write for metadata mutations 2026-02-04 10:38:48 +00:00
rcourtman 9409969ddd test: require monitoring:read for core data endpoints 2026-02-04 10:37:53 +00:00
rcourtman 8ed47b8971 test: enforce agent scope checks 2026-02-04 10:37:06 +00:00
rcourtman 37f909c6dd test: guard discovery endpoints by scope 2026-02-04 10:35:43 +00:00
rcourtman ad21be68f3 test: enforce settings:write for config node mutations 2026-02-04 10:34:41 +00:00
rcourtman ead8eb7087 test: require ai:execute scope on more ai endpoints 2026-02-04 10:33:53 +00:00
rcourtman c68e386d01 test: cover ai patrol and run-command scopes 2026-02-04 10:32:05 +00:00
rcourtman b9eee668e5 test: expand security regression coverage 2026-02-04 10:28:41 +00:00
rcourtman 5c1487e406 feat: add resource picker and multi-resource report generation
Replace manual resource ID entry with a searchable, filterable resource
picker that uses live WebSocket state. Support selecting multiple
resources (up to 50) for combined fleet reports.

Multi-resource PDFs include a cover page, fleet summary table with
aggregate health status, and condensed per-resource detail pages with
overlaid CPU/memory charts. Multi-resource CSVs include a summary
section followed by interleaved time-series data with resource columns.

New POST /api/admin/reports/generate-multi endpoint handles multi-resource
requests while the existing single-resource GET endpoint remains unchanged.

Also fixes resource ID validation regex to allow colons used in
VM/container IDs (e.g., "instance:node:vmid").
2026-02-04 10:24:23 +00:00
rcourtman f60050a801 fix(security): restrict query-string token auth to WebSocket upgrades only
API tokens passed via ?token= query parameter were accepted on all HTTP
requests. This is a security concern because tokens in URLs can leak via
server logs, browser history, referrer headers, and proxy logs.

The query-string token path exists solely for WebSocket connections which
cannot set custom headers during the upgrade handshake. This change adds
an isWebSocketUpgrade check to all three query-string extraction sites
in CheckAuth and extractAndStoreAuthContext, rejecting ?token= on regular
HTTP requests while preserving WebSocket functionality.

No frontend impact — the kiosk flow stores the token in sessionStorage
then uses X-API-Token headers for all API calls.
2026-02-04 09:52:32 +00:00
rcourtman a6f2a674eb fix: resolve test failures blocking release
- KnowledgeStore: use atomic write (temp+rename) to prevent file
  corruption from concurrent async saves
- Change password tests: add auth headers since endpoint now requires
  authentication
- ClearSession test: expect 2 cookies (pulse_session + pulse_csrf)
  matching updated clearSession behavior
- API token test: update to match current behavior where query-string
  tokens are accepted (needed for WebSocket connections)
- Host agent config: allow ScopeHostManage to resolve any host, not
  just token-bound hosts
2026-02-03 23:53:54 +00:00
rcourtman 6059759958 feat: Add sparkline support for unified host agents on hosts page
Backend:
- Add HostData field to ChartResponse struct in types.go
- Add host data processing in /api/charts endpoint using 'host:' prefix key
- Include hosts count in debug logging for chart responses

Frontend:
- Add 'host' to MetricResourceKind type in metricsKeys.ts
- Add hostData field to ChartsResponse interface in charts.ts
- Process hostData in seedFromBackend() in metricsHistory.ts
- Pass resourceId to EnhancedCPUBar and StackedMemoryBar in HostsOverview.tsx
- Add '7d' and '30d' to TIME_RANGE_OPTIONS in metricsViewMode.ts

This enables sparkline trend visualization for unified host agents,
consistent with Proxmox guests. Data accumulates over time at 30s intervals.
2026-02-03 22:59:55 +00:00
rcourtman 7c1ebbecd5 fix(security): enhance webhook validation, enforce API scopes, and improve test coverage 2026-02-03 22:41:44 +00:00
rcourtman 5a990dd554 Fix sparkline data inconsistency and support 30d range 2026-02-03 22:39:50 +00:00
rcourtman b7a94bad9f security: fix websocket scope and agent impersonation
1. Enforce monitoring:read scope on WebSocket upgrades
   - Prevents low-privilege tokens (e.g. host-agent:report) from accessing
     full infra state via requestData on the main WebSocket.

2. Enforce agent token binding to prevent impersonation
   - Added Metadata field to APITokenRecord to support bound_agent_id
   - Updated agentexec server to validate token-to-agent binding if present
   - Prevents agent:exec tokens from registering as arbitrary agent IDs
2026-02-03 20:40:08 +00:00
rcourtman 0dfe3d16b3 security: secure socket.io, test-notification, and stats endpoints
1. Secure /socket.io/ endpoint
   - Previously allowed unauthenticated WebSocket upgrades via transport=websocket
   - Now enforces CheckAuth() before upgrade

2. Secure /api/test-notification
   - Previously unauthenticated and allowed broadcasting to all clients
   - Now requires Admin + settings:write scope

3. Secure /simple-stats
   - Added authentication requirement (was public)
2026-02-03 20:08:16 +00:00
rcourtman dd47cbe5b4 security: fix host token binding, AI findings scope, and DLQ credential exposure
1. Host agent link/unlink/delete now require settings:write scope
   - Prevents compromised host-agent:manage tokens from manipulating
     or deleting unrelated hosts
   - Host tokens scoped to one host can no longer affect other hosts

2. AI investigation endpoints now require ai:execute scope
   - /api/ai/findings/* was only protected by RequireAuth
   - Low-privilege tokens could read investigation details and chat logs

3. Notification DLQ endpoints now require settings:read/write scope
   - DLQ entries contain notification configs (webhooks, SMTP, etc.)
   - Prevents monitoring:read tokens from reading credential data
   - DLQ retry/delete operations require settings:write
2026-02-03 19:59:46 +00:00
rcourtman fdc99418d6 security: add authentication to /api/security/apply-restart endpoint
CRITICAL FIX: This endpoint previously allowed unauthenticated users to
trigger service restarts, which is a denial-of-service vulnerability.

Now requires:
- Authentication (CheckAuth) when auth is configured
- Admin role for proxy auth users
- settings:write scope for API tokens

Initial setup (no auth configured yet) remains accessible to allow
first-time security configuration to trigger restart.
2026-02-03 19:55:29 +00:00
rcourtman 832fda6c96 security: add scope checks to alerts, AI models, patrol status/stream, and remaining AI endpoints
- /api/alerts/* now requires monitoring:read scope
- /api/ai/models now requires ai:chat scope
- /api/ai/patrol/status and /api/ai/patrol/stream now require ai:execute scope
- /api/ai/patrol/findings now requires ai:execute scope
- /api/ai/remediation/* endpoints now require ai:execute scope
- /api/ai/circuit/status now requires ai:execute scope
- /api/ai/incidents/* now requires ai:execute scope
- /api/ai/question/* now requires ai:chat scope
- /api/ai/agents now requires ai:execute scope
- /api/ai/cost/summary now requires settings:read scope
2026-02-03 19:48:43 +00:00
rcourtman c295ee277f security: add scope checks to AI endpoints and mitigate CSWSH
- AI Intelligence endpoints (/api/ai/intelligence/*, /api/ai/forecast/*,
  /api/ai/unified/findings, etc.) now require ai:execute scope to prevent
  low-privilege tokens from reading sensitive intelligence data

- AI Knowledge endpoints (/api/ai/knowledge/*) now require ai:chat scope
  to prevent arbitrary guest data access across the fleet

- AI Debug Context (/api/ai/debug/context) now requires settings:read scope
  to prevent system prompt and infrastructure details leakage

- WebSocket origin check now validates peer IP is private when allowing
  private network origins, mitigating CSWSH attacks where a malicious page
  on the same LAN tries to hijack connections using victim's session cookie
2026-02-03 19:40:46 +00:00
rcourtman 2ebe65bbc5 security: add scope checks to AI Patrol and agent profile endpoints
- AI Patrol mutation endpoints (acknowledge, dismiss, suppress, snooze, resolve,
  findings/note, suppressions/*) now require ai:execute scope to prevent
  low-privilege tokens from blinding patrol by hiding/suppressing findings

- Agent profile admin endpoints (/api/admin/profiles/*) now require
  settings:write scope to prevent low-privilege tokens from modifying
  fleet-wide agent behavior
2026-02-03 19:29:56 +00:00
rcourtman 69e3286e5e security: fix AI OAuth scope bypass, approval replay attacks, and approval endpoint scope gating
- OAuth endpoints now require settings:write scope (not just admin)
- Approval endpoints now require ai:execute scope
- Added CommandHash to approvals for replay protection
- Approvals are now single-use (consumed on first use)
- consumeApprovalWithValidation validates command matches approval
2026-02-03 19:15:15 +00:00
rcourtman 43c696896f security: fix high severity authz issues (AI chat, patrol autonomy, discovery, host config) 2026-02-03 19:00:56 +00:00
rcourtman 4fdc0cae64 feat(reporting): enrich metric reports with detailed resource info 2026-02-03 18:51:27 +00:00
rcourtman 225da6eb39 security: strengthen public URL capture to enforce scope and admin checks 2026-02-03 18:49:42 +00:00
rcourtman 83382ee251 security: enforce scope checks on admin diagnostics endpoint 2026-02-03 18:44:55 +00:00