mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-12-03 13:11:05 +00:00
Review 6154399166 on #841: spawn_task inherited standing company consent for any LLM-selected fully approved company, never checking that the calling task was allowed to reach it. A task scoped to customer A, or a chat with no scope, could start a child on customer B with B's whole frozen egress and no operator decision - reversing the consent invariant the drift test pins. CreateTaskWithOptions now carries CompanyScopeCallerID, the id of the task running spawn_task (0 = chat session or direct API). Inheritance requires the company to be the caller's own: an operator-approved task_scope link on the caller, on top of the company's fully approved inventory. With no task caller nothing is auto-approved: the child stays coverage-only until the operator confirms, restoring the pre-#830 posture for unanchored spawns. The handler reads the caller id from the target scope whether or not the gate is on. Probes: TestSpawnWithoutTaskCallerDoesNotAutoApprove proven RED on the reviewed head; caller-boundary teeth shown by removing only the caller EXISTS clause (3 boundary assertions fail, guard case unaffected); drift case 4 now flows consent through an operator caller and a no-caller child task denies on proxy, WebFetch and browser. Verified in-container on real Postgres: ok db, ok intercept; ./server carries only the six known AsRoot container-noise failures. Related: #830, #833.
453 lines
20 KiB
Go
453 lines
20 KiB
Go
package server
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"net/netip"
|
|
"net/url"
|
|
"os"
|
|
"strconv"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/Autumn-27/artex/agent"
|
|
"github.com/Autumn-27/artex/db"
|
|
"github.com/Autumn-27/artex/sandbox"
|
|
actool "github.com/Autumn-27/norma/tool"
|
|
)
|
|
|
|
// TestSandboxScopeDriftBlockedAcrossProxyWebFetchAndBrowser verifies that
|
|
// agent-added (add_task_scope / AddAgentScope) and auto-added (insert_assets /
|
|
// AddAutoScope) task_scope rows are strictly coverage-only and NEVER grant
|
|
// egress to the sandbox proxy, WebFetch, or shared browser. Only operator-
|
|
// approved rows (AddOperatorScope / operator API) and operator-selected
|
|
// companies (TaskCreateOptions.CompanyIDs) grant egress, with strict domain
|
|
// suffix matching and deny-by-default when no approved scope exists.
|
|
func TestSandboxScopeDriftBlockedAcrossProxyWebFetchAndBrowser(t *testing.T) {
|
|
dsn := strings.TrimSpace(os.Getenv("ARTEX_PG_DSN"))
|
|
if dsn == "" {
|
|
t.Skip("ARTEX_PG_DSN not set")
|
|
}
|
|
pg, err := db.Open(dsn)
|
|
if err != nil {
|
|
db.SkipPGUnavailable(t, err)
|
|
}
|
|
t.Cleanup(func() { _ = pg.Close() })
|
|
|
|
agent.SetSandboxExecutor(&agent.SandboxExecutor{Mode: sandbox.ModeRequired})
|
|
t.Cleanup(func() { agent.SetSandboxExecutor(nil) })
|
|
|
|
// Local canary HTTP server representing a target IP reachable only when
|
|
// explicitly in ScopeCIDRs.
|
|
canary := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.Header().Set("Content-Type", "text/plain")
|
|
_, _ = w.Write([]byte("CANARY_REACHED"))
|
|
}))
|
|
t.Cleanup(canary.Close)
|
|
canaryHost, canaryPort, err := net.SplitHostPort(strings.TrimPrefix(canary.URL, "http://"))
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
canaryURL := "http://" + net.JoinHostPort(canaryHost, canaryPort) + "/probe"
|
|
|
|
// Helper: build a real sandbox HTTP egress proxy + WebFetch + sharedBrowserTool
|
|
// directly from taskSandboxRunInfo(pg, dataDir, taskID).
|
|
buildEnforcers := func(t *testing.T, taskID int64) (
|
|
info agent.SandboxRunInfo,
|
|
proxyCheck func(rawURL string) (int, error),
|
|
webFetchCheck func(rawURL string) (bool, string),
|
|
browserCheck func(rawURL string) (bool, string),
|
|
) {
|
|
t.Helper()
|
|
info = taskSandboxRunInfo(pg, t.TempDir(), strconv.FormatInt(taskID, 10))
|
|
pol, err := sandbox.NewEgressPolicy(info.TaskID, info.ScopeDomains, info.ScopeCIDRs, nil)
|
|
if err != nil {
|
|
t.Fatalf("NewEgressPolicy: %v", err)
|
|
}
|
|
// Deterministic offline resolver for domain suffix tests (resolves to public TEST-NET-3 IP).
|
|
pol.Resolver = func(_ context.Context, host string) ([]netip.Addr, error) {
|
|
return []netip.Addr{netip.MustParseAddr("203.0.113.99")}, nil
|
|
}
|
|
// Dialer that routes 203.0.113.99 to our local canary so allowed domain
|
|
// requests succeed without external internet access.
|
|
pol.Dialer = func(ctx context.Context, network, addr string) (net.Conn, error) {
|
|
h, _, _ := net.SplitHostPort(addr)
|
|
var d net.Dialer
|
|
if h == "203.0.113.99" {
|
|
return d.DialContext(ctx, network, net.JoinHostPort(canaryHost, canaryPort))
|
|
}
|
|
return d.DialContext(ctx, network, addr)
|
|
}
|
|
|
|
proxy := sandbox.NewEgressProxy(pol)
|
|
proxySrv := httptest.NewServer(proxy)
|
|
t.Cleanup(proxySrv.Close)
|
|
proxyURL, _ := url.Parse(proxySrv.URL)
|
|
httpClient := &http.Client{
|
|
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
|
|
Timeout: 5 * time.Second,
|
|
}
|
|
proxyCheck = func(rawURL string) (int, error) {
|
|
resp, err := httpClient.Get(rawURL)
|
|
if err != nil {
|
|
return 0, err
|
|
}
|
|
defer resp.Body.Close()
|
|
return resp.StatusCode, nil
|
|
}
|
|
|
|
// WebFetch and the browser build their own policy: the same offline
|
|
// resolver reaches it through the context (a failed lookup is a denial).
|
|
ctx := sandbox.WithResolver(agent.WithSandboxRunInfo(context.Background(), info), pol.Resolver)
|
|
wf := agent.NewWebFetchTool(ctx, "", "")
|
|
webFetchCheck = func(rawURL string) (bool, string) {
|
|
in, _ := json.Marshal(map[string]any{"url": rawURL})
|
|
res, err := wf.Call(ctx, in, &actool.ToolContext{})
|
|
if err != nil {
|
|
return false, err.Error()
|
|
}
|
|
return !res.IsError, res.Flatten()
|
|
}
|
|
|
|
innerBrowser := actool.Build(actool.Spec{
|
|
Name: "browser_navigate",
|
|
Description: "navigate",
|
|
Run: func(_ context.Context, _ json.RawMessage, _ *actool.ToolContext) (actool.Result, error) {
|
|
return actool.Text("NAVIGATED"), nil
|
|
},
|
|
})
|
|
br := &sharedBrowserTool{CoreTool: innerBrowser}
|
|
browserCheck = func(rawURL string) (bool, string) {
|
|
in, _ := json.Marshal(map[string]any{"url": rawURL})
|
|
res, err := br.Call(ctx, in, &actool.ToolContext{})
|
|
if err != nil {
|
|
return false, err.Error()
|
|
}
|
|
return !res.IsError, res.Flatten()
|
|
}
|
|
return
|
|
}
|
|
|
|
assertAllDenied := func(t *testing.T, label, targetURL string,
|
|
proxyCheck func(string) (int, error),
|
|
webFetchCheck func(string) (bool, string),
|
|
browserCheck func(string) (bool, string),
|
|
) {
|
|
t.Helper()
|
|
if code, err := proxyCheck(targetURL); err == nil && code != http.StatusForbidden {
|
|
t.Fatalf("%s: proxy unexpectedly allowed %s (HTTP %d)", label, targetURL, code)
|
|
}
|
|
if ok, body := webFetchCheck(targetURL); ok {
|
|
t.Fatalf("%s: WebFetch unexpectedly allowed %s (body=%q)", label, targetURL, body)
|
|
} else if !strings.Contains(body, "target-gate approval only clears the tool gate") {
|
|
t.Fatalf("%s: WebFetch denial missing non-silent gate/scope guidance: %q", label, body)
|
|
}
|
|
if ok, body := browserCheck(targetURL); ok {
|
|
t.Fatalf("%s: shared browser unexpectedly allowed %s (body=%q)", label, targetURL, body)
|
|
} else if !strings.Contains(body, "target-gate approval only clears the tool gate") {
|
|
t.Fatalf("%s: browser denial missing non-silent gate/scope guidance: %q", label, body)
|
|
}
|
|
}
|
|
|
|
suffix := strconv.FormatInt(time.Now().UnixNano(), 10)
|
|
as := pg.Assets()
|
|
|
|
// -----------------------------------------------------------------------
|
|
// Case 1: Unscoped task + add_task_scope (AddAgentScope) + insert_assets
|
|
// (AddAutoScope) + agent-added company -> ALL DENIED across proxy,
|
|
// WebFetch, and shared browser.
|
|
// -----------------------------------------------------------------------
|
|
tUnscoped, err := pg.CreateTaskWithOptions("unscoped-drift-"+suffix, "goal", db.TaskCreateOptions{})
|
|
if err != nil {
|
|
t.Fatalf("CreateTaskWithOptions unscoped: %v", err)
|
|
}
|
|
|
|
agentDom := "agent-drift-" + suffix + ".test"
|
|
autoDom := "auto-drift-" + suffix + ".test"
|
|
agentCompDom := "agent-co-" + suffix + ".test"
|
|
agentCompName := "AgentInjectedCo-" + suffix
|
|
_, _, _, _, _, err = pg.Companies().CreateCompanyWithScope(
|
|
agentCompName, "",
|
|
[]db.ScopeInput{
|
|
{Kind: "domain", Value: agentCompDom},
|
|
{Kind: "cidr", Value: canaryHost + "/32"},
|
|
},
|
|
"test",
|
|
true,
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("CreateCompanyWithScope agentComp: %v", err)
|
|
}
|
|
|
|
// Simulate prompt-injected agent calling add_task_scope & insert_assets:
|
|
if ts, err := as.AddAgentScope(tUnscoped.ID, "root_domain", agentDom, "injected domain", "agent"); err != nil || ts.ApprovedByOperator {
|
|
t.Fatalf("AddAgentScope domain: ts=%+v err=%v (must be approved_by_operator=false)", ts, err)
|
|
}
|
|
if ts, err := as.AddAgentScope(tUnscoped.ID, "ip", canaryHost, "injected ip", "agent"); err != nil || ts.ApprovedByOperator {
|
|
t.Fatalf("AddAgentScope ip: ts=%+v err=%v (must be approved_by_operator=false)", ts, err)
|
|
}
|
|
if ts, err := as.AddAgentScope(tUnscoped.ID, "company", agentCompName, "injected company", "agent"); err != nil || ts.ApprovedByOperator {
|
|
t.Fatalf("AddAgentScope company: ts=%+v err=%v (must be approved_by_operator=false)", ts, err)
|
|
}
|
|
// Even passing source="manual" to AddAgentScope must NOT grant operator approval.
|
|
if ts, err := as.AddAgentScope(tUnscoped.ID, "root_domain", "forged-manual-"+suffix+".test", "spoof", "manual"); err != nil || ts.ApprovedByOperator {
|
|
t.Fatalf("AddAgentScope manual spoof must stay approved_by_operator=false: ts=%+v err=%v", ts, err)
|
|
}
|
|
if err := as.AddAutoScope(tUnscoped.ID, "root_domain", autoDom, "", ""); err != nil {
|
|
t.Fatalf("AddAutoScope domain: %v", err)
|
|
}
|
|
if err := as.AddAutoScope(tUnscoped.ID, "ip", "", "", canaryHost); err != nil {
|
|
t.Fatalf("AddAutoScope ip: %v", err)
|
|
}
|
|
|
|
info1, proxy1, wf1, br1 := buildEnforcers(t, tUnscoped.ID)
|
|
if len(info1.ScopeDomains) != 0 || len(info1.ScopeCIDRs) != 0 {
|
|
t.Fatalf("scope drift! unapproved agent/auto rows leaked into sandbox allowlist: domains=%v cidrs=%v", info1.ScopeDomains, info1.ScopeCIDRs)
|
|
}
|
|
for _, target := range []string{
|
|
canaryURL,
|
|
"http://" + agentDom + "/",
|
|
"http://" + autoDom + "/",
|
|
"http://" + agentCompDom + "/",
|
|
"http://forged-manual-" + suffix + ".example.com/",
|
|
"http://169.254.169.254/latest/meta-data/",
|
|
} {
|
|
assertAllDenied(t, "unapproved-drift", target, proxy1, wf1, br1)
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
// Case 2: Operator-approved rows (AddOperatorScope) -> ALLOWED, with
|
|
// strict domain suffix enforcement (sub.approved allowed, evil-approved denied).
|
|
// -----------------------------------------------------------------------
|
|
approvedDom := "approved-" + suffix + ".test"
|
|
if ts, err := as.AddOperatorScope(tUnscoped.ID, "root_domain", approvedDom, "operator approved"); err != nil || !ts.ApprovedByOperator {
|
|
t.Fatalf("AddOperatorScope domain: ts=%+v err=%v", ts, err)
|
|
}
|
|
// Promoting the previously agent-added canaryHost IP via AddOperatorScope succeeds.
|
|
if ts, err := as.AddOperatorScope(tUnscoped.ID, "ip", canaryHost, "operator approved canary IP"); err != nil || !ts.ApprovedByOperator {
|
|
t.Fatalf("AddOperatorScope ip promote: ts=%+v err=%v", ts, err)
|
|
}
|
|
|
|
_, proxy2, wf2, br2 := buildEnforcers(t, tUnscoped.ID)
|
|
// Operator-approved IP allowed across proxy, WebFetch, and browser:
|
|
if code, err := proxy2(canaryURL); err != nil || code != http.StatusOK {
|
|
t.Fatalf("proxy should allow operator-approved IP %s, got code=%d err=%v", canaryURL, code, err)
|
|
}
|
|
if ok, body := wf2(canaryURL); !ok || !strings.Contains(body, "CANARY_REACHED") {
|
|
t.Fatalf("WebFetch should allow operator-approved IP %s, got ok=%v body=%q", canaryURL, ok, body)
|
|
}
|
|
if ok, body := br2(canaryURL); !ok || body != "NAVIGATED" {
|
|
t.Fatalf("browser should allow operator-approved IP %s, got ok=%v body=%q", canaryURL, ok, body)
|
|
}
|
|
// Operator-approved domain and strict subdomain allowed:
|
|
for _, okDomURL := range []string{"http://" + approvedDom + "/x", "http://sub." + approvedDom + "/y"} {
|
|
if code, err := proxy2(okDomURL); err != nil || code != http.StatusOK {
|
|
t.Fatalf("proxy should allow operator-approved domain/suffix %s, got code=%d err=%v", okDomURL, code, err)
|
|
}
|
|
if ok, body := br2(okDomURL); !ok || body != "NAVIGATED" {
|
|
t.Fatalf("browser should allow operator-approved domain/suffix %s, got ok=%v body=%q", okDomURL, ok, body)
|
|
}
|
|
}
|
|
// Strict domain suffix enforcement: lookalike prefix/suffix domains DENIED!
|
|
for _, badSuffixURL := range []string{
|
|
"http://evil" + approvedDom + "/",
|
|
"http://evil-" + approvedDom + "/",
|
|
"http://" + approvedDom + ".attacker.invalid/",
|
|
"http://" + agentDom + "/",
|
|
"http://" + agentCompDom + "/",
|
|
} {
|
|
assertAllDenied(t, "suffix-enforcement", badSuffixURL, proxy2, wf2, br2)
|
|
}
|
|
|
|
// -----------------------------------------------------------------------
|
|
// Case 3: Operator-selected company (TaskCreateOptions.CompanyIDs) ->
|
|
// ALLOWED for company domain/CIDR, while agent-added company on same task
|
|
// remains DENIED.
|
|
// -----------------------------------------------------------------------
|
|
opCompDom := "op-co-" + suffix + ".test"
|
|
opCompID, _, _, _, _, err := pg.Companies().CreateCompanyWithScope(
|
|
"OperatorSelectedCo-"+suffix, "",
|
|
[]db.ScopeInput{
|
|
{Kind: "domain", Value: opCompDom},
|
|
{Kind: "cidr", Value: canaryHost + "/32"},
|
|
},
|
|
"test",
|
|
true,
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("CreateCompanyWithScope opComp: %v", err)
|
|
}
|
|
tOpComp, err := pg.CreateTaskWithOptions("op-company-"+suffix, "goal", db.TaskCreateOptions{
|
|
CompanyIDs: []int64{opCompID},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateTaskWithOptions opComp: %v", err)
|
|
}
|
|
// Agent tries to attach a second unapproved company to the same task -> must NOT widen egress!
|
|
if ts, err := as.AddAgentScope(tOpComp.ID, "company", agentCompName, "agent widen company", "agent"); err != nil || ts.ApprovedByOperator {
|
|
t.Fatalf("AddAgentScope second company: ts=%+v err=%v", ts, err)
|
|
}
|
|
|
|
_, proxy3, wf3, br3 := buildEnforcers(t, tOpComp.ID)
|
|
// Operator-selected company domain/subdomain and IP allowed:
|
|
if code, err := proxy3("http://api." + opCompDom + "/v1"); err != nil || code != http.StatusOK {
|
|
t.Fatalf("proxy should allow operator-selected company subdomain, got code=%d err=%v", code, err)
|
|
}
|
|
if ok, body := br3("https://api." + opCompDom + "/v1"); !ok || body != "NAVIGATED" {
|
|
t.Fatalf("browser should allow operator-selected company subdomain, got ok=%v body=%q", ok, body)
|
|
}
|
|
if ok, body := wf3(canaryURL); !ok || !strings.Contains(body, "CANARY_REACHED") {
|
|
t.Fatalf("WebFetch should allow operator-selected company CIDR, got ok=%v body=%q", ok, body)
|
|
}
|
|
// Agent-added second company and lookalike suffix DENIED:
|
|
assertAllDenied(t, "agent-added-second-company", "http://"+agentCompDom+"/", proxy3, wf3, br3)
|
|
assertAllDenied(t, "op-company-bad-suffix", "http://evil-"+opCompDom+"/", proxy3, wf3, br3)
|
|
|
|
// -----------------------------------------------------------------------
|
|
// Case 4: Operator RetargetTask sets approved_by_operator=true for newHost
|
|
// and agent-spawned task with CompanyScopeByAgent=true leaves it false.
|
|
// -----------------------------------------------------------------------
|
|
oldRetargetHost := "old-inst-" + suffix + ".test"
|
|
newRetargetHost := "new-inst-" + suffix + ".test"
|
|
tRetarget, err := pg.CreateTaskWithOptions("retarget-"+suffix, "Test https://"+oldRetargetHost, db.TaskCreateOptions{})
|
|
if err != nil {
|
|
t.Fatalf("CreateTaskWithOptions retarget: %v", err)
|
|
}
|
|
if _, err := as.AddOperatorScope(tRetarget.ID, "subdomain", oldRetargetHost, "operator"); err != nil {
|
|
t.Fatalf("AddOperatorScope old host: %v", err)
|
|
}
|
|
if _, err := pg.RetargetTask(context.Background(), tRetarget.ID, oldRetargetHost, "https://"+newRetargetHost); err != nil {
|
|
t.Fatalf("RetargetTask: %v", err)
|
|
}
|
|
_, proxy4, wf4, br4 := buildEnforcers(t, tRetarget.ID)
|
|
if code, err := proxy4("http://" + newRetargetHost + "/"); err != nil || code != http.StatusOK {
|
|
t.Fatalf("proxy should allow operator-retargeted host %s, got code=%d err=%v", newRetargetHost, code, err)
|
|
}
|
|
if ok, body := br4("https://" + newRetargetHost + "/"); !ok || body != "NAVIGATED" {
|
|
t.Fatalf("browser should allow operator-retargeted host %s, got ok=%v body=%q", newRetargetHost, ok, body)
|
|
}
|
|
assertAllDenied(t, "old-retargeted-host-removed", "http://"+oldRetargetHost+"/", proxy4, wf4, br4)
|
|
|
|
// Agent-spawned task (spawn_task sets CompanyScopeByAgent=true) inherits a
|
|
// company whose whole inventory the operator approved (#830, on top of
|
|
// migration 0025) through the caller's trust boundary (#841, review
|
|
// 6154399166): tCaller holds the operator-approved link to opComp, so its
|
|
// spawn carries opComp's operator-entered domain and canary IP instead of
|
|
// the empty allowlist that made every connection from a chat-spawned task
|
|
// 403. Provenance stays agent; the approval column records that the
|
|
// consent predates the spawn.
|
|
tCaller, err := pg.CreateTaskWithOptions("caller-"+suffix, "goal", db.TaskCreateOptions{
|
|
CompanyIDs: []int64{opCompID},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateTaskWithOptions caller: %v", err)
|
|
}
|
|
tAgentSpawn, err := pg.CreateTaskWithOptions("agent-spawn-"+suffix, "goal", db.TaskCreateOptions{
|
|
CompanyIDs: []int64{opCompID},
|
|
CompanyScopeByAgent: true,
|
|
CompanyScopeCallerID: tCaller.ID,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateTaskWithOptions agent-spawn: %v", err)
|
|
}
|
|
info5, proxy5, wf5, _ := buildEnforcers(t, tAgentSpawn.ID)
|
|
if !containsStr(info5.ScopeDomains, opCompDom) || !containsStr(info5.ScopeCIDRs, canaryHost+"/32") {
|
|
t.Fatalf("agent-spawned task must inherit the fully approved company: domains=%v cidrs=%v", info5.ScopeDomains, info5.ScopeCIDRs)
|
|
}
|
|
if code, err := proxy5("http://api." + opCompDom + "/v1"); err != nil || code != http.StatusOK {
|
|
t.Fatalf("proxy should allow the inherited company subdomain, got code=%d err=%v", code, err)
|
|
}
|
|
if ok, body := wf5(canaryURL); !ok || !strings.Contains(body, "CANARY_REACHED") {
|
|
t.Fatalf("WebFetch should allow the inherited company IP, got ok=%v body=%q", ok, body)
|
|
}
|
|
|
|
// The inheritance requires ALL of the company's scope rows to be approved:
|
|
// one agent-written row (add_company_scope, ScopeSentry sync) keeps the
|
|
// whole company coverage-only, so the agent can never self-widen a spawn
|
|
// grant by appending one row to an operator company.
|
|
halfDom := "half-co-" + suffix + ".test"
|
|
halfID, _, _, _, _, err := pg.Companies().CreateCompanyWithScope("HalfApprovedCo-"+suffix, "",
|
|
[]db.ScopeInput{{Kind: "domain", Value: halfDom}}, "test", true)
|
|
if err != nil {
|
|
t.Fatalf("CreateCompanyWithScope halfComp: %v", err)
|
|
}
|
|
if _, err := pg.Exec(`INSERT INTO company_scope(company_id, kind, domain, raw, approved_by_operator)
|
|
VALUES ($1, 'domain', $2, $2, false)`, halfID, "agent-row-"+suffix+".test"); err != nil {
|
|
t.Fatalf("seed agent company_scope row: %v", err)
|
|
}
|
|
// Keep the trust boundary satisfied here, so this case tests the
|
|
// half-approved inventory itself and not an unreachable company.
|
|
tHalfCaller, err := pg.CreateTaskWithOptions("half-caller-"+suffix, "goal", db.TaskCreateOptions{
|
|
CompanyIDs: []int64{halfID},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateTaskWithOptions half-caller: %v", err)
|
|
}
|
|
tHalf, err := pg.CreateTaskWithOptions("half-spawn-"+suffix, "goal", db.TaskCreateOptions{
|
|
CompanyIDs: []int64{halfID},
|
|
CompanyScopeByAgent: true,
|
|
CompanyScopeCallerID: tHalfCaller.ID,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateTaskWithOptions half-spawn: %v", err)
|
|
}
|
|
info6, proxy6, wf6, br6 := buildEnforcers(t, tHalf.ID)
|
|
if len(info6.ScopeDomains) != 0 || len(info6.ScopeCIDRs) != 0 {
|
|
t.Fatalf("company holding an agent row must stay coverage-only: domains=%v cidrs=%v", info6.ScopeDomains, info6.ScopeCIDRs)
|
|
}
|
|
assertAllDenied(t, "half-approved-company", "http://"+halfDom+"/", proxy6, wf6, br6)
|
|
// A company with no scope rows at all grants nothing: an id the LLM
|
|
// invented, or an empty inventory, is not standing consent.
|
|
emptyID, _, _, _, _, err := pg.Companies().CreateCompanyWithScope("EmptyCo-"+suffix, "", nil, "test", true)
|
|
if err != nil {
|
|
t.Fatalf("CreateCompanyWithScope emptyComp: %v", err)
|
|
}
|
|
tEmptyCaller, err := pg.CreateTaskWithOptions("empty-caller-"+suffix, "goal", db.TaskCreateOptions{
|
|
CompanyIDs: []int64{emptyID},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateTaskWithOptions empty-caller: %v", err)
|
|
}
|
|
tEmpty, err := pg.CreateTaskWithOptions("empty-spawn-"+suffix, "goal", db.TaskCreateOptions{
|
|
CompanyIDs: []int64{emptyID},
|
|
CompanyScopeByAgent: true,
|
|
CompanyScopeCallerID: tEmptyCaller.ID,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateTaskWithOptions empty-spawn: %v", err)
|
|
}
|
|
info7, _, _, _ := buildEnforcers(t, tEmpty.ID)
|
|
if len(info7.ScopeDomains) != 0 || len(info7.ScopeCIDRs) != 0 {
|
|
t.Fatalf("company without scope rows must grant no egress: domains=%v cidrs=%v", info7.ScopeDomains, info7.ScopeCIDRs)
|
|
}
|
|
// Same fully approved company as case 4, spawn with no task caller (chat
|
|
// session or direct API): the trust boundary has nothing to inherit
|
|
// through, so nothing is auto-approved silently - the child keeps the
|
|
// empty allowlist until the operator confirms the link (#841, review
|
|
// 6154399166).
|
|
tNoCaller, err := pg.CreateTaskWithOptions("nocaller-"+suffix, "goal", db.TaskCreateOptions{
|
|
CompanyIDs: []int64{opCompID},
|
|
CompanyScopeByAgent: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("CreateTaskWithOptions nocaller-spawn: %v", err)
|
|
}
|
|
info8, proxy8, wf8, br8 := buildEnforcers(t, tNoCaller.ID)
|
|
if len(info8.ScopeDomains) != 0 || len(info8.ScopeCIDRs) != 0 {
|
|
t.Fatalf("spawn without a task caller must stay coverage-only: domains=%v cidrs=%v", info8.ScopeDomains, info8.ScopeCIDRs)
|
|
}
|
|
assertAllDenied(t, "no-caller-spawn", "http://api."+opCompDom+"/v1", proxy8, wf8, br8)
|
|
}
|
|
|
|
func containsStr(list []string, want string) bool {
|
|
for _, s := range list {
|
|
if s == want {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|