mirror of
https://github.com/BaaRai/ARTEX.git
synced 2026-11-25 09:20:53 +08:00
The SDK file tools Read, Write, Edit, MultiEdit, LS, Glob and Grep run in the server process, which is root in the image, and took any absolute or relative path: Read returned /app/keys/jwt.key or the config file, and Write could plant a skill or rewrite the config past the approval gate. - agent/filetools.go: defaultTools replaces the seven tools for every agent kind (chat, main agent, planner, worker). Same names, prompts and schemas; every path goes through an os.Root on the run's working directory, opened component by component below the data directory, so absolute paths elsewhere, "..", symlinks leading out, a run directory swapped for a symlink and files with extra hard links are refused. Grep no longer starts ripgrep. The LLM connection test passes an empty tool list instead of nil (nil meant the unconfined defaults). - traffic: chmod the go-mitmproxy CA private key to 0600 after the proxy creates or loads it; the CA certificate stays readable. - server: the executor gets HOME and XDG_CACHE_HOME in <data>/exec-home, owned by it, on the bash shim, the MCP drop shim and the custom-tool credential path. - server: ARTEX_LLM_PROXY and ARTEX_LLM_BASE_URL can carry user:pass@; they are scrubbed and sealed with the other startup secrets. - docker: no-new-privileges for the artex service, setuid/setgid bits stripped in the image, PLAYWRIGHT_BROWSERS_PATH kept at root's cache. - db: the persistence approval seed inserts each rule only when no rule of that name exists, so a re-run does not duplicate rules. - Root-gated tests run the bash shim, a custom tool and an MCP stdio command as the executor and check the uid, a 0600 root file, the server's /proc environ and a cache write.
51 lines
2.3 KiB
Go
51 lines
2.3 KiB
Go
package db
|
|
|
|
import "fmt"
|
|
|
|
// seedPersistenceApprovalRules inserts the built-in approval rules for the platform
|
|
// tools that store something the agents load or run later (custom tools, MCP
|
|
// servers, skill files). Each call of those tools is an ask: the operator approves it
|
|
// in the console. Seeded once, behind its own settings flag, like the other built-in
|
|
// seeds, so a later disable by the operator is never undone on restart. No agent tool
|
|
// reads or edits intercept rules, so an agent cannot lower them.
|
|
func (d *DB) seedPersistenceApprovalRules() error {
|
|
if v, _, _ := d.GetSetting("intercept_persistence_rules_v1"); v == "done" {
|
|
return nil
|
|
}
|
|
rules := []struct {
|
|
name string
|
|
pattern string
|
|
message string
|
|
}{
|
|
{
|
|
name: "[built-in] Persistent change: custom tool",
|
|
pattern: `^(?:create_custom_tool|update_custom_tool)$`,
|
|
message: "Approval needed: the agent asks to create or change a custom tool. It is stored on the platform and its code runs on this server in later calls. Approve only code you have read.",
|
|
},
|
|
{
|
|
name: "[built-in] Persistent change: MCP server",
|
|
pattern: `^(?:create_mcp|update_mcp)$`,
|
|
message: "Approval needed: the agent asks to add or change an MCP server. A stdio entry starts its command on this server; an HTTP or SSE entry sends its headers to its URL.",
|
|
},
|
|
{
|
|
name: "[built-in] Persistent change: skill",
|
|
pattern: `^(?:create_skill|update_skill_file)$`,
|
|
message: "Approval needed: the agent asks to create or change a skill file. Every agent that sees the skill loads its content as instructions.",
|
|
},
|
|
}
|
|
// intercept_rules.name has no unique index, so ON CONFLICT cannot apply: the insert
|
|
// is conditional on the name instead. A start that stopped between these inserts
|
|
// and SetSetting re-runs them without duplicating a rule.
|
|
for _, r := range rules {
|
|
if _, err := d.Exec(`
|
|
INSERT INTO intercept_rules(name, enabled, priority, match_target, match_type, pattern, action, message, timeout_enabled, timeout_seconds, timeout_action)
|
|
SELECT $1, true, 95, 'tool_name', 'regex', $2, 'ask', $3, false, 60, 'deny'
|
|
WHERE NOT EXISTS (SELECT 1 FROM intercept_rules WHERE name = $1)`,
|
|
r.name, r.pattern, r.message,
|
|
); err != nil {
|
|
return fmt.Errorf("rule %q: %w", r.name, err)
|
|
}
|
|
}
|
|
return d.SetSetting("intercept_persistence_rules_v1", "done")
|
|
}
|