diff --git a/.claude/skills/connectors/SKILL.md b/.claude/skills/connectors/SKILL.md index 9c303133a5..67a5b9b312 100644 --- a/.claude/skills/connectors/SKILL.md +++ b/.claude/skills/connectors/SKILL.md @@ -181,7 +181,7 @@ binding grants, and `sandbox: true` is refused beside it (`session/connector_app Beside a sensitive connector (Nessy), a binding's write tool needs `require_approval`: the config is refused unless each tool it grants only reads (`read_only_tools`) or is held, and a `tool_patterns` binding needs an entry such as `*` that matches each pattern as written -(`api/configs.go`, `sensitiveBindingsComplaint`). In agent.yaml it is `require_approval:` on +(`connectors/sensitive`, `ConfigComplaint`; across a parent and its child agents, `GraphComplaint`). In agent.yaml it is `require_approval:` on the connector entry. Tools a caller declares at createSession are not checked. The caller runs them, or a person's device does (`executor: client`). The router sends a client tool's arguments to the caller on the events socket (`api/sessionws.go`). Every channel member can diff --git a/acceleration/internal/api/child_agents_sensitive_test.go b/acceleration/internal/api/child_agents_sensitive_test.go new file mode 100644 index 0000000000..2fb0d10482 --- /dev/null +++ b/acceleration/internal/api/child_agents_sensitive_test.go @@ -0,0 +1,197 @@ +//go:build integration + +package api + +import ( + "encoding/json" + "net/http" + "strconv" + "strings" + + "github.com/GetStream/Vision-Agents/acceleration/internal/harness" + "github.com/GetStream/Vision-Agents/acceleration/internal/store" +) + +// The graphs below are wired through the config store, past the API's checks, as a graph +// saved before the rule held across agents, or changed since, is stored. + +func (s *ChildAgentsSuite) TestADelegationIsRefusedWhenTheParentIsSensitiveAndAChildSendsOut() { + s.useInternalApp() + parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + writer := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}) + s.delegate(parent, map[string]AgentConfig{"ask_a": writer}) + + run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"}) + + s.refusedAll(run) + s.Contains(s.refusals(parent), strconv.Quote(parent.Name)+ + `'s connector binding "customers" binds "nessy", whose tools read private data, and connector binding "code" `+ + "of the agent "+strconv.Quote(writer.Name)+" can send data out with no person's approval") +} + +func (s *ChildAgentsSuite) TestADelegationIsRefusedWhenAChildIsSensitiveAndTheParentSendsOut() { + s.useInternalApp() + parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}) + reader := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + s.delegate(parent, map[string]AgentConfig{"ask_b": reader}) + + run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"}) + + s.refusedAll(run) + s.Contains(s.refusals(parent), strconv.Quote(reader.Name)+`'s connector binding "customers" binds "nessy"`) + s.Contains(s.refusals(parent), `and connector binding "code" of the agent `+strconv.Quote(parent.Name)+" can send data out") +} + +// Neither child alone breaks the rule, nor does the parent: the parent hands one child's +// answer to the other. +func (s *ChildAgentsSuite) TestADelegationIsRefusedWhenOneChildIsSensitiveAndASiblingSendsOut() { + s.useInternalApp() + parent := s.agentWith("fanning/fanning-model", nil) + reader := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + writer := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}) + s.delegate(parent, map[string]AgentConfig{"ask_a": reader, "ask_b": writer}) + + run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"}) + + s.refusedAll(run) + s.Contains(s.refusals(reader), strconv.Quote(reader.Name)+ + `'s connector binding "customers" binds "nessy", whose tools read private data, and connector binding "code" `+ + "of the agent "+strconv.Quote(writer.Name)+" can send data out") +} + +func (s *ChildAgentsSuite) TestADelegationIsRefusedWhenAChildsSandboxReachesTheNetworkBesideASensitiveParent() { + s.useInternalApp() + parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + coder := s.agentWith("echo/echo-model", map[string]any{"sandbox": "daytona", "sandbox_options": map[string]any{"network": true}}) + s.delegate(parent, map[string]AgentConfig{"ask_c": coder}) + + run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"}) + + s.refusedAll(run) + s.Contains(s.refusals(coder), strconv.Quote(parent.Name)+ + `'s connector binding "customers" binds "nessy", whose tools read private data, and the sandbox's network `+ + "access of the agent "+strconv.Quote(coder.Name)+" can send data out") + s.NotContains(s.refusals(coder), "require_approval", "a sandbox has no tool a require_approval could hold") +} + +// The parent's own sandbox is part of the graph: it can send out what a sensitive child answered. +func (s *ChildAgentsSuite) TestADelegationIsRefusedWhenTheParentsSandboxReachesTheNetworkBesideASensitiveChild() { + s.useInternalApp() + parent := s.agentWith("fanning/fanning-model", map[string]any{"sandbox": "daytona", "sandbox_options": map[string]any{"network": true}}) + reader := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + s.delegate(parent, map[string]AgentConfig{"ask_a": reader}) + + run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"}) + + s.refusedAll(run) + s.Contains(s.refusals(parent), strconv.Quote(reader.Name)+ + `'s connector binding "customers" binds "nessy", whose tools read private data, and the sandbox's network `+ + "access of the agent "+strconv.Quote(parent.Name)+" can send data out") +} + +// The false-positive side: a write tool a person must allow first sends nothing out unasked. +// A sibling deleted since the parent was saved is skipped, as its own call is refused. +func (s *ChildAgentsSuite) TestADelegationBesideASensitiveConnectorRunsWhenEachOutboundToolNeedsApproval() { + s.useInternalApp() + parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + held := sessionGitHubGranting("code", "create_issue") + held["require_approval"] = []string{"create_issue"} + writer := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{held}}) + deleted := s.agentWith("echo/echo-model", nil) + s.delegate(parent, map[string]AgentConfig{"ask_a": writer, "ask_c": deleted}) + s.Require().NoError(s.store.AgentConfigs.Delete(s.T().Context(), s.customerID(), deleted.Id)) + + run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"}) + + s.NotContains(run.FinalText, "was not run") + s.Contains(run.FinalText, "tool: be brief", "the held child answered") + s.Contains(run.FinalText, "tool: That did not work: the agent "+strconv.Quote(deleted.Name)+" behind ask_c no longer exists") +} + +// A child whose tool has the name of another tool is not offered, so it runs nothing a +// sibling could read. +func (s *ChildAgentsSuite) TestADelegationRunsBesideASensitiveChildTheParentDoesNotOffer() { + s.useInternalApp() + parent := s.agentWith("fanning/fanning-model", nil) + reader := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionNessy("customers")}}) + writer := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}) + s.delegate(parent, map[string]AgentConfig{"ask_a": writer}) + s.change(parent.Id, func(config *store.AgentConfig) { + config.Agents = append(config.Agents, store.ChildAgent{Config: reader.Name, Tool: harness.LoadSkillTool}) + }) + + run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"}) + + s.NotContains(run.FinalText, "was not run") + s.Contains(run.FinalText, "tool: be brief") +} + +// TestADelegationWithNoSensitiveConnectorRuns is the control: on the base, dca845c2e, the +// same graph answered the same (author-1.md, «Control probe»). +func (s *ChildAgentsSuite) TestADelegationWithNoSensitiveConnectorRuns() { + parent := s.agentWith("fanning/fanning-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}) + writer := s.agentWith("echo/echo-model", map[string]any{"connectors": []map[string]any{sessionGitHubGranting("code", "create_issue")}}) + s.delegate(parent, map[string]AgentConfig{"ask_a": writer}) + + run := s.run(CreateRunRequest{ConfigId: parent.Id, Input: "review this"}) + + s.NotContains(run.FinalText, "That did not work") + s.Contains(run.FinalText, "tool: be brief") +} + +// useInternalApp gives the test an app Stream marks internal, the only kind that sees nessy. +func (s *ChildAgentsSuite) useInternalApp() { + s.useApp(s.data.createAppAdmitting(store.AppSettings{InternalConnectors: new(true)})) +} + +// agentWith is a text agent config of the app answered by model, with fields. +func (s *ChildAgentsSuite) agentWith(model string, fields map[string]any) AgentConfig { + request := map[string]any{"name": "agent-" + s.utils.uuid(), "mode": "text", "llm": model, "instructions": "be brief"} + for key, value := range fields { + request[key] = value + } + status, payload := s.serverClient.call(http.MethodPost, "/v1/agents/configs", request) + s.Require().Equal(http.StatusCreated, status, string(payload)) + var created AgentConfig + s.Require().NoError(json.Unmarshal(payload, &created)) + return created +} + +// delegate makes parent call each of fanned: the config children names for it, or else an +// agent with no connector. +func (s *ChildAgentsSuite) delegate(parent AgentConfig, children map[string]AgentConfig) { + var agents []store.ChildAgent + for _, tool := range fanned { + child, ok := children[tool] + if !ok { + child = s.agentWith("echo/echo-model", nil) + } + agents = append(agents, store.ChildAgent{Config: child.Name, Tool: tool}) + } + s.change(parent.Id, func(config *store.AgentConfig) { config.Agents = agents }) +} + +// refusals is the log's lines about a refused delegation that name config, with what the tool error leaves out. +func (s *ChildAgentsSuite) refusals(config AgentConfig) string { + var lines []string + for line := range strings.SplitSeq(s.logged.String(), "\n") { + if strings.Contains(line, "a delegation was refused") && strings.Contains(line, config.Name) { + lines = append(lines, line) + } + } + // The text handler quotes the complaint, and its own quotes with it. + return strings.ReplaceAll(strings.Join(lines, "\n"), `\`, "") +} + +// refusedAll requires every delegation of the run refused, and the parent to have answered. What +// the model and the end user read names no binding, connector or tool: the log has the complaint. +func (s *ChildAgentsSuite) refusedAll(run Run) { + for _, tool := range fanned { + s.Contains(run.FinalText, "tool: That did not work: "+tool+" was not run: the agents it works with together read private data and can send data out", + "the graph breaks the rule whichever child is called") + } + s.NotContains(run.FinalText, "tool: be brief", "no child ran") + for _, name := range []string{"nessy", "customers", "create_issue", "binding", "connector", "sandbox", "require_approval"} { + s.NotContains(run.FinalText, name, "the tool error names nothing of a server-side config") + } +} diff --git a/acceleration/internal/api/child_agents_test.go b/acceleration/internal/api/child_agents_test.go index cfaa798645..265f12b825 100644 --- a/acceleration/internal/api/child_agents_test.go +++ b/acceleration/internal/api/child_agents_test.go @@ -14,10 +14,12 @@ import ( "testing" "time" + "github.com/GetStream/Vision-Agents/acceleration/internal/connectors/providers" "github.com/GetStream/Vision-Agents/acceleration/internal/harness" "github.com/GetStream/Vision-Agents/acceleration/internal/llm" "github.com/GetStream/Vision-Agents/acceleration/internal/llmrouter" "github.com/GetStream/Vision-Agents/acceleration/internal/routing" + "github.com/GetStream/Vision-Agents/acceleration/internal/sandbox/daytona/daytonatest" "github.com/GetStream/Vision-Agents/acceleration/internal/store" ) @@ -39,6 +41,8 @@ type ChildAgentsSuite struct { // offeredMu guards offered, the tools each request of offering was offered, by name. offeredMu sync.Mutex offered [][]string + // logged is what the router logs, for the tests about what a refused delegation logs. + logged *lockedLog } func TestChildAgentsSuite(t *testing.T) { @@ -81,7 +85,12 @@ func (s *ChildAgentsSuite) SetupSuite() { return &chainingLLM{}, nil }) } + s.logged = &lockedLog{} + s.logs = s.logged + s.daytona = daytonatest.Start(s.T()) s.RouterSuite.SetupSuite() + // The catalog, for the children that bind its connectors (child_agents_sensitive_test.go). + s.Require().NoError(s.store.ConnectorDefinitions.Seed(context.Background(), providers.FS)) } func (s *ChildAgentsSuite) SetupTest() { diff --git a/acceleration/internal/api/configs.go b/acceleration/internal/api/configs.go index 5ac7641e6f..474ee6cc5e 100644 --- a/acceleration/internal/api/configs.go +++ b/acceleration/internal/api/configs.go @@ -16,6 +16,7 @@ import ( "time" "github.com/GetStream/Vision-Agents/acceleration/internal/connectors/core" + "github.com/GetStream/Vision-Agents/acceleration/internal/connectors/sensitive" "github.com/GetStream/Vision-Agents/acceleration/internal/conversation" "github.com/GetStream/Vision-Agents/acceleration/internal/egress" "github.com/GetStream/Vision-Agents/acceleration/internal/guardrail" @@ -1046,111 +1047,9 @@ func sandboxOfConfig(config store.AgentConfig) *savedSandbox { Granted: slices.ContainsFunc(config.Connectors, func(binding store.ConnectorBinding) bool { return binding.Sandbox })}} } -// sensitiveBindingsComplaint refuses a config that binds a sensitive connector, one whose -// manifest says its tools read private data, together with a tool that sends data out: a -// model that reads untrusted text could be steered into sending out what it read («Nessy as -// a connector» on AI-1538, change 13). These send data out: -// - a binding whose connector has a source that does not say outbound: false, as one of its -// tools may write, unless each tool it grants is in the source's read_only_tools or its -// require_approval, which holds every call for a person to allow, and a binding with -// sandbox set, whose code calls the connector's whole API; -// - a sandbox that may reach the network. -// -// Only a binding's require_approval asks a person before a call is sent; the others ask -// nobody. It reads the config as it is about to be stored. -func SensitiveBindingsComplaint(ctx context.Context, definitions store.Definitions, customerID string, config store.AgentConfig) (string, bool, error) { - var sensitive *store.ConnectorBinding - var outbound, unheld []string - for i, binding := range config.Connectors { - definition, err := definitions.Latest(ctx, customerID, binding.ConnectorID) - // A forced connector delete leaves its bindings behind (store.refuseUndefined), and - // a binding to a connector with no definition opens nothing. - if errors.Is(err, store.ErrNoConnectorDefinition) { - continue - } - if err != nil { - return "", false, err - } - if definition.Manifest.Sensitive { - sensitive = &config.Connectors[i] - } - if tools, sends := bindingSendsOut(binding, definition.Manifest); sends { - outbound = append(outbound, fmt.Sprintf("connector binding %q", binding.Name)) - if len(tools) > 0 { - unheld = append(unheld, fmt.Sprintf("%q %s", binding.Name, strings.Join(tools, ", "))) - } - } - } - if sensitive == nil { - return "", true, nil - } - if config.Sandbox.Provider != "" && !config.Sandbox.Options.Isolated() { - outbound = append(outbound, "the sandbox's network access") - } - if len(outbound) == 0 { - return "", true, nil - } - message := fmt.Sprintf("connector binding %q binds %q, whose tools read private data, and %s can send data out "+ - "with no person's approval: take them out of this config", sensitive.Name, sensitive.ConnectorID, - strings.Join(outbound, ", ")) - if len(unheld) > 0 { - message += ", or add to each binding's require_approval its tools that do not only read: " + - strings.Join(unheld, "; ") - } - return message, false, nil -} - -// sensitiveBindingsComplaint is SensitiveBindingsComplaint over the server's store. +// sensitiveBindingsComplaint is sensitive.ConfigComplaint over the server's store. func (s *Server) sensitiveBindingsComplaint(ctx context.Context, customerID string, config store.AgentConfig) (string, bool, error) { - return SensitiveBindingsComplaint(ctx, s.store.ConnectorDefinitions, customerID, config) -} - -// bindingSendsOut reports whether a binding offers a tool that may send data out with nobody -// asked, and the names or patterns it grants such tools by: one of a source that does not say -// outbound: false, unless the binding grants it by name and the source lists it in -// read_only_tools, or its require_approval holds it, or the connector's API to sandbox code, -// which names none. A tool pattern matches tools only a session lists, so it sends out if any -// source may and its require_approval does not hold all it matches. A binding does not say -// which source a granted name comes from, so it sends out if any source may send it. A -// connector with no source offers no tool, and neither does a binding that grants none. -func bindingSendsOut(binding store.ConnectorBinding, manifest core.Manifest) ([]string, bool) { - if binding.Sandbox { - return nil, true - } - var unheld []string - if binding.ToolPatterns != nil { - if !slices.ContainsFunc(manifest.Sources, core.SourceRule.SendsOut) { - return nil, false - } - for _, pattern := range *binding.ToolPatterns { - if !holdsPattern(binding, pattern) { - unheld = append(unheld, pattern) - } - } - return unheld, len(unheld) > 0 - } - for _, tool := range binding.Tools { - if manifest.SendsOutTool(tool.Name) && !binding.RequiresApproval(tool.Name) { - unheld = append(unheld, tool.Name) - } - } - return unheld, len(unheld) > 0 -} - -// holdsPattern reports whether the binding's require_approval holds every tool a tool pattern -// matches: an entry does when it matches the pattern as written and has no wildcard or escape -// but *, such as * or create_* for create_*, as each * then also matches what the pattern's -// wildcards stand for. An entry's ? or class matches one character where the pattern's * may -// stand for several, an escaped \* only the pattern's own *, and the pattern's class may stand -// for a / that no * matches, so none of them is taken to hold the pattern. -func holdsPattern(binding store.ConnectorBinding, pattern string) bool { - if strings.Contains(pattern, "[") { - return false - } - return slices.ContainsFunc(binding.RequireApproval, func(entry string) bool { - matched, _ := path.Match(entry, pattern) - return matched && !strings.ContainsAny(entry, `?[\`) - }) + return sensitive.ConfigComplaint(ctx, s.store.ConnectorDefinitions, customerID, config) } // storedBindings turns the bindings a caller sent into what a config stores, as written. diff --git a/acceleration/internal/api/configs_test.go b/acceleration/internal/api/configs_test.go index 4b69cd2b81..453bf4de87 100644 --- a/acceleration/internal/api/configs_test.go +++ b/acceleration/internal/api/configs_test.go @@ -2392,7 +2392,7 @@ func (s *ConfigsSuite) TestABindingBesideNessyMayGrantExactlyTheToolsFlaggedRead } // read_only is read from the connector's latest revision, as a config save beside nessy reads -// it (SensitiveBindingsComplaint), not from the revision the connection pins: a connection +// it (sensitive.ConfigComplaint), not from the revision the connection pins: a connection // pinned to revision 1, which leaves search_documentation out of read_only_tools, flags it // read_only once revision 2 lists it, and a binding granting it sits beside nessy. func (s *ConfigsSuite) TestReadOnlyIsTheConnectorsLatestRevisionsAsAConfigSaveChecks() { @@ -2677,6 +2677,7 @@ func (s *ConfigsSuite) TestNessyBesideASandboxIsRefusedOnlyWhenItReachesTheNetwo s.Equal(http.StatusBadRequest, status, name) s.Contains(failure, "and the sandbox's network access can send data out", name) + s.NotContains(failure, "require_approval", "a sandbox has no tool a require_approval could hold") } } diff --git a/acceleration/internal/api/connection_tools.go b/acceleration/internal/api/connection_tools.go index b873f515a9..42d1d6e197 100644 --- a/acceleration/internal/api/connection_tools.go +++ b/acceleration/internal/api/connection_tools.go @@ -762,7 +762,7 @@ func (s *Server) listConnectionTools(ctx context.Context, request *connectionReq return nil, err } // The latest revision, not the one the connection pins: it is what a config save checks a - // binding beside a sensitive connector against (SensitiveBindingsComplaint). + // binding beside a sensitive connector against (sensitive.ConfigComplaint). // A connector the app can no longer see has no definition: a save skips such a binding, so // no tool of it is a read (read_only false) and the tools are still listed. definition, err := s.store.ConnectorDefinitions.Latest(ctx, connection.CustomerID, connection.ConnectorID) diff --git a/acceleration/internal/api/connector_approvals_test.go b/acceleration/internal/api/connector_approvals_test.go index f7a1732348..77c3190c85 100644 --- a/acceleration/internal/api/connector_approvals_test.go +++ b/acceleration/internal/api/connector_approvals_test.go @@ -533,7 +533,7 @@ func (s *SessionConnectorsSuite) TestACallBesideNessyIsHeldForApproval() { } // TestAPatternCallBesideNessyIsHeldByAWildcardEntry: the session holds the call through -// store.ConnectorBinding.RequiresApproval, not the config check's holdsPattern, so "*" must hold +// store.ConnectorBinding.RequiresApproval, not the config check's sensitive.holdsPattern, so "*" must hold // the ec* pattern's echo in the session too. func (s *SessionConnectorsSuite) TestAPatternCallBesideNessyIsHeldByAWildcardEntry() { s.useApp(s.data.createAppAdmitting(store.AppSettings{InternalConnectors: new(true)})) diff --git a/acceleration/internal/connectors/core/AGENTS.md b/acceleration/internal/connectors/core/AGENTS.md index 57fb07b80d..b85825f109 100644 --- a/acceleration/internal/connectors/core/AGENTS.md +++ b/acceleration/internal/connectors/core/AGENTS.md @@ -53,7 +53,7 @@ One word, one meaning, in code, docs and API alike. A name follows the Go auth l A manifest has `sources`, a `channel` block, or both: Linear has only `sources`, Telegram and Linq only `channel`, Slack and WhatsApp both. `sources` is what tools run against; `channel` is what the provider's inbound requests say: messages a person wrote (an inbound channel), signals about grants, or both. An inbound channel is never a kind of tool. The channel block lives in `channel.go`; `Manifest.Validate` checks it with the rest. -`sensitive: true` marks a connector that reads private data, and `sources[].outbound: false` says a source offers only tools that read, and `sources[].read_only_tools` names the ones that read on a source that also offers tools that write; left out, a tool may write and counts as sending data out. A config binding a sensitive connector is refused beside any binding granting a tool that may send out (`providers/AGENTS.md`, `sensitiveBindingsComplaint`). +`sensitive: true` marks a connector that reads private data, and `sources[].outbound: false` says a source offers only tools that read, and `sources[].read_only_tools` names the ones that read on a source that also offers tools that write; left out, a tool may write and counts as sending data out. A config binding a sensitive connector is refused beside any binding granting a tool that may send out (`providers/AGENTS.md`, `sensitive.ConfigComplaint`). | Term | What it is | In code | | --- | --- | --- | diff --git a/acceleration/internal/connectors/core/manifest.go b/acceleration/internal/connectors/core/manifest.go index b1022af65b..fbb05015ce 100644 --- a/acceleration/internal/connectors/core/manifest.go +++ b/acceleration/internal/connectors/core/manifest.go @@ -49,8 +49,8 @@ type Manifest struct { // every manifest stored before it stays as it was. Internal bool `yaml:"internal,omitempty" json:"internal,omitempty"` // Sensitive is a connector whose tools read private data. An agent config that binds one - // binds no tool that sends data out with no person's approval (sensitiveBindingsComplaint in - // internal/api/configs.go), since a model that reads untrusted text could be steered into + // binds no tool that sends data out with no person's approval (sensitive.ConfigComplaint in + // internal/connectors/sensitive), since a model that reads untrusted text could be steered into // sending out what it read («Nessy as a connector» on AI-1538, change 13). Left out of the // JSON when false, so the JSON of every manifest stored before it stays as it was. Sensitive bool `yaml:"sensitive,omitempty" json:"sensitive,omitempty"` @@ -121,7 +121,7 @@ type Manifest struct { // revision (connectorOf, internal/api/connectors.go); and sensitive and each source's outbound // and read_only_tools, which only the sensitive-connector check and a connection's tools' // read_only read, from the connector's latest revision whatever a connection pins -// (SensitiveBindingsComplaint, internal/api/configs.go; listConnectionTools, +// (ConfigComplaint, internal/connectors/sensitive; listConnectionTools, // internal/api/connection_tools.go); and sandbox.reads, which a session reads from the connector's latest // revision (sandboxGrant, internal/session/sandbox_grants.go). Any other field counts, the name // among them: a consent shows the pinned name (ConnectorConsents, internal/api/authorizations.go). diff --git a/acceleration/internal/connectors/providers/AGENTS.md b/acceleration/internal/connectors/providers/AGENTS.md index 1cbfb6eb44..e84bda8576 100644 --- a/acceleration/internal/connectors/providers/AGENTS.md +++ b/acceleration/internal/connectors/providers/AGENTS.md @@ -15,7 +15,7 @@ The built-in connector manifests: one `.yaml` per connector, in the schema ` - **Every vendor fact carries its source** in a comment beside it: a vendor page (with the date it was opened), a line of the prototype `internal/mcp/connectors.yaml` on `codex/connector-support` at `cf62af0d`, a row of the architecture doc (`acceleration/docs/connectors/architecture.md` on `connectors/planning`), or a fixture in `internal/connectors/core/testdata/manifests/`. A value with no source is marked `# unverified` and listed in the PR. - **`internal: true` hides a built-in from every app but Stream's own**: the lists, lookups, connections and OAuth clients of an app whose `apps.settings.internal_connectors` is `true` see it, any other app and any customer with no app row does not. A built-in takes `internal` from its latest revision at every revision, so making one internal (or public) later changes what every earlier revision shows; a custom definition is internal revision by revision. Check: `go test -tags integration -run 'TestStoreSuite/.*(Internal|Flag|Public)' ./internal/store`. - **`owner_email: true` makes a user-owned connection's first consent sign in as its owner** (`nessy.yaml` revision 4, AI-1543): the `email` captured from the `id_token` must be the one the app's backend last sent for that user in `X-Stream-User-Email`, compared without case; otherwise the consent ends `account_mismatch` and nothing is stored. It needs a required `email` capture from the `id_token`, so the scheme checks the token's `iss`, `aud` and `exp`; an `email_verified` capture, which refuses the consent when not `true`, must come from the `id_token` too, never the browser's `callback_query`. Check: `go test -tags integration -run 'TestAuthorizationsSuite/(TestAnOwners|TestAnotherPerson|TestAConsentIsRefusedWhen|TestAChatConsentIsChecked)' ./internal/api`, and `go test -run 'TestManifestSuite/TestOwnerEmail' ./internal/connectors/core`. -- **`sensitive: true` keeps outbound tools away from a connector that reads private data** (AI-1545, `nessy.yaml` revision 2). A config that binds one is refused with a 400 naming each tool that sends data out: a binding whose connector has a source that does not say `outbound: false`, a binding with `sandbox` set, and a sandbox that reaches the network (`sensitiveBindingsComplaint`, `internal/api/configs.go`). `sources[].outbound: false` says the server offers only tools that read, with a vendor source beside it; `sources[].read_only_tools` names the tools that only read on a server that also offers tools that write (`bigquery.yaml`, `google_docs.yaml`, `google_drive.yaml`), and a binding granting only those by name is not outbound; `tool_patterns` stay outbound. Left out, a tool may write, so it sends data out. Tools a caller declares at createSession are the caller's and are not checked (AI-1642): one that sends data on to others should carry `approval`. On a voice call the router asks the user; in text the caller's client must wait for `tool_approval` before it runs the tool. Check: `go test -tags integration -run 'TestConfigsSuite/(TestNessy|TestAConfigWithoutASensitive|TestAnUpdateOrAPatch|TestAnUpdateKeepingABindingToAForceDeleted)|TestSyncSuite/TestASyncedNessy' ./internal/api`. +- **`sensitive: true` keeps outbound tools away from a connector that reads private data** (AI-1545, `nessy.yaml` revision 2). A config that binds one is refused with a 400 naming each tool that sends data out: a binding whose connector has a source that does not say `outbound: false`, a binding with `sandbox` set, and a sandbox that reaches the network (`ConfigComplaint`, `internal/connectors/sensitive`). `sources[].outbound: false` says the server offers only tools that read, with a vendor source beside it; `sources[].read_only_tools` names the tools that only read on a server that also offers tools that write (`bigquery.yaml`, `google_docs.yaml`, `google_drive.yaml`), and a binding granting only those by name is not outbound; `tool_patterns` stay outbound. Left out, a tool may write, so it sends data out. Tools a caller declares at createSession are the caller's and are not checked (AI-1642): one that sends data on to others should carry `approval`. On a voice call the router asks the user; in text the caller's client must wait for `tool_approval` before it runs the tool. Check: `go test -tags integration -run 'TestConfigsSuite/(TestNessy|TestAConfigWithoutASensitive|TestAnUpdateOrAPatch|TestAnUpdateKeepingABindingToAForceDeleted)|TestSyncSuite/TestASyncedNessy' ./internal/api`. - **`scopes.covered_by` names, for a scope a tool needs, the broader scopes that meet it**, each with the vendor page saying the broader scope gives all the needed one gives (`google_drive.yaml` revision 6 and `google_docs.yaml` revision 5: `drive` covers `drive.file` and `documents`). Validate takes a grant holding one as holding the need, and a tool whose need an asked scope covers is offered (`core.ScopePolicy.Meets`). A scope a tool's page takes that gives less, such as Drive's `drive.appdata`, is not listed. A connection on an earlier revision gets it at its next consent. Check: `go test -run 'TestToolsetSuite/TestAGrantOfDrive' ./internal/connectors/providers`. - **Every id here is a provider name the core may not spell.** `TestCoreNamesNoProvider` (`internal/connectors/core/guard_test.go`) reads the ids from this directory into its deny list. - **No Go here beyond the embed and its tests** for now. A provider's hook (`hooks:` in a manifest) is the only Go a provider may need, and it is added with the hook registry, not before. diff --git a/acceleration/internal/connectors/providers/nessy.yaml b/acceleration/internal/connectors/providers/nessy.yaml index 547243be61..eb0a89f14d 100644 --- a/acceleration/internal/connectors/providers/nessy.yaml +++ b/acceleration/internal/connectors/providers/nessy.yaml @@ -22,7 +22,7 @@ internal: true # [design] change 13 (AI-1545): Nessy's tools read Stream's customer data, so an agent config # that binds it may bind no tool that sends data out with no person's approval, such as another # connector's write tool, an MCP server, a plugin or a sandbox that reaches the network -# (internal/api/configs.go, sensitiveBindingsComplaint). A write tool beside it needs its +# (internal/connectors/sensitive, ConfigComplaint). A write tool beside it needs its # binding's require_approval. sensitive: true setup: diff --git a/acceleration/internal/connectors/sensitive/AGENTS.md b/acceleration/internal/connectors/sensitive/AGENTS.md new file mode 100644 index 0000000000..d0ded8c82b --- /dev/null +++ b/acceleration/internal/connectors/sensitive/AGENTS.md @@ -0,0 +1,10 @@ +# internal/connectors/sensitive + +The rule that keeps a connector whose manifest says `sensitive: true` (its tools read private data) away from what may send data out with no person's approval: a binding to a source that does not say `outbound: false` (unless each tool it grants is in `read_only_tools` or its `require_approval`), a binding with `sandbox` set, and a sandbox that reaches the network. + +- `ConfigComplaint` checks one agent config. Config writes call it (`internal/api`: create, update, patch, sync), so a config that breaks it is a 400. +- `GraphComplaint` checks a parent and its child agents as one config. A parent hands its input to each child and reads each answer, so what one reads may reach any other, a sibling's tools included. `childRunner.Run` (`internal/session/child_agents.go`) calls it on every delegation, with the parent as it runs and each child as stored now, and refuses a delegation that breaks it with a tool error the model reads. + +It lives here, not in `internal/api`, because `internal/api` imports `internal/session`, and both need it. It reads only the store and the manifest model. + +Check: `go test -tags integration -run 'TestChildAgentsSuite/TestADelegation|TestConfigsSuite/TestNessy' ./internal/api`. diff --git a/acceleration/internal/connectors/sensitive/CLAUDE.md b/acceleration/internal/connectors/sensitive/CLAUDE.md new file mode 100644 index 0000000000..43c994c2d3 --- /dev/null +++ b/acceleration/internal/connectors/sensitive/CLAUDE.md @@ -0,0 +1 @@ +@AGENTS.md diff --git a/acceleration/internal/connectors/sensitive/sensitive.go b/acceleration/internal/connectors/sensitive/sensitive.go new file mode 100644 index 0000000000..e646536eb5 --- /dev/null +++ b/acceleration/internal/connectors/sensitive/sensitive.go @@ -0,0 +1,165 @@ +// Package sensitive keeps a connector whose tools read private data away from tools that send +// data out, in one agent config and across a parent and the child agents it hands work to. +package sensitive + +import ( + "context" + "errors" + "fmt" + "path" + "slices" + "strings" + + "github.com/GetStream/Vision-Agents/acceleration/internal/connectors/core" + "github.com/GetStream/Vision-Agents/acceleration/internal/store" +) + +// ConfigComplaint refuses a config that binds a sensitive connector, one whose manifest says +// its tools read private data, together with a tool that sends data out: a model that reads +// untrusted text could be steered into sending out what it read («Nessy as a connector» on +// AI-1538, change 13). These send data out: +// - a binding whose connector has a source that does not say outbound: false, as one of its +// tools may write, unless each tool it grants is in the source's read_only_tools or its +// require_approval, which holds every call for a person to allow, and a binding with +// sandbox set, whose code calls the connector's whole API; +// - a sandbox that may reach the network. +// +// Only a binding's require_approval asks a person before a call is sent; the others ask +// nobody. It reads the config as it is about to be stored. +func ConfigComplaint(ctx context.Context, definitions store.Definitions, customerID string, config store.AgentConfig) (string, bool, error) { + found, err := exposureOf(ctx, definitions, customerID, config) + if err != nil { + return "", false, err + } + if found.sensitive == nil || len(found.outbound) == 0 { + return "", true, nil + } + message := fmt.Sprintf("connector binding %q binds %q, whose tools read private data, and %s can send data out "+ + "with no person's approval: take them out of this config", found.sensitive.Name, found.sensitive.ConnectorID, + strings.Join(found.outbound, ", ")) + if len(found.unheld) > 0 { + message += ", or add to each binding's require_approval its tools that do not only read: " + + strings.Join(found.unheld, "; ") + } + return message, false, nil +} + +// GraphComplaint is ConfigComplaint over a parent and its child agents taken as one config: a +// parent hands its input to each child and reads each child's answer, so what one of them +// reads may reach any other, a sibling's tools included, through the parent. +func GraphComplaint(ctx context.Context, definitions store.Definitions, customerID string, configs []store.AgentConfig) (string, bool, error) { + var sensitive *store.ConnectorBinding + var holder string + var outbound, unheld []string + for _, config := range configs { + found, err := exposureOf(ctx, definitions, customerID, config) + if err != nil { + return "", false, err + } + if found.sensitive != nil { + sensitive, holder = found.sensitive, config.Name + } + for _, out := range found.outbound { + outbound = append(outbound, fmt.Sprintf("%s of the agent %q", out, config.Name)) + } + for _, tools := range found.unheld { + unheld = append(unheld, fmt.Sprintf("the agent %q's %s", config.Name, tools)) + } + } + if sensitive == nil || len(outbound) == 0 { + return "", true, nil + } + message := fmt.Sprintf("the agent %q's connector binding %q binds %q, whose tools read private data, and %s "+ + "can send data out with no person's approval, and a parent and its child agents pass on to each other "+ + "what they read: take them out of these agents", holder, sensitive.Name, sensitive.ConnectorID, + strings.Join(outbound, ", ")) + if len(unheld) > 0 { + message += ", or add to each binding's require_approval its tools that do not only read: " + + strings.Join(unheld, "; ") + } + return message, false, nil +} + +// exposure is what one config holds that the rule weighs: a binding to a sensitive connector, +// what may send data out, and the tools by binding that a require_approval would hold. +type exposure struct { + sensitive *store.ConnectorBinding + outbound []string + unheld []string +} + +func exposureOf(ctx context.Context, definitions store.Definitions, customerID string, config store.AgentConfig) (exposure, error) { + var found exposure + for i, binding := range config.Connectors { + definition, err := definitions.Latest(ctx, customerID, binding.ConnectorID) + // A forced connector delete leaves its bindings behind (store.refuseUndefined), and + // a binding to a connector with no definition opens nothing. + if errors.Is(err, store.ErrNoConnectorDefinition) { + continue + } + if err != nil { + return exposure{}, err + } + if definition.Manifest.Sensitive { + found.sensitive = &config.Connectors[i] + } + if tools, sends := bindingSendsOut(binding, definition.Manifest); sends { + found.outbound = append(found.outbound, fmt.Sprintf("connector binding %q", binding.Name)) + if len(tools) > 0 { + found.unheld = append(found.unheld, fmt.Sprintf("%q %s", binding.Name, strings.Join(tools, ", "))) + } + } + } + if config.Sandbox.Provider != "" && !config.Sandbox.Options.Isolated() { + found.outbound = append(found.outbound, "the sandbox's network access") + } + return found, nil +} + +// bindingSendsOut reports whether a binding offers a tool that may send data out with nobody +// asked, and the names or patterns it grants such tools by: one of a source that does not say +// outbound: false, unless the binding grants it by name and the source lists it in +// read_only_tools, or its require_approval holds it, or the connector's API to sandbox code, +// which names none. A tool pattern matches tools only a session lists, so it sends out if any +// source may and its require_approval does not hold all it matches. A binding does not say +// which source a granted name comes from, so it sends out if any source may send it. A +// connector with no source offers no tool, and neither does a binding that grants none. +func bindingSendsOut(binding store.ConnectorBinding, manifest core.Manifest) ([]string, bool) { + if binding.Sandbox { + return nil, true + } + var unheld []string + if binding.ToolPatterns != nil { + if !slices.ContainsFunc(manifest.Sources, core.SourceRule.SendsOut) { + return nil, false + } + for _, pattern := range *binding.ToolPatterns { + if !holdsPattern(binding, pattern) { + unheld = append(unheld, pattern) + } + } + return unheld, len(unheld) > 0 + } + for _, tool := range binding.Tools { + if manifest.SendsOutTool(tool.Name) && !binding.RequiresApproval(tool.Name) { + unheld = append(unheld, tool.Name) + } + } + return unheld, len(unheld) > 0 +} + +// holdsPattern reports whether the binding's require_approval holds every tool a tool pattern +// matches: an entry does when it matches the pattern as written and has no wildcard or escape +// but *, such as * or create_* for create_*, as each * then also matches what the pattern's +// wildcards stand for. An entry's ? or class matches one character where the pattern's * may +// stand for several, an escaped \* only the pattern's own *, and the pattern's class may stand +// for a / that no * matches, so none of them is taken to hold the pattern. +func holdsPattern(binding store.ConnectorBinding, pattern string) bool { + if strings.Contains(pattern, "[") { + return false + } + return slices.ContainsFunc(binding.RequireApproval, func(entry string) bool { + matched, _ := path.Match(entry, pattern) + return matched && !strings.ContainsAny(entry, `?[\`) + }) +} diff --git a/acceleration/internal/session/child_agents.go b/acceleration/internal/session/child_agents.go index fa00ec77db..4f69516078 100644 --- a/acceleration/internal/session/child_agents.go +++ b/acceleration/internal/session/child_agents.go @@ -11,6 +11,7 @@ import ( "time" "github.com/GetStream/Vision-Agents/acceleration/internal/agent" + "github.com/GetStream/Vision-Agents/acceleration/internal/connectors/sensitive" "github.com/GetStream/Vision-Agents/acceleration/internal/harness" "github.com/GetStream/Vision-Agents/acceleration/internal/llm" "github.com/GetStream/Vision-Agents/acceleration/internal/routing" @@ -130,6 +131,15 @@ func (r *childRunner) Run(ctx context.Context, call llm.ToolCall) ([]llm.Content case len(config.Agents) > 0: return nil, fmt.Errorf("the agent %q behind %s calls agents of its own", child.Config, call.Name) } + if message, ok, err := r.sensitiveComplaint(ctx, config); err != nil { + return nil, err + } else if !ok { + // The complaint names bindings, connectors and tools of server-side configs: the log + // has it, and the model, whose words the end user reads, gets a sentence that names none. + r.manager.logger.Warn("a delegation was refused: the agent and its children break the sensitive connector rule", + "config", r.spec.ConfigID, "tool", call.Name, "complaint", message) + return nil, fmt.Errorf("%s was not run: the agents it works with together read private data and can send data out", call.Name) + } spec := FromConfig(config) spec.CustomerID = r.spec.CustomerID @@ -165,6 +175,33 @@ func (r *childRunner) Run(ctx context.Context, call llm.ToolCall) ([]llm.Content return llm.TextParts(run.FinalText), nil } +// sensitiveComplaint is sensitive.GraphComplaint over the parent as it runs, called and every +// other child the parent offers as the store holds it now: a stored graph may break the rule, +// having been saved before the rule held across agents or changed since, as a child can be. +func (r *childRunner) sensitiveComplaint(ctx context.Context, called store.AgentConfig) (string, bool, error) { + configs := []store.AgentConfig{{ + Name: r.spec.AgentName, Connectors: r.spec.ConnectorBindings, + Sandbox: store.AgentSandbox{Provider: r.spec.Sandbox, Options: r.spec.SandboxOptions}, + }, called} + read := map[string]bool{called.Name: true} + for _, child := range r.spec.Agents { + if _, offered := r.children[child.Tool]; !offered || read[child.Config] { + continue + } + read[child.Config] = true + config, err := r.manager.options.Store.AgentConfigs.GetByName(ctx, r.spec.CustomerID, child.Config) + // A child deleted since runs nothing, as its own call says. + if errors.Is(err, store.ErrNoAgentConfig) { + continue + } + if err != nil { + return "", false, err + } + configs = append(configs, config) + } + return sensitive.GraphComplaint(ctx, r.manager.options.Store.ConnectorDefinitions, r.spec.CustomerID, configs) +} + // childEnded is a child given up on before it answered. func childEnded(tool string, err error) error { if errors.Is(err, context.DeadlineExceeded) {