mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-24 00:50:54 +08:00
GHSA-prm8-vw2v-wjwh: the agent command executor ran as root in the server's container and PID namespace, so it could read /app/keys and recover the server secrets from /proc/<pid>/environ. Deliverable 1, executor identity. Agent processes (Bash, the interactive shell, custom tools, stdio MCP servers) run as the uid/gid set by -exec-uid and -exec-gid (default 10001). Custom tools use SysProcAttr.Credential. Norma starts Bash and the shell itself, so a PATH shim (the server binary named bash) drops the identity before exec; MCP stdio commands run through the same binary in drop mode. The task and chat workspace trees are shared with the executor group (setgid, group rw, umask 002). The key files and the config file become root-only, and /app/keys is 0700 in the image. An explicit -exec-uid that cannot be applied stops the start; the default logs once that same-uid isolation is unavailable when the server is not root. Deliverable 2, sealed environment. On Linux, SealProcessEnv re-executes the server once with the secret variables removed from its environment block, passing the values through an inherited pipe. The new image restores them into the Go environment, so readers see the same configuration. Off Linux it logs that the environment is not sealed. Deliverable 3, approval gate. Custom tools, MCP servers and skill files (create_/update_ of custom tool and MCP, create_skill, update_skill_file) meet built-in ask rules seeded once (intercept_persistence_rules_v1). A user allow rule cannot skip them; a user deny still wins. The rules are data the agent cannot edit. Tests: resolution and refusal of root identities, drop command wrapping, sealed-environment encoding, and an end-to-end handoff test on Linux that checks the kernel environment block and a child process hold no secret names and that the values survive (empty and multi-line included). Approval matching is tested in intercept.
94 lines
2.8 KiB
Go
94 lines
2.8 KiB
Go
package server
|
||
|
||
import (
|
||
"context"
|
||
"os"
|
||
"path/filepath"
|
||
"testing"
|
||
|
||
"github.com/Autumn-27/artex/agent"
|
||
"github.com/Autumn-27/artex/db"
|
||
actool "github.com/Autumn-27/norma/tool"
|
||
)
|
||
|
||
// hasSkillTool reports whether the packed tool set contains the Skill meta-tool.
|
||
func hasSkillTool(tools []actool.CoreTool) bool {
|
||
for _, t := range tools {
|
||
if t.Name() == "Skill" {
|
||
return true
|
||
}
|
||
}
|
||
return false
|
||
}
|
||
|
||
// TestAssembleVisibleSkill verifies a filesystem skill made visible to an agent is
|
||
// packed into that agent's tool set (as the single Skill meta-tool) via the wired
|
||
// ToolAugment hook. Skills live on disk under skillDir; visibility is a per-agent
|
||
// (agent × skill_name) row keyed by the skill's directory name.
|
||
func TestAssembleVisibleSkill(t *testing.T) {
|
||
dsn, _, err := db.DSN()
|
||
if err != nil {
|
||
db.SkipPGUnavailable(t, err)
|
||
}
|
||
pg, err := db.Open(dsn)
|
||
if err != nil {
|
||
db.SkipPGUnavailable(t, err)
|
||
}
|
||
defer pg.Close()
|
||
|
||
// Filesystem skill fixture: <skillDir>/t-assemble/SKILL.md. The directory name
|
||
// (t-assemble) is the visibility key matched against AgentSkillNames.
|
||
skillDir := t.TempDir()
|
||
const skillName = "t-assemble"
|
||
if err := os.MkdirAll(filepath.Join(skillDir, skillName), 0o755); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
md := "---\nname: t-assemble\ndescription: do the thing\n---\ndo the thing"
|
||
if err := os.WriteFile(filepath.Join(skillDir, skillName, "SKILL.md"), []byte(md), 0o644); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
|
||
wireAgentAugment(pg, skillDir, nil, ExecPrivilege{})
|
||
t.Cleanup(func() { agent.SetToolAugment(nil) })
|
||
|
||
ag, _ := pg.GetAgentByKey("planner")
|
||
if ag == nil {
|
||
t.Fatal("planner agent missing")
|
||
}
|
||
|
||
// Isolate this test from whatever skill visibility the planner already has in the
|
||
// shared DB: clear it now, restore it on cleanup.
|
||
orig, _ := pg.AgentSkillNames(ag.ID)
|
||
if err := pg.SetAgentSkillVisibility(ag.ID, nil); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Cleanup(func() { _ = pg.SetAgentSkillVisibility(ag.ID, orig) })
|
||
|
||
// before: skill not visible → no Skill meta-tool
|
||
extra, _, cleanup := agent.ToolAugment()(context.Background(), "planner")
|
||
cleanup()
|
||
if hasSkillTool(extra) {
|
||
t.Fatalf("expected no Skill meta-tool before the skill is made visible")
|
||
}
|
||
|
||
// make the skill visible to planner
|
||
if err := pg.ToggleSkillVisibility(ag.ID, skillName, true); err != nil {
|
||
t.Fatal(err)
|
||
}
|
||
t.Cleanup(func() { _ = pg.ToggleSkillVisibility(ag.ID, skillName, false) })
|
||
|
||
// after: the Skill meta-tool is packed in
|
||
extra, _, cleanup = agent.ToolAugment()(context.Background(), "planner")
|
||
defer cleanup()
|
||
if !hasSkillTool(extra) {
|
||
t.Fatalf("expected the Skill meta-tool after making the skill visible")
|
||
}
|
||
|
||
// AugmentTools appends extra to base without filtering base
|
||
combined, _, c2 := agent.AugmentTools(context.Background(), "planner", nil)
|
||
defer c2()
|
||
if !hasSkillTool(combined) {
|
||
t.Fatalf("AugmentTools should surface the Skill meta-tool")
|
||
}
|
||
}
|