Commit Graph

25 Commits

Author SHA1 Message Date
rcourtman
357f43f32e Harden AI tool sandboxing, agentexec sessions, and Patrol/Assistant isolation (#5077)
Hardens Pulse agentexec command transport, AI provider/tool sandboxing,
and Assistant/Patrol authorization boundaries:

- Bind agentexec sessions to organization and live connected agent token
ownership, reject NUL bytes in agent IDs, add write deadlines so stalled
agents cannot freeze dispatch, and enforce symlink-safe `/var/log` reads
with target-aware command policy.
- Sandbox AI read-only tools and providers: reject `lsblk --sysroot`,
bare hostnames in `ss` filters, sensitive path escapes, unbounded
`pulse_query` preallocation, unescaped `@path` attachments in Claude
subscription prompts, SSRF to broadcast/non-global-unicast targets in
`fetch_url`, Gemini key exposure, and command output leaks in failed
Codex turns.
- Enforce Assistant session ownership and handoff authority, bound
unknown-session abort tracking, prevent cross-org inventory leakage
after monitor reload, lock Patrol dismiss/resolve note steering behind
host-command authority, redact tool outputs from Patrol run history for
non-admins, protect saved AI provider keys on base URL changes, and
serialize AI settings updates.
2026-11-24 14:09:08 +00:00
rcourtman
92a16ba961 Harden AI subscription prompts, Gemini keys, and fetch_url SSRF
Close provider-layer file-read, credential-leak, error-leak, and SSRF gaps:

- Escape '@' as '\u0040' in subscriptionAgentPrompt and set CLAUDE_CODE_DISABLE_ATTACHMENTS=1 on Claude CLI invocations so untrusted text cannot trigger local file attachment expansion.
- Audit failed Codex subscription turns with rejectCodexAgentToolActivity and extract only CLI error/turn.failed messages via codexFailureDetail so raw event streams and tool output never leak into Patrol errors.
- Send Gemini API keys in the x-goog-api-key header instead of URL query strings and restrict Gemini client redirects to the same origin so transport and URL errors never expose the key.
- Add securityutil.IsSpecialUseInternalIP and block CGNAT (100.64.0.0/10), 192.0.0.0/24, 198.18.0.0/15, 0.0.0.0/8, and 240.0.0.0/4 in isBlockedFetchIP under the private-IP policy while keeping non-unicast addresses like 255.255.255.255 blocked.

Contract-Neutral: Security hardening of AI tool sandboxing, agentexec sessions, and Patrol/Assistant authorization without public contract delta
2026-11-24 12:28:48 +00:00
rcourtman
a138a6e1c1 Harden VMware inventory bounds, Proxmox JSON limits, and HTTPS probes
Bound vCenter inventory lists and nested JSON arrays before decoding,
prevent infinite recursion on cyclic placement parent chains, and bound
Proxmox guest-agent JSON responses before unmarshaling.

For availability probes, verify the HTTPS server certificate (trusted
chain or pinned SHA-256 fingerprint) before sending stored credentials,
header values, or request bodies unless explicitly opted out. Cap HTTP
probe response headers at 64 KiB and transport error strings at 240
bytes, and require re-entering write-only HTTP secrets when assigning a
new host agent to an availability check.

Contract-Neutral: security hardening and additive HTTPS probe TLS verification options
2026-11-24 11:59:33 +00:00
pulse-triage[bot]
0e231eff8d Use virtual time for the synthetic pinned-dial budget fixture
A retained standard proof missed the healthy third fake address under the existing 1.5-second budget. The fake dials only wait on context timers; drive this named fixture with synctest instead of host wall time. Preserve every original assertion and the exact budget and concurrency bounds, and additionally require the third address to win at 750ms. The failed wall-time sample stays adverse; its scheduling cause is unknown. No product timeout, chart SLO or live performance claim changes.

Contract-Neutral: This is a deterministic test-fixture correction only; production dialing and every timeout, fallback, concurrency and destination contract are unchanged.
Change-source: pulse-maintainer
2026-11-14 01:11:27 +00:00
pulse-triage[bot]
33183dc950 Keep appliance policy refusals distinct from ordinary dial failures
Retain genuine cancellation and approved-peer connection errors. Give VMware a fixed safe existing-category policy explanation instead of mislabeling a refused destination as an unreachable host. Strengthen consumer assertions to count accepted TCP sockets as well as requests.

Contract-Neutral: Correct existing appliance-policy failure handling without adding public fields, routes, scopes or categories, and retain the established transport/privacy contracts.
Change-source: pulse-maintainer
2026-11-14 01:00:07 +00:00
pulse-triage[bot]
1a156c8e33 Bind tenant appliance dials and saved polls to their destination policy
Validate each complete DNS answer at dial time and connect only to its numeric addresses, including TrueNAS WebSocket reconnects. Retain server-derived tenant save provenance for polling, ignore submitted policy metadata, preserve legacy/instance-managed behavior and keep TLS, pins and failed observations intact.

Contract-Neutral: Complete the existing tenant appliance-destination rule without changing public fields, routes, scopes, TLS, History or recovery contracts; new provenance is internal storage only and legacy records are unchanged.
Change-source: pulse-maintainer
2026-11-14 00:51:54 +00:00
rcourtman
e0a98e49f1 Limit the addresses organization admins can connect Pulse to
An organization's owner or admin manages that organization's connections,
availability checks and email settings, but is not the instance operator.
Those routes connect from the Pulse server itself, so on a multi-org or
hosted install the address should not be one of the server's own.

Requests that RequireOrgAdmin or RequireOrgManager admit without instance
authority now carry a tenant outbound policy. Node, connection probe,
availability, TrueNAS, vCenter and SMTP destinations are refused with 403
when they are loopback, link-local, unspecified, multicast or a cloud
metadata address, and a host name is refused unless every address it
resolves to passes. Private networks stay allowed for shared-process
organizations and provider client runtimes, where tenants' systems sit on
the LAN or behind a VPN, and are closed on Pulse Cloud. Availability
checks are held to the policy whatever their observation locations, since
agent-only checks run on the server when the external probe entitlement
lapses.

The TrueNAS and vCenter clients also stop following redirects to another
host, matching the same-origin rule the Proxmox clients already apply; an
HTTP to HTTPS upgrade on the same host still follows.

Instance administrators, and so every single-tenant install, are not
affected.
2026-11-13 22:33:06 +00:00
pulse-triage[bot]
d6e72532e3 Isolate guest fixtures and safely observe pinned loser closure
Keep typed guest-agent cases on the existing namespaced fixture identity so recycled loopback ports cannot inherit a previous synthetic guest cooldown. Add a forced shared-listener regression without clearing the production admission registry.

Set the pinned loser peer deadline before cancellation can close the pipe, exercise the already-closed ordering deterministically, and verify that the winning connection stays usable. No runtime, transport policy, cooldown or admission behaviour changes.

Contract-Neutral: Repository-run test fixture isolation and closure observation only; production guest and pinned-dial contracts are unchanged.
Change-source: pulse-maintainer
2026-10-24 00:54:09 +01:00
rcourtman
3c103f1263 Fix pinned notification connectivity and cancelled DNS lookups
Serial pinned-address dialing could spend the request deadline on a stalled
first address while a validated fallback was healthy. Share one bounded
two-worker dialer with restricted HTTP clients and retain cancellation in
webhook DNS admission and dialing.

Add real stalled-TCP and DNS cancellation controls, persistent queue verdict
readback, shared transport ownership and explicit proof routing.
2026-10-18 08:49:56 +01:00
Richard Courtman
d4ce19219c Block IPv6 transition addresses in SSRF guards (GHSA-8f8r-p75h-jwq5)
The net.IP predicates every SSRF guard is built from read only the literal
address bytes, so an IPv6 transition address smuggles an internal IPv4
destination past all of them. 64:ff9b::a9fe:a9fe reaches 169.254.169.254
while IsLoopback, IsPrivate, IsLinkLocalUnicast and To4 all report an
ordinary public address, defeating both the webhook URL validator and the
restricted outbound transport with the same input.

Add securityutil.EmbeddedIPv4Candidates, which unwraps NAT64 (RFC 6052
well-known and RFC 8215 local-use prefixes), 6to4, Teredo, ISATAP,
IPv4-compatible and IPv4-translated encodings, and run every candidate
through the caller's own policy in both layers. The embedded destination
inherits the outer policy rather than a stricter one, so a NAT64 address
wrapping a permitted public target stays permitted and AllowPrivateIPs /
AllowLoopback relax the embedded check the same way they relax the outer.

Reported by tonghuaroot.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-07-31 17:57:26 +01:00
rcourtman
c035c5b514 Cover the missing arms of the SSRF, clone and classifier guards
A second pass targeting PARTIALLY covered functions rather than untouched
ones, so every case here is an arm the existing suites never reached.
Percentages are per-function coverage, measured before and after.

- pkg/securityutil: the SSRF guards, which is where the uncovered arms
  actually matter. isCarrierGradeNATIPv4 and isLocalNetworkIP are pinned at
  the first and last address of 100.64.0.0/10 and just outside both ends,
  across loopback, link-local, every RFC1918 range and IPv6 unique-local.
  joinURLPath, IsLocalNetworkHost, resolveOutboundIPAddrs and
  cloneRestrictedTransport to 100 percent, resolvePermittedOutboundIPs to
  96.8, with the transport clone asserted independent of its source.
- internal/models: eleven deep-copy helpers from as low as 25 percent to 100.
  Every one asserts real independence, mutating each nested slice, map and
  pointer field of the clone and checking the original is untouched, which is
  the failure mode a deep-copy helper actually has.
- internal/alerts: metricClearThreshold 28.6 to 100, resourceTypeLabel and
  alertspecsMetricTriggered 50 to 100, the four canonical spec-id and
  tracking-key builders 66.7 to 100, inferCanonicalKindFromLegacyAlert to 100,
  and the backup-snapshot and ack-identity predicates.
- internal/servicediscovery: the four fingerprint generators to 100, each
  asserted for both stability and sensitivity; the three command builders and
  ValidateResourceID on their exact output and each rejection reason.
- internal/storagehealth: zfsScanActive and firstNonEmpty.

cephClusterSourceRank is deliberately left at 75 percent: its default arm is
unreachable because normalizeCephClusterSource can only return the two cases
above it. That is recorded rather than faked.

No source file is modified. Adversarial review returned no rejects and flagged
nine re-hit subtests; all nine were removed and every target function
re-measured at an identical percentage, proving they carried nothing.

PULSE_ALLOW_CONTRACT_NEUTRAL_COMMIT=test-only branch coverage, no source or contract change
2026-07-25 00:39:15 +01:00
rcourtman
4a2335ce7f fix(ai): harden local compatible providers 2026-07-24 12:35:31 +01:00
rcourtman
278673aa0f Add Go branch-coverage tests for twelve pure backend helpers
New *_branchcov0718_test.go files raise coverage of previously-uncovered pure
functions across ten packages. Covered areas include securityutil SSRF and URL
validation, truenas path and telemetry parse helpers, storagehealth SMART and
physical-disk risk assessment, vmware inventory sort keys and error classifiers,
servicediscovery token filtering and readiness, telemetry evidence-from-history,
models ToFrontend converters and frontend NormalizeCollections normalizers,
actionplanner type predicates and canonical resource-id sort, config API-token
accessors, and licensing state accessors.

Test-only, with no runtime or subsystem-contract change. Verified in a clean
worktree at HEAD with go vet and package tests green, gofmt clean, and every
named target function moved from 0 percent to covered.
2026-07-19 15:10:09 +01:00
rcourtman
64fb3d198d fix(securityutil): dial every permitted resolved IP instead of pinning the first
The restricted outbound dialer resolved a hostname, validated the results,
then dialed only the first permitted IP. When localhost resolves to ::1
ahead of 127.0.0.1 and the target service binds only 127.0.0.1 (Ollama's
default), the dial failed with 'connect: connection refused' even though
curl and browsers connect fine via address-family fallback. This broke the
AI provider setup quickstart: the blessed http://localhost:11434 Ollama URL
failed Pulse's connection test on IPv6-first hosts (setup-friction class of
#847/#1003).

Try each permitted IP from the validating resolution in order until one
connects. Every candidate is still validated against the outbound policy
from the same resolution, so the DNS-rebinding pinning guarantee is
unchanged. Fixes all consumers of the shared client (Ollama provider, OIDC,
SSO, connection probes, availability poller); api-contracts wording updated
to match. Live-verified against Ollama 0.32.1 bound to 127.0.0.1 only:
TestConnection via http://localhost:11434 failed before, passes after.
2026-07-17 23:35:45 +01:00
rcourtman
df4e02ef89 Add Go branch-coverage tests for models config securityutil and aicontracts helpers
Adds table-driven branch-coverage unit tests for previously uncovered pure
functions across internal/models, internal/config, pkg/securityutil and
pkg/aicontracts. New test files only, with no source changes.

Covers model collection normalizers, reflect-based metric deep-copy,
removed-host agent bookkeeping, report-schedule and entitlement-billing
normalization, effective AI control and Patrol autonomy resolution,
websocket-origin host normalization, and command-safety classifiers. 61
TestBranchCov functions in 8 files, all vet and gofmt clean.
2026-07-16 14:20:13 +01:00
rcourtman
47f2bdaed4 Add Go branch-coverage tests for pure config and helper packages
Adds table-driven branch-coverage unit tests for previously untested pure
helper functions across internal/alerts/config, internal/config,
internal/ai/safety, internal/ai/modelresolution, internal/operationreceipt,
internal/models, internal/securityutil and pkg/securityutil. New test files
only, with no source changes.

Covers alert-config normalization and validation, sensitive-path and
redaction classifiers, URL normalizers, provider model resolution,
operation-receipt decoding, credential masking, and account-to-org role
mapping. 57 TestBranchCov functions in 12 files, all vet and gofmt clean.
2026-07-16 10:19:51 +01:00
rcourtman
93fff4f1d8 Add an explicit operator override for plaintext HTTP to non-local Pulse hosts
Fleets on networks numbered from nominally public IP space (issue
#1522: an AD estate on 192.20.0.0/16) cannot pass the agent's
local-network plaintext heuristic, and the only workaround was pointing
a .internal DNS alias at the server, which bypasses the same control
less visibly than a flag would. --allow-plaintext-http
(PULSE_AGENT_ALLOW_PLAINTEXT_HTTP) records process-wide consent once at
agent startup before any module validates a URL, covers every agent
transport including the websocket command channel, warns at startup
that the API token travels in cleartext, defaults closed, and is never
emitted by generated install commands or settable by the server.
2026-07-14 16:42:02 +01:00
rcourtman
042e7ef966 Harden remaining CodeQL security boundaries 2026-07-09 19:46:40 +01:00
rcourtman
e7334e66e4 Allow local DNS agent HTTP URLs
Refs #1522
2026-07-06 13:53:19 +01:00
rcourtman
314429b879 Fix v5 agent update recovery
Issue: #1515
2026-07-05 10:08:19 +01:00
rcourtman
6344d17fd1 Allow local Pulse HTTP agent URLs
Refs #1505
2026-07-03 00:24:40 +01:00
rcourtman
b6f7091952 fix: block SSRF bypass through HTTP proxy in restricted outbound client
NewRestrictedOutboundHTTPClient validates target IPs via a custom
DialContext, but when an HTTP proxy is configured (HTTP_PROXY env var)
DialContext only validates the proxy's address — the actual target host
is never checked. This allows requests to cloud metadata service
addresses (169.254.169.254) and other blocked IPs through the proxy.

Add a restrictedRoundTripper wrapper that validates the request URL
hostname against resolvePermittedOutboundIP before forwarding. This
provides defense-in-depth that works regardless of proxy configuration,
while the existing DialContext guard continues to prevent DNS rebinding
for direct connections.
2026-06-26 13:05:23 +01:00
rcourtman
eb98c13896 Allow insecure dev HTTP agent runtime URLs 2026-04-23 13:48:54 +01:00
rcourtman
8a42bb432e Harden commercial callback and transport URL policy 2026-04-22 10:57:21 +01:00
rcourtman
9c8387be6f Export restricted outbound HTTP security helpers 2026-04-22 10:05:57 +01:00