Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/exec-routed-ca-env.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@cloudflare/computer": patch
---

Commands run with an `outbound` now get the egress CA's environment variables, so npm, pnpm and Node scripts trust the routed container's HTTPS instead of failing with `SELF_SIGNED_CERT_IN_CHAIN`.
21 changes: 20 additions & 1 deletion packages/computer/src/remote-exec/sandbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function interceptingContainer(
trust: { exitCode: number; stderr: string } = { exitCode: 0, stderr: "" },
) {
const { container, log } = fakeContainer(false);
const execOptions: unknown[] = [];
const intercepting = Object.assign(container, {
interceptAllOutboundHttp: async (binding: Fetcher) => {
log.push(`intercept http ${(binding as unknown as { name: string }).name}`);
Expand All @@ -99,6 +100,7 @@ function interceptingContainer(
},
exec: async (cmd: string[], options?: unknown) => {
const script = cmd[2] === TRUST_CA_SCRIPT;
if (!script) execOptions.push(options);
log.push(script ? `trust ${JSON.stringify(options)}` : `exec ${cmd.join(" ")}`);
return script
? fakeProcess({
Expand All @@ -108,7 +110,7 @@ function interceptingContainer(
: fakeProcess();
},
});
return { container: intercepting, log };
return { container: intercepting, log, execOptions };
}

interface Egress {
Expand Down Expand Up @@ -263,6 +265,23 @@ describe("ContainerExec (what ExecSandbox delegates to)", () => {
]);
});

it("gives each command routed through an egress the CA's env, over its own", async () => {
const { container, execOptions } = interceptingContainer();
const target = egressing(container);
await target.exec(["a"], { env: { A: "1", SSL_CERT_FILE: "/mine" } }, EGRESS);
await target.exec(["b"], undefined, EGRESS);
expect(execOptions).toEqual([
{ env: { A: "1", ...CA_ENV }, user: "0:0" },
{ env: CA_ENV, user: "0:0" },
]);
Comment on lines +268 to +276

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Routed Node HTTPS lacks end-to-end coverage

The stub checks exec options but never launches Node. The remote-exec agent rebuilds the child environment from its own environment and the image’s. A routed Node HTTPS smoke test would verify the fix at the user-facing boundary.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Declined for this PR. This is a coverage suggestion, not a defect. environment() in packages/remote-exec/src/procs.rs applies the command's own env last (env.extend(given…)), after the agent's and the image's env, so the CA_ENV that exec() now passes reaches the child. The repo has no harness that runs a real routed container with Node, and none of the vitest configs under packages/computer start one. Building that harness is separate work. The new sandbox.test.ts cases check the contract at the ContainerExec boundary, which is where this change sits.

});

it("leaves the env of a command with no egress alone", async () => {
const { container, execOptions } = interceptingContainer();
await egressing(container).exec(["a"], { env: { A: "1" } });
expect(execOptions).toEqual([{ env: { A: "1" }, user: "0:0" }]);
});

it("lets the start options turn the internet on, and keeps their env under the CA's", async () => {
const { container, log } = interceptingContainer();
const env = { A: "1", SSL_CERT_FILE: "/image/bundle.pem" };
Expand Down
5 changes: 5 additions & 0 deletions packages/computer/src/remote-exec/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,13 @@ export class ContainerExec<Egress = undefined> implements ExecTarget {
await this.#admit(egress);
try {
// exec() waits for a container that's still starting.
const routed = this.#route?.kind === "egress";
process = await this.#get().exec(cmd, {
...options,
// The start's env reaches only the entrypoint, so a routed command needs the CA itself.
...(routed
? { env: { ...(options?.env as Record<string, string> | undefined), ...CA_ENV } }
: {}),
user: options?.user ?? this.#options.user ?? ROOT,
});
} catch (error) {
Expand Down