Skip to content

security: inherit operator-approved company grants for LLM-spawned tasks (#830) - #841

Open
c4nc wants to merge 1 commit into
BaaRai:mainfrom
c4nc:fix/spawn-company-egress-inheritance
Open

c4nc wants to merge 1 commit into
BaaRai:mainfrom
c4nc:fix/spawn-company-egress-inheritance

Conversation

@c4nc

@c4nc c4nc commented Dec 2, 2026

Copy link
Copy Markdown

Problem

Follows from #830 and refines the shape sketched in my supplement there. spawn_task hardcodes CompanyScopeByAgent: true, so every company link a chat-spawned task carries is stamped approved_by_operator=false — even when the operator had fully configured and approved that company's scope. The task starts with an empty egress allowlist and every connection 403s until the operator re-approves scope per task. #833 (open) warns about the symptom; this PR removes its most common cause.

The premise is the one migration 0025 itself established: company-level company_scope rows carry explicit operator consent (approved_by_operator, set only by the operator company API). But that consent was never consulted when an LLM selected the company at task creation.

Change

All of it in insertTaskCompanies (db/tasks.go) — no schema change, no server change, spawn_task keeps passing CompanyScopeByAgent: true:

  • A selected company whose scope inventory exists and is entirely operator-approved carries standing consent: its task link is inserted with approved_by_operator=true and its grant is frozen into task_scope_egress in the same transaction, exactly like an operator selection (AddOperatorScope semantics; the snapshot still copies 0025-approved rows only).
  • A company holding any agent-written (unapproved) row — the footprint of add_company_scope and the ScopeSentry sync — stays coverage-only, so the agent can never self-widen a spawn grant by appending one row to an operator company.
  • A company with no scope rows (an invented id, empty inventory) grants nothing.
  • Provenance is preserved: source stays agent; the approval column records who consented, row by row, auditable.

The pre-0025 self-grant worry (sandbox_scope_drift_test.go case 4, which pinned "agent spawn of an operator-approved company must mint NO egress") predates the approval column: after 0025 the address set behind a fully approved company is exactly what the operator entered — inheriting it introduces no new address. The drift guardrails stand and are extended: agent-appended rows keep the whole company coverage-only, and empty inventories grant nothing (new negative cases in that test).

Tests

  • db: TestSpawnInheritsFullyApprovedCompany — full/half/empty companies spawned in one call: link flags per company (true/false/false, all source=agent), snapshot holds exactly the full company's approved rows, nothing leaks from the half company's approved row or the empty company.
  • server: sandbox_scope_drift_test.go case 4 rewritten — agent spawn now inherits the fully approved company (allowlist carries its domain + canary /32; proxy and WebFetch allow), plus the two new negative cases (half-approved company coverage-only and denied; no-scope company grants nothing).
  • Against a real PostgreSQL: go test ./db ./intercept ./server -count=1 — db and intercept fully green; in server every scope/egress/gate test green. The six failing server tests (TestIsolation*AsRoot) fail identically on pristine e38f58d in the same container — pre-existing environment artifacts, untouched by this diff.
  • go build ./..., go vet, gofmt clean.

spawn_task stamps every company link approved_by_operator=false, so chat-spawned tasks start with an empty egress allowlist even for companies the operator fully approved (BaaRai#830; BaaRai#833 warns about the symptom). insertTaskCompanies now checks each selected company: one whose company_scope inventory exists and is entirely operator-approved carries standing consent - the link is inserted approved and the grant frozen in the same transaction, like an operator selection. Companies holding any unapproved row, or without scope rows, stay coverage-only: add_company_scope, the ScopeSentry sync and invented ids still cannot self-grant. source stays agent. Case 4 of sandbox_scope_drift_test is rewritten accordingly and gains two negative cases. Related: BaaRai#830, BaaRai#833.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant