fix(daemon): bound a package workflow's tools by its accepted authority

This commit is contained in:
sam committed 2026-10-11 03:48:31 +11:00
1 parent 2be3314faa
commit 4ed4b7f9d7
6 files changed
+108 -6

No files matched your search

+3 -3
View File
@@ -31,7 +31,7 @@ type LoopRunner struct {
// Limits bounds the size of tool results fed back into the stage. The
// zero value applies no limits.
Limits ToolLimits
// AllowTools is the profile's allowlist over archie-added tools. Empty allows
// AllowTools is the allowlist over archie-added tools. Nil allows
// all. Capture tools and agentloop's built-in file tools are never
// filtered.
AllowTools []string
@@ -187,9 +187,9 @@ func makeCaptureHandler(spec agentrun.CaptureTool, captures map[string][]json.Ra
}
}
// allowedTools keeps the tools allow names; an empty allow keeps them all.
// allowedTools keeps the tools allow names; a nil allow keeps them all.
func allowedTools(set core.ToolSet, allow []string) core.ToolSet {
if len(allow) == 0 {
if allow == nil {
return set
}
kept := core.ToolSet{}
+1
View File
@@ -572,6 +572,7 @@ func (b *boot) buildDaemon() {
Bus: b.bus,
Forge: b.forgeClient,
Trees: b.trees,
PackageAuthorities: installedAuthorities{b.stateStoreGrants.Client},
Storage: b.storeBackend,
Log: log,
Tasks: b.natsClient,
+4 -1
View File
@@ -191,6 +191,9 @@ type Daemon struct {
IdentityRepository identity.Repository
RootIdentityID identity.IdentityID
// PackageAuthorities bounds the tools a package workflow's run is offered.
PackageAuthorities PackageAuthorities
// Playbooks are the loaded EDA playbooks, consulted before kind/label
// bindings when pinning a workflow. Nil means none.
Playbooks interface {
@@ -1954,7 +1957,7 @@ func (d *Daemon) runViaAgent(ctx context.Context, task *workflow.Task, repo conf
MCPServers: cfg.Tools.MCPServers,
RunCredential: credential,
WorkflowDefinition: task.WorkflowDefinitionYAML,
Tools: profile.Tools,
Tools: d.toolAllowlist(ctx, task, profile.Tools),
Harness: harness,
}
data, err := json.Marshal(req)
+45
View File
@@ -0,0 +1,45 @@
package daemon
import (
"context"
"slices"
"github.com/samcharles93/archie-core/internal/domain/storepkg"
"github.com/samcharles93/archie-core/internal/domain/workflow"
)
// PackageAuthorities answers what the operator accepted for an installed
// package. A package that is not installed, or not accepted, has none.
type PackageAuthorities interface {
AcceptedAuthority(ctx context.Context, name string) (storepkg.Authority, error)
}
// toolAllowlist is the tool allowlist a task runs with. nil offers every tool;
// a non-nil list offers exactly its members. A run of a package's workflow is
// bounded by the tools accepted for that package, so a missing, unaccepted or
// unreadable package offers none.
func (d *Daemon) toolAllowlist(ctx context.Context, task *workflow.Task, profileTools []string) []string {
name := workflow.PackageOf(task.WorkflowDefinitionYAML)
if name == "" {
if len(profileTools) == 0 {
return nil
}
return profileTools
}
var accepted []string
if d.PackageAuthorities != nil {
authority, err := d.PackageAuthorities.AcceptedAuthority(ctx, name)
if err != nil {
d.Log.Warn("package authority unavailable; offering no tools", "task", task.ID, "package", name, "err", err)
} else {
accepted = authority.Tools
}
}
allowed := []string{}
for _, tool := range accepted {
if len(profileTools) == 0 || slices.Contains(profileTools, tool) {
allowed = append(allowed, tool)
}
}
return allowed
}
+53
View File
@@ -0,0 +1,53 @@
package daemon
import (
"context"
"errors"
"log/slog"
"reflect"
"testing"
"github.com/samcharles93/archie-core/internal/domain/storepkg"
"github.com/samcharles93/archie-core/internal/domain/workflow"
)
type acceptedTools map[string]storepkg.Authority
func (a acceptedTools) AcceptedAuthority(_ context.Context, name string) (storepkg.Authority, error) {
if authority, ok := a[name]; ok {
return authority, nil
}
return storepkg.Authority{}, errors.New("not installed")
}
// TestToolAllowlistFollowsPackageAuthority pins that a package workflow is
// offered only the tools accepted for its package, and none when the package
// is missing or unaccepted, while an operator workflow keeps its profile's list.
func TestToolAllowlistFollowsPackageAuthority(t *testing.T) {
d := &Daemon{Log: slog.Default(), PackageAuthorities: acceptedTools{
"triage": {Tools: []string{"search", "fetch"}},
"unsigned": {},
}}
tests := []struct {
name string
yaml string
profile []string
want []string
}{
{"operator workflow without a profile list", "id: a\n", nil, nil},
{"operator workflow keeps its profile list", "id: a\n", []string{"x"}, []string{"x"}},
{"package workflow gets its accepted tools", "package: triage\nid: a\n", nil, []string{"search", "fetch"}},
{"profile narrows the accepted tools", "package: triage\nid: a\n", []string{"fetch", "shell"}, []string{"fetch"}},
{"profile cannot widen the accepted tools", "package: triage\nid: a\n", []string{"shell"}, []string{}},
{"package with nothing accepted", "package: unsigned\nid: a\n", nil, []string{}},
{"package that is gone", "package: gone\nid: a\n", nil, []string{}},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := d.toolAllowlist(context.Background(), &workflow.Task{WorkflowDefinitionYAML: tt.yaml}, tt.profile)
if !reflect.DeepEqual(got, tt.want) {
t.Fatalf("got %#v, want %#v", got, tt.want)
}
})
}
}
+2 -2
View File
@@ -28,8 +28,8 @@ type Request struct {
RunCredential string `json:"run_credential,omitempty"`
// WorkflowDefinition is the exact YAML pinned on Task before dispatch.
WorkflowDefinition string `json:"workflow_definition"`
// Tools is the agent profile's tool allowlist; empty allows every tool.
Tools []string `json:"tools,omitempty"`
// Tools is the tool allowlist: nil allows every tool, an empty list none.
Tools []string `json:"tools"`
// Harness, set for a Kit profile, runs every agent stage on the Kit's
// CLI instead of the built-in loop.
Harness *agentrun.HarnessSpec `json:"harness,omitempty"`