Harden dispatched app-server sandbox defaults
This commit is contained in:
parent
390dcf16d2
commit
1fdf6b8a87
5 changed files with 163 additions and 4 deletions
|
|
@ -75,6 +75,7 @@ For the full staged roadmap, including contribution points, revenue share, patro
|
|||
- set `BIFROST_BRIDGE_BASE_URL` and `BIFROST_BRIDGE_TOKEN` when `tools/bifrost-bridge.mjs` should round-trip every action through the app ledger before mutating GitHub, Discord, or Reddit
|
||||
- the same bridge URL/token pair lets `tools/dispatch-agent-requests.mjs` record `/dispatch/runs/*` receipts for launched Codex work, so Bifrost keeps a live run trail even when a turn fails
|
||||
- Bifrost-dispatched Codex turns also inject Bifrost-owned GitHub gates through environment config: `git` and `gh` wrappers are prepended in `PATH`, a `pre-push` hook backs up raw Git pushes, raw `git push` and mutating `gh` commands stay blocked, and only `tools/bifrost-bridge.mjs` is allowed to authorize the bridge-owned GitHub mutation path
|
||||
- dispatched Codex turns now default to `workspace-write` instead of full machine access, and the app-server sandbox policy disables network access unless the operator explicitly chooses a broader sandbox
|
||||
- `tools/agent-transport.mjs` also uses that bridge configuration to record `/transport/receipts` entries for queue, claim, release, and close events on the request lane
|
||||
- `tools/agent-transport.mjs apply-snapshot` is also treated as a mutating import path now: it fails closed without the bridge receipt config and derives request-lane receipts from the imported state delta
|
||||
- `tools/governance-threads.mjs` uses that same bridge configuration to record `/governance/receipts` entries for topic opens, comments, approvals, and promotions
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@ The dispatcher now tags those Discord receipts with the Bifrost request id as br
|
|||
Those dispatched turns also inherit Bifrost-owned GitHub gates through environment config. `git` and `gh` wrappers are prepended in `PATH`, a `pre-push` hook backs up raw Git pushes, raw `git push` stays blocked inside dispatched work even with `--no-verify`, and mutating `gh` commands are blocked too unless the bridge explicitly authorizes the GitHub mutation it owns.
|
||||
Those dispatched turns also lock the local-only recovery hatches. `--allow-ungated-github`, `BIFROST_ALLOW_UNGATED_GITHUB`, `--allow-unreceipted-activity`, and `BIFROST_ALLOW_UNRECEIPTED_ACTIVITY` are refused inside dispatched work so an agent cannot quietly downgrade itself out of Bifrost's gate or receipt trail.
|
||||
Those dispatched turns also scrub ambient GitHub auth state from the child environment before the worker starts. `GH_TOKEN` and `GITHUB_TOKEN` are cleared, `gh` gets an isolated config directory, `git` gets an isolated global config plus non-interactive credential settings, and terminal prompts are disabled. That does not prove every imaginable direct-HTTP escape is impossible, but it removes the normal ambient credential path from dispatched work.
|
||||
Those dispatched turns now also default to the `workspace-write` sandbox instead of full machine access, and the app-server launch path now tells Codex to keep `networkAccess: false` unless the operator explicitly chooses a broader sandbox. The worker can still read the repo and do its job, but GitHub authority no longer leaks in through the default launch posture.
|
||||
When that same bridge configuration is present, `tools/agent-transport.mjs` records `/transport/receipts` entries for queue, claim, release, and close operations on the request lane. The packet still lives in CultCache. The hosted receipt row is the Bifrost-side witness that an agent or dispatcher touched it.
|
||||
`apply-snapshot` is treated as a mutating import path too. It now fails closed without that same bridge configuration and derives request-lane receipts from the imported state delta, so a snapshot can no longer rewrite queue or claim state behind Bifrost's back.
|
||||
Those mutating scripts now fail closed without that bridge configuration. Use `--allow-unreceipted-activity true` or `BIFROST_ALLOW_UNRECEIPTED_ACTIVITY=true` only for explicit local recovery work where you are intentionally accepting a blind spot.
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ Current CLI wiring:
|
|||
- those dispatched turns also inject Bifrost-owned GitHub gates through environment config: `git` and `gh` wrappers are prepended in `PATH`, a `pre-push` hook backs up raw Git pushes, raw `git push` stays blocked even when `--no-verify` is used, and mutating `gh` commands are blocked unless the bridge explicitly authorizes them
|
||||
- those dispatched turns also lock local-only recovery hatches: `--allow-ungated-github`, `BIFROST_ALLOW_UNGATED_GITHUB`, `--allow-unreceipted-activity`, and `BIFROST_ALLOW_UNRECEIPTED_ACTIVITY` are refused inside dispatched work so a worker cannot opt itself out of Bifrost gate or receipt policy
|
||||
- those dispatched turns also scrub ambient GitHub auth state from the child environment before the worker starts: `GH_TOKEN` and `GITHUB_TOKEN` are cleared, `gh` gets an isolated config directory, `git` gets an isolated global config plus non-interactive credential settings, and terminal prompts are disabled
|
||||
- those dispatched turns now default to the `workspace-write` sandbox in both `codex exec` and app-server launch paths, and the non-danger app-server sandbox policy sets `networkAccess: false` so GitHub mutation authority stays with Bifrost instead of bleeding back into the child runtime by default
|
||||
- the dispatcher also uses that same bridge configuration to post dispatch-run start/complete/fail receipts, including the worker pid, thread/turn ids when available, and result/log paths for the local operator trail
|
||||
- the agent transport CLI uses that same bridge configuration to post request-lane receipts for queue, claim, release, and close events, so Bifrost does not go blind between intake and dispatch
|
||||
- the governance threads CLI uses that same bridge configuration to post governance receipts for topic opens, comments, approvals, and promotions, so Bifrost does not lose the pre-dispatch reasoning trail
|
||||
|
|
|
|||
|
|
@ -499,6 +499,143 @@ writeFileSync(process.env.DISPATCH_ENV_DUMP, JSON.stringify({
|
|||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Dispatch_worker_uses_workspace_write_without_network_for_app_server()
|
||||
{
|
||||
var tempDir = Path.Combine(Path.GetTempPath(), $"bifrost-dispatch-appserver-{Guid.NewGuid():N}");
|
||||
var transportStorePath = Path.Combine(RepoRoot, ".bifrost", "agent-transport.cc");
|
||||
var transportStoreBackup = Path.Combine(Path.GetTempPath(), $"bifrost-agent-transport-backup-{Guid.NewGuid():N}.cc");
|
||||
var hadTransportStore = File.Exists(transportStorePath);
|
||||
Directory.CreateDirectory(tempDir);
|
||||
var requestPath = Path.Combine(tempDir, "request.json");
|
||||
var promptPath = Path.Combine(tempDir, "prompt.md");
|
||||
var logPath = Path.Combine(tempDir, "codex.log");
|
||||
var dumpPath = Path.Combine(tempDir, "app-server.json");
|
||||
var fakeServerPath = Path.Combine(tempDir, "fake-app-server.mjs");
|
||||
|
||||
if (hadTransportStore)
|
||||
{
|
||||
File.Copy(transportStorePath, transportStoreBackup, overwrite: true);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await File.WriteAllTextAsync(requestPath, """
|
||||
{
|
||||
"id": "req_dispatch_appserver_123",
|
||||
"targetRepoName": "Bifrost",
|
||||
"targetRepositoryFullName": "GameCult/Bifrost",
|
||||
"targetAgentIdentity": "nibu",
|
||||
"title": "Dispatch app-server test",
|
||||
"requestMarkdown": "## Request\n\nInspect sandbox policy.",
|
||||
"priority": 50,
|
||||
"status": "claimed",
|
||||
"sourceKind": "manual",
|
||||
"sourceChannelId": "",
|
||||
"sourceMessageIds": [],
|
||||
"sourcePacketPath": "",
|
||||
"sourcePromptPath": "",
|
||||
"createdByAgent": "tester",
|
||||
"claimedByAgent": "tester",
|
||||
"closeNote": "",
|
||||
"createdAt": "2026-06-17T00:00:00Z",
|
||||
"updatedAt": "2026-06-17T00:00:00Z",
|
||||
"claimedAt": "2026-06-17T00:00:00Z",
|
||||
"closedAt": ""
|
||||
}
|
||||
""", new UTF8Encoding(false));
|
||||
await File.WriteAllTextAsync(promptPath, "Hello", new UTF8Encoding(false));
|
||||
await File.WriteAllTextAsync(fakeServerPath, """
|
||||
import { createInterface } from "node:readline";
|
||||
import { writeFileSync } from "node:fs";
|
||||
|
||||
const dumpPath = process.env.DISPATCH_APP_SERVER_DUMP;
|
||||
const requests = [];
|
||||
const rl = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
||||
|
||||
rl.on("line", (line) => {
|
||||
const message = JSON.parse(line);
|
||||
requests.push({ method: message.method, params: message.params ?? null });
|
||||
|
||||
if (message.method === "initialize") {
|
||||
process.stdout.write(JSON.stringify({ id: message.id, result: {} }) + "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.method === "thread/start") {
|
||||
process.stdout.write(JSON.stringify({ id: message.id, result: { thread: { id: "thread_test" } } }) + "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.method === "turn/start") {
|
||||
writeFileSync(dumpPath, JSON.stringify({
|
||||
threadStart: requests.find((entry) => entry.method === "thread/start")?.params ?? null,
|
||||
turnStart: message.params ?? null,
|
||||
}, null, 2));
|
||||
process.stdout.write(JSON.stringify({ id: message.id, result: { turn: { id: "turn_test" } } }) + "\n");
|
||||
process.stdout.write(JSON.stringify({ method: "turn/completed", params: { threadId: "thread_test", turn: { id: "turn_test", status: "completed" } } }) + "\n");
|
||||
return;
|
||||
}
|
||||
|
||||
process.stdout.write(JSON.stringify({ id: message.id, result: {} }) + "\n");
|
||||
});
|
||||
""", Encoding.UTF8);
|
||||
|
||||
await RunNodeAsync([
|
||||
"tools/agent-transport.mjs",
|
||||
"enqueue",
|
||||
"--id", "req_dispatch_appserver_123",
|
||||
"--repo", "Bifrost",
|
||||
"--agent", "nibu",
|
||||
"--title", "Dispatch app-server seed",
|
||||
"--request", "Seed the live request lane.",
|
||||
"--allow-unmirrored", "true",
|
||||
"--allow-unreceipted-activity", "true",
|
||||
]);
|
||||
|
||||
var result = await RunNodeAsync([
|
||||
"tools/dispatch-agent-requests.mjs",
|
||||
"run-claimed",
|
||||
"--request-file", requestPath,
|
||||
"--repo-root", RepoRoot,
|
||||
"--prompt-file", promptPath,
|
||||
"--log", logPath,
|
||||
"--launch-mode", "app-server",
|
||||
"--codex-executable", "node",
|
||||
"--codex-exec-args", fakeServerPath,
|
||||
"--no-discord", "true",
|
||||
], new Dictionary<string, string?>
|
||||
{
|
||||
["BIFROST_ALLOW_UNRECEIPTED_ACTIVITY"] = "true",
|
||||
["DISPATCH_APP_SERVER_DUMP"] = dumpPath,
|
||||
});
|
||||
|
||||
Assert.Equal(0, result.ExitCode);
|
||||
Assert.True(File.Exists(dumpPath), "Fake app-server did not record dispatch policy.");
|
||||
using var payload = JsonDocument.Parse(await File.ReadAllTextAsync(dumpPath, Encoding.UTF8));
|
||||
|
||||
var threadStart = payload.RootElement.GetProperty("threadStart");
|
||||
Assert.Equal("workspace-write", threadStart.GetProperty("sandbox").GetString());
|
||||
|
||||
var turnStart = payload.RootElement.GetProperty("turnStart");
|
||||
var sandboxPolicy = turnStart.GetProperty("sandboxPolicy");
|
||||
Assert.Equal("workspaceWrite", sandboxPolicy.GetProperty("type").GetString());
|
||||
Assert.False(sandboxPolicy.GetProperty("networkAccess").GetBoolean());
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (hadTransportStore)
|
||||
{
|
||||
File.Copy(transportStoreBackup, transportStorePath, overwrite: true);
|
||||
File.Delete(transportStoreBackup);
|
||||
}
|
||||
else if (File.Exists(transportStorePath))
|
||||
{
|
||||
File.Delete(transportStorePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Dispatched_turn_git_hook_blocks_raw_git_push()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -285,7 +285,7 @@ async function runClaimedViaCodexExec(request, repoRoot, promptPath, logPath, op
|
|||
async function runClaimedViaAppServer(request, repoRoot, promptPath, logPath, options) {
|
||||
const model = options.model ?? process.env.CODEX_MODEL ?? "gpt-5.4";
|
||||
const reasoningEffort = options["reasoning-effort"] ?? process.env.CODEX_MODEL_REASONING_EFFORT ?? "medium";
|
||||
const sandbox = options.sandbox ?? "danger-full-access";
|
||||
const sandbox = options.sandbox ?? "workspace-write";
|
||||
const startedAt = new Date().toISOString();
|
||||
const prompt = await readFile(promptPath, "utf8");
|
||||
const resultPath = resolve(dirname(logPath), "result.json");
|
||||
|
|
@ -631,6 +631,7 @@ class CodexAppServerClient {
|
|||
this.buffer = "";
|
||||
this.pending = new Map();
|
||||
this.turnWaiters = [];
|
||||
this.completedTurns = new Map();
|
||||
}
|
||||
|
||||
async start() {
|
||||
|
|
@ -656,12 +657,18 @@ class CodexAppServerClient {
|
|||
waiter.reject(error);
|
||||
}
|
||||
this.turnWaiters = [];
|
||||
this.completedTurns.clear();
|
||||
});
|
||||
this.child.on("error", (error) => {
|
||||
for (const waiter of this.pending.values()) {
|
||||
waiter.reject(error);
|
||||
}
|
||||
this.pending.clear();
|
||||
for (const waiter of this.turnWaiters) {
|
||||
waiter.reject(error);
|
||||
}
|
||||
this.turnWaiters = [];
|
||||
this.completedTurns.clear();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -673,7 +680,6 @@ class CodexAppServerClient {
|
|||
const id = this.nextId;
|
||||
this.nextId += 1;
|
||||
appendLog(this.logPath, `client-request ${method}#${id}`);
|
||||
this.child.stdin.write(`${JSON.stringify({ id, method, params })}\n`);
|
||||
return new Promise((resolvePromise, reject) => {
|
||||
const timer = setTimeout(() => {
|
||||
this.pending.delete(id);
|
||||
|
|
@ -689,10 +695,17 @@ class CodexAppServerClient {
|
|||
reject(error);
|
||||
},
|
||||
});
|
||||
this.child.stdin.write(`${JSON.stringify({ id, method, params })}\n`);
|
||||
});
|
||||
}
|
||||
|
||||
waitForTurnCompleted(threadId, turnId) {
|
||||
const key = `${threadId}:${turnId}`;
|
||||
const completed = this.completedTurns.get(key);
|
||||
if (completed) {
|
||||
this.completedTurns.delete(key);
|
||||
return Promise.resolve(completed);
|
||||
}
|
||||
return new Promise((resolvePromise, reject) => {
|
||||
this.turnWaiters.push({ threadId, turnId, resolve: resolvePromise, reject });
|
||||
});
|
||||
|
|
@ -741,15 +754,21 @@ class CodexAppServerClient {
|
|||
if (message.method === "turn/completed") {
|
||||
const params = message.params ?? {};
|
||||
const completedTurnId = params.turn?.id;
|
||||
const key = `${params.threadId ?? ""}:${completedTurnId ?? ""}`;
|
||||
const remaining = [];
|
||||
let resolved = false;
|
||||
for (const waiter of this.turnWaiters) {
|
||||
if (waiter.threadId === params.threadId && waiter.turnId === completedTurnId) {
|
||||
waiter.resolve(params);
|
||||
resolved = true;
|
||||
} else {
|
||||
remaining.push(waiter);
|
||||
}
|
||||
}
|
||||
this.turnWaiters = remaining;
|
||||
if (!resolved && params.threadId && completedTurnId) {
|
||||
this.completedTurns.set(key, params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -778,13 +797,13 @@ function sandboxPolicyFromMode(mode) {
|
|||
return { type: "dangerFullAccess" };
|
||||
}
|
||||
if (mode === "read-only") {
|
||||
return { type: "readOnly", access: { type: "fullAccess" }, networkAccess: true };
|
||||
return { type: "readOnly", access: { type: "fullAccess" }, networkAccess: false };
|
||||
}
|
||||
return {
|
||||
type: "workspaceWrite",
|
||||
writableRoots: [],
|
||||
readOnlyAccess: { type: "fullAccess" },
|
||||
networkAccess: true,
|
||||
networkAccess: false,
|
||||
excludeTmpdirEnvVar: false,
|
||||
excludeSlashTmp: false,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue