Skip to content
Merged
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 .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@
!plugins/
!plugins/**/package.json
!plugins/**/*.ts
!llm-proxy/
!llm-proxy/Cargo.toml
!llm-proxy/Cargo.lock
!llm-proxy/src/
!llm-proxy/src/main.rs
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@
**/*.log
**/node_modules
**/dist
llm-proxy/target/
**/coverage
*.tsbuildinfo
graphify*
44 changes: 44 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# hadolint ignore=DL3007
ARG BUN_VERSION="latest"

# llm-proxy: localhost reverse proxy with classical-only TLS (rustls/ring)
# so Azure never sees a multi-segment PQC ClientHello.
FROM rust:1-trixie AS proxy-builder
WORKDIR /src/llm-proxy
COPY llm-proxy/Cargo.toml llm-proxy/Cargo.lock ./
COPY llm-proxy/src/ ./src/
RUN <<'FOE'
set -e
cargo build --release --locked
cp target/release/llm-proxy /llm-proxy
FOE

FROM oven/bun:${BUN_VERSION}

SHELL ["/bin/bash", "-o", "pipefail", "-c"]
Expand Down Expand Up @@ -396,6 +409,23 @@ EOF

FOE

COPY --chmod=0555 --from=proxy-builder /llm-proxy /usr/local/bin/llm-proxy

# MITM CA for llm-proxy, created once per image (not on every start).
# Private key stays in the image, 0600 bun-owned; rotation = rebuild.
RUN mkdir -p /usr/local/share/llm-proxy \
&& openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 \
-keyout /usr/local/share/llm-proxy/mitm-ca-key.pem \
-out /usr/local/share/ca-certificates/llm-proxy-mitm.crt \
-days 3650 -nodes -subj "/CN=llm-proxy MITM CA" \
-addext "basicConstraints=critical,CA:TRUE" \
-addext "keyUsage=critical,digitalSignature,cRLSign,keyCertSign" \
-addext "subjectKeyIdentifier=hash" \
-addext "authorityKeyIdentifier=keyid:always" \
&& chmod 600 /usr/local/share/llm-proxy/mitm-ca-key.pem \
&& chown bun:bun /usr/local/share/llm-proxy/mitm-ca-key.pem \
&& update-ca-certificates

COPY --chmod=0555 scripts/entrypoint.sh /entrypoint.sh
COPY --chmod=0555 scripts/convert-gemini.auth.ts /usr/local/bin/convert-gemini.auth.ts

Expand All @@ -404,9 +434,23 @@ USER bun:bun

RUN mise use -g --silent go@1.26 ripgrep

###
# Image clean up (always keep last just before ENTRYPOINT or ENV settings)
# hadolint ignore=DL3066
USER root:root

RUN rm -rf /tmp/* /var/tmp/* \
&& rm -rf "${BUN_HOME}/.cache/go-build" "${BUN_HOME}/.cache/uv" "${BUN_HOME}/.cache/pip" \
&& rm -rf "${BUN_HOME}/.local/share/mise/downloads" "${BUN_HOME}/.cache/mise" \
&& find "${BUN_HOME}" \! -path '*/llm-proxy/*' -name '__pycache__' -type d -prune -exec rm -rf {} +

# hadolint ignore=DL3066
USER bun:bun

# Set BASH_ENV so non-interactive bash shells (spawned by OpenCode CLI) source /etc/bash.bashrc
# This ensures mise activation and PATH are available in shell commands
ENV BASH_ENV=/etc/bash.bashrc
ENV SHELL=/bin/bash
ENV LLM_PROXY_LOGFILE=/tmp/llm_proxy.log

ENTRYPOINT [ "/entrypoint.sh" ]
39 changes: 39 additions & 0 deletions LLMPROXY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# LLM Proxy

This document describes use of the `llm-proxy` HTTP proxy that ships inside the OpenCode CLI image.

## Purpose

OpenCode runs inside a container where all outgoing HTTP(S) traffic goes through a localhost proxy at `http://127.0.0.1:8899`. The proxy starts itself, without user action, on container launch.

The proxy ensures TLS connections to upstream services — in particular Azure Foundry — are established using classical curves, so the upstream front-end never receives post-quantum client hellos it would reject. It also terminates intercepted TLS connections locally, endpoints that are reached via plain HTTP are forwarded, and everything else is relayed. In short, HTTPS traffic visible to the proxy never inherits the client’s TLS capabilities.

For the user, this behavior is transparent and no manual proxy configuration is required.

## Configuration

All configuration is done with environment variables. Below, in alphabetical order.

> [!WARNING]
> `HTTP_PROXY` / `HTTPS_PROXY` (and lowercase) are enforced by the entrypoint; any other value is overridden with a warning.
> `NO_PROXY` / `no_proxy` are equally enforced to `localhost,127.0.0.1`. Existing value is overridden with a warning.

| Variable | Default | Meaning |
| --- | --- | --- |
| `LLM_PROXY_ENABLED` | enabled | `off`, `0`, `false` or `no` disables the proxy entirely: it is not started and no proxy environment is enforced. |
| `LLM_PROXY_LISTEN_ADDR` | `127.0.0.1:8899` | Address the proxy listens on; also the value `HTTP_PROXY` is forced to. |
| `LLM_PROXY_INTERCEPT_SUFFIXES` | everything | Comma-separated domain suffixes (e.g. `cognitiveservices.azure.com`) whose TLS is terminated locally. Empty means all hosts. |
| `LLM_PROXY_MITM` | enabled | `off` disables TLS termination; all `CONNECT` tunnels are then relayed opaquely. |
| `LLM_PROXY_MITM_CA_CERT` / `LLM_PROXY_MITM_CA_KEY` | baked-in image paths | Optional alternate CA certificate/key files for terminated TLS. |
| `LLM_PROXY_UPSTREAM_PROXY` | direct | Optional corporate proxy for the proxy's own upstream connections: an `http://` or `https://` URL, or `direct`/`none`/`off` to force direct connections. Unset means direct (container-wide `HTTP_PROXY` is never followed by the proxy itself). |
| `LLM_PROXY_UPSTREAM_URL` | none | Upstream origin for reverse-proxying (e.g. `https://example.com`). When set, relative (origin-form) requests are forwarded there. When unset, each request must name its target host or it is rejected. |
| `LLM_PROXY_TLS_MIN_VERSION` / `LLM_PROXY_TLS_MAX_VERSION` | none | Bound TLS versions accepted by the proxy. Values `1.2` or `1.3` only; any other value, or minimum above maximum, prevents startup with an error. |
| `LLM_PROXY_LOGFILE` | syslog | Path of the proxy's own log file. Parent directories are created automatically. Unset means syslog (requires something listening on `/dev/log`, otherwise stderr fallback). |
| `LLM_PROXY_LOGLEVEL` | `INFO` | Maximum log verbosity: `ERROR`, `WARN`, `INFO` (default), or `DEBUG`. Any other value prevents startup with an error. Relay ends and byte counts appear only at `DEBUG`. |
| `LLM_PROXY_LLM_LOGFILE` | none | Optional JSONL log of every forwarded LLM request (status, latency, token counts). Unset disables it. |
| `LLM_PROXY_LLM_LOG_BODIES` | off | `1` also stores complete request bodies in the JSONL log. |

Two operational aspects worth knowing:

- Every `CONNECT` accepted by the proxy produces exactly one `INFO` line in the proxy log (`CONNECT <authority> (MITM|tunnel) <host>`). Relay end details are `DEBUG` only.
- If no log file is configured, the proxy logs via syslog (facility `daemon`, tag `llm-proxy`). With no syslog listener the messages fall back to stderr; the container's entrypoint severs the proxy's stdio so they cannot corrupt the OpenCode TUI.
Loading