Files
cursor-agent-api-proxy/scripts/bootstrap-cursor.sh
T
Ubuntu c0d758249c security: split internal/edge access, harden sandbox, fix follow-up matching
- server: two listeners — :4646 internal (PROXY_INTERNAL_TOKEN only,
  X-Authentik-Username no longer trusted) and :4647 edge (Authentik
  outpost only; requires X-Authentik-Username; NetworkPolicy-restricted)
- session-manager: strip PROXY_INTERNAL_TOKEN & friends from the ACP
  child env (allowlist + proxy vars), dedicated agent HOME, resolved
  tool_call tracking so findSessionForFollowUp ignores already-answered
  results (no more cross-turn log spam / stale matches)
- ask_question auto-answer picks the SAFE option (deny/reject/last),
  never options[0] — root cause of the allow-all config drift
- bootstrap: force-rewrite deny-all cli-config on every boot into BOTH
  proxy and agent HOME (PVC drift self-heals), strip agent-authored hooks
- cli-config: deny all 22 built-in tools (Shell/Read/Write/Grep/Glob/
  WebFetch/WebSearch/Task/...), allow Mcp(*) only
- deploy: edge Service + ServiceExport, NetworkPolicy (4646 open+token,
  4647 only from node2 pod CIDR), readOnlyRootFilesystem, no SA token,
  agent-home + tmp emptyDirs
- Dockerfile: pin cursor-agent 2026.10.22-27dcf5f from build cache (deny
  enforcement verified), non-root, dedicated agent home
- e2e: auth-surface matrix + built-in Read leak check + bridge egress

Closes infra-yip
2026-10-23 10:11:39 +00:00

77 lines
2.9 KiB
Bash
Executable File

#!/bin/bash
# Bootstrap: enforce the sandbox cli-config and verify the cursor-agent
# binary works before the HTTP server starts serving traffic.
#
# The config is FORCE-REWRITTEN on every boot. The agent CLI rewrites
# ~/.cursor/cli-config.json at runtime (model choice, permission dialogs
# auto-answered in the past, etc.); with HOME on a PVC a drifted config
# (observed 2026-10: allow-all Shell/Read/Write) would survive reboots
# forever. Rewriting on boot pins the security-relevant fields.
set -euo pipefail
CURSOR_HOME="${HOME}/.cursor"
BOOTSTRAP="/opt/cursor-bootstrap"
export NO_OPEN_BROWSER=1
mkdir -p "${CURSOR_HOME}"
# Force-rewrite the security config every boot (merge model preference if
# the runtime config has one, keep everything else from the bootstrap file).
# Written to BOTH the proxy HOME and the sandboxed agent HOME — the ACP
# children read the latter.
write_config() {
local target_home="$1"
mkdir -p "${target_home}/.cursor"
if [[ -f "${BOOTSTRAP}/cli-config.json" ]]; then
local model_json="{}"
if [[ -f "${target_home}/.cursor/cli-config.json" ]]; then
model_json=$(node -e '
try {
const cur = JSON.parse(require("fs").readFileSync(process.argv[1], "utf8"));
if (cur.model) console.log(JSON.stringify({ model: cur.model }));
else console.log("{}");
} catch { console.log("{}"); }
' "${target_home}/.cursor/cli-config.json" 2>/dev/null || echo '{}')
fi
node -e '
const fs = require("fs");
const base = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
const extra = JSON.parse(process.argv[2] || "{}");
const out = { ...base, ...extra };
fs.writeFileSync(process.argv[3], JSON.stringify(out, null, 2) + "\n");
' "${BOOTSTRAP}/cli-config.json" "${model_json}" "${target_home}/.cursor/cli-config.json"
fi
# Drop runtime-written hook config: hooks execute arbitrary commands from
# the agent's HOME; we never want agent-authored hooks in this deployment.
if [[ -f "${target_home}/.cursor/settings.json" ]]; then
node -e '
const fs = require("fs");
const p = process.argv[1];
try {
const s = JSON.parse(fs.readFileSync(p, "utf8"));
if (s.hooks) { delete s.hooks; fs.writeFileSync(p, JSON.stringify(s, null, 2) + "\n"); }
} catch { /* leave broken file alone */ }
' "${target_home}/.cursor/settings.json"
fi
}
write_config "${HOME}"
if [[ -n "${CURSOR_AGENT_HOME:-}" && "${CURSOR_AGENT_HOME}" != "${HOME}" ]]; then
write_config "${CURSOR_AGENT_HOME}"
fi
# cursor-agent auth via env (no interactive login).
if [[ -z "${CURSOR_API_KEY:-}" ]]; then
echo "CURSOR_API_KEY is not set" >&2
exit 1
fi
export CURSOR_API_KEY
# cursor-agent itself must respond.
if ! /usr/local/bin/agent.real --version >/dev/null 2>&1; then
echo "cursor-agent binary is not executable" >&2
exit 1
fi
echo "cursor-agent bootstrap: sandbox config enforced, auth ok, agent responds"