diff --git a/docs/packages/cli.mdx b/docs/packages/cli.mdx index b22e3f65d6..7d3b55e0ea 100644 --- a/docs/packages/cli.mdx +++ b/docs/packages/cli.mdx @@ -1938,6 +1938,14 @@ Low-memory detection reads **host** RAM, not cgroup or container limits, so containerised callers — including `--docker` — should set `PRODUCER_LOW_MEMORY_MODE` explicitly. +`--docker` runs the render container on Docker's default network, which can +reach your machine, your local network and the internet. It does not restrict +what the rendered page loads unless you ask it to. When you set +`PRODUCER_RESTRICT_PAGE_NETWORK` or `PRODUCER_NON_PUBLIC_CIDRS` in the shell +that runs `hyperframes render --docker`, the CLI passes them into the container, +so the render there refuses the same addresses a local render would. See +[the producer docs](/packages/producer) for what the restriction allows. + Render Chrome keeps its sandbox on macOS, on Windows, and on Linux for a non-root user outside a container. It runs without one as root, in Docker, Podman or Kubernetes, on AWS Lambda and Cloud Run, and where Linux restricts diff --git a/docs/packages/producer.mdx b/docs/packages/producer.mdx index ebf583b64d..87da3f7e74 100644 --- a/docs/packages/producer.mdx +++ b/docs/packages/producer.mdx @@ -232,6 +232,10 @@ add it with `PRODUCER_NON_PUBLIC_CIDRS`, a comma-separated list like `192.160.0. downloads and the render browser then refuse those addresses too. A malformed entry refuses every address rather than being skipped, and logs a warning. +`hyperframes render --docker` passes both settings into its render container when they +are set in the shell that runs it. When they are not set, the container's render page can +reach anything the container's network can, including private addresses. + ## Related topics diff --git a/packages/cli/src/utils/dockerRunArgs.test.ts b/packages/cli/src/utils/dockerRunArgs.test.ts index 92bcd99b12..26dff07987 100644 --- a/packages/cli/src/utils/dockerRunArgs.test.ts +++ b/packages/cli/src/utils/dockerRunArgs.test.ts @@ -26,6 +26,7 @@ const FIXED_INPUT = { // flip between linux/amd64 and linux/arm64 depending on the host running // the test). platform: "linux/amd64", + hostEnv: {}, }; describe("buildDockerRunArgs", () => { @@ -68,6 +69,30 @@ describe("buildDockerRunArgs", () => { `); }); + it("forwards the host's render-network restriction into the container only when it is set", () => { + const envArgs = (hostEnv: Record) => { + const args = buildDockerRunArgs({ ...FIXED_INPUT, hostEnv, options: BASE }); + const beforeImage = args.slice(0, args.indexOf(FIXED_INPUT.imageTag)); + return beforeImage.filter((_, i) => beforeImage[i - 1] === "-e"); + }; + expect( + envArgs({ + PRODUCER_RESTRICT_PAGE_NETWORK: "Yes", + PRODUCER_NON_PUBLIC_CIDRS: "192.160.0.0/16,fd00::/8", + }), + ).toEqual([ + "PRODUCER_RESTRICT_PAGE_NETWORK=Yes", + "PRODUCER_NON_PUBLIC_CIDRS=192.160.0.0/16,fd00::/8", + ]); + expect(envArgs({ PRODUCER_RESTRICT_PAGE_NETWORK: "maybe" })).toEqual([ + "PRODUCER_RESTRICT_PAGE_NETWORK=maybe", + ]); + expect(envArgs({})).toEqual([]); + expect(envArgs({ PRODUCER_RESTRICT_PAGE_NETWORK: " ", PRODUCER_NON_PUBLIC_CIDRS: "" })).toEqual( + [], + ); + }); + it("tells the container its output reaches a terminal only when the host's stdout is one", () => { const flags = (hostStdoutIsTty?: boolean) => buildDockerRunArgs({ ...FIXED_INPUT, hostStdoutIsTty, options: BASE }).slice(0, 4); diff --git a/packages/cli/src/utils/dockerRunArgs.ts b/packages/cli/src/utils/dockerRunArgs.ts index 94ad079c9b..d01f401e36 100644 --- a/packages/cli/src/utils/dockerRunArgs.ts +++ b/packages/cli/src/utils/dockerRunArgs.ts @@ -28,6 +28,8 @@ export interface DockerRunArgsInput { * byte-for-byte parity with amd64 renders. */ platform?: string; + /** Environment read for the render-network settings forwarded into the container. Defaults to `process.env`. */ + hostEnv?: Readonly>; options: DockerRenderOptions; } @@ -106,6 +108,19 @@ export function resolveDockerPlatform( return arch === "arm64" ? "linux/arm64" : "linux/amd64"; } +/** Settings the in-container engine reads to restrict the render page's network, passed through as set on the host. */ +const FORWARDED_RENDER_NETWORK_ENV = [ + "PRODUCER_RESTRICT_PAGE_NETWORK", + "PRODUCER_NON_PUBLIC_CIDRS", +]; + +function renderNetworkEnvArgs(env: Readonly>): string[] { + return FORWARDED_RENDER_NETWORK_ENV.flatMap((name) => { + const value = env[name]; + return value?.trim() ? ["-e", `${name}=${value}`] : []; + }); +} + // Pure argv builder — the cognitive count tracks the number of optional CLI // flags it forwards, not branching depth. Each conditional spread is one // option = O(1) to read. Inherited from main (#1196 added platform handling); @@ -118,6 +133,7 @@ export function buildDockerRunArgs(input: DockerRunArgsInput): string[] { "run", "--rm", ...(input.hostStdoutIsTty ? ["-e", "HYPERFRAMES_STDOUT_IS_TTY=1"] : []), + ...renderNetworkEnvArgs(input.hostEnv ?? process.env), "--platform", platform, "--shm-size=2g",