mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-25 01:10: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.
89 lines
2.8 KiB
Go
89 lines
2.8 KiB
Go
package intercept
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Autumn-27/artex/db"
|
|
)
|
|
|
|
const customToolApproval = `^(?:create_custom_tool|update_custom_tool)$`
|
|
|
|
func builtinAsk(enabled bool) db.InterceptRule {
|
|
return db.InterceptRule{
|
|
ID: 1, Name: "[built-in] Persistent change: custom tool", Enabled: enabled, Priority: 95,
|
|
MatchTarget: "tool_name", MatchType: "regex", Pattern: customToolApproval,
|
|
Action: "ask", Message: "approve the custom tool",
|
|
}
|
|
}
|
|
|
|
func TestPersistenceToolsAreSixNamedTools(t *testing.T) {
|
|
if len(PersistenceTools) != 6 {
|
|
t.Fatalf("got %d persistence tools, want 6", len(PersistenceTools))
|
|
}
|
|
for _, name := range PersistenceTools {
|
|
if !IsPersistenceTool(name) {
|
|
t.Fatalf("%s not recognised", name)
|
|
}
|
|
}
|
|
if IsPersistenceTool("Bash") {
|
|
t.Fatal("Bash is not a persistence tool")
|
|
}
|
|
}
|
|
|
|
func TestBuiltinAskAnswersPersistenceCall(t *testing.T) {
|
|
ic := New(nil)
|
|
ic.SetRulesForTest([]db.InterceptRule{builtinAsk(true)})
|
|
dec, ok := ic.MatchPersistence("create_custom_tool", []byte(`{"key":"x"}`))
|
|
if !ok || dec.Action != "ask" {
|
|
t.Fatalf("got %+v ok=%v, want an ask", dec, ok)
|
|
}
|
|
if dec.RuleName != "[built-in] Persistent change: custom tool" {
|
|
t.Fatalf("rule name = %q", dec.RuleName)
|
|
}
|
|
}
|
|
|
|
func TestPersistenceIgnoresOtherTools(t *testing.T) {
|
|
ic := New(nil)
|
|
ic.SetRulesForTest([]db.InterceptRule{builtinAsk(true)})
|
|
if _, ok := ic.MatchPersistence("Bash", []byte(`{"command":"create_custom_tool"}`)); ok {
|
|
t.Fatal("a tool outside PersistenceTools must not be answered here")
|
|
}
|
|
}
|
|
|
|
// An operator-disabled built-in rule is not loaded, so nothing answers the call.
|
|
func TestDisabledBuiltinAskDoesNotApply(t *testing.T) {
|
|
ic := New(nil)
|
|
ic.SetRulesForTest([]db.InterceptRule{builtinAsk(false)})
|
|
if _, ok := ic.MatchPersistence("create_custom_tool", nil); ok {
|
|
t.Fatal("a disabled rule must not answer")
|
|
}
|
|
}
|
|
|
|
// An allow rule at a higher priority cannot skip the built-in approval.
|
|
func TestUserAllowCannotBypassApproval(t *testing.T) {
|
|
ic := New(nil)
|
|
ic.SetRulesForTest([]db.InterceptRule{
|
|
{ID: 2, Name: "user allow all", Enabled: true, Priority: 500,
|
|
MatchTarget: "tool_name", MatchType: "regex", Pattern: `.*`, Action: "allow"},
|
|
builtinAsk(true),
|
|
})
|
|
dec, ok := ic.MatchPersistence("update_custom_tool", nil)
|
|
if !ok || dec.Action != "ask" {
|
|
t.Fatalf("got %+v ok=%v, want the approval to stand", dec, ok)
|
|
}
|
|
}
|
|
|
|
// A user deny that matches a persistence call wins over the built-in approval.
|
|
func TestUserDenyWinsOverApproval(t *testing.T) {
|
|
ic := New(nil)
|
|
ic.SetRulesForTest([]db.InterceptRule{
|
|
{ID: 3, Name: "user deny custom tools", Enabled: true, Priority: 10,
|
|
MatchTarget: "tool_name", MatchType: "regex", Pattern: `custom_tool`, Action: "deny"},
|
|
builtinAsk(true),
|
|
})
|
|
dec, ok := ic.MatchPersistence("create_custom_tool", nil)
|
|
if !ok || dec.Action != "deny" {
|
|
t.Fatalf("got %+v ok=%v, want deny", dec, ok)
|
|
}
|
|
}
|