|
| 1 | +# Dev Proxy (dev-proxy) |
| 2 | + |
| 3 | +Installs [Dev Proxy](https://aka.ms/devproxy), an API simulator that helps you test how your app handles API failures, rate limits, latency, and more. Trusts a per-container Dev Proxy root certificate system-wide. |
| 4 | + |
| 5 | +## Example Usage |
| 6 | + |
| 7 | +```json |
| 8 | +"features": { |
| 9 | + "ghcr.io/dotnet/dev-proxy/dev-proxy:1": {} |
| 10 | +} |
| 11 | +``` |
| 12 | + |
| 13 | +## Options |
| 14 | + |
| 15 | +| Options Id | Description | Type | Default Value | |
| 16 | +|-----|-----|-----|-----| |
| 17 | +| version | Dev Proxy version to install: 'latest', 'beta', or a specific version like '2.2.0' or 'v2.2.0'. | string | latest | |
| 18 | +| trustCertificate | After the container is created, generate a Dev Proxy root certificate unique to the container and trust it system-wide and for common runtimes. | boolean | true | |
| 19 | + |
| 20 | +## Customizations |
| 21 | + |
| 22 | +### VS Code Extensions |
| 23 | + |
| 24 | +- `garrytrinder.dev-proxy-toolkit` |
| 25 | + |
| 26 | +## What the Feature does |
| 27 | + |
| 28 | +When the image is built, the Feature: |
| 29 | + |
| 30 | +- Installs Dev Proxy in `/opt/devproxy` and adds the `devproxy` command to `/usr/local/bin`. For beta versions, `devproxy-beta` is available too. |
| 31 | +- Installs the required dependencies (`curl`, `unzip`, `ca-certificates`, `openssl`, ICU) if they're missing. |
| 32 | +- Creates the Dev Proxy configuration folder (`~/.config/dev-proxy`) for the remote user. |
| 33 | +- If `trustCertificate` is `true`, installs a root-owned helper that adds the Dev Proxy root certificate to the system certificate store, and allows the remote user to run it with `sudo` without a password. |
| 34 | + |
| 35 | +The Feature doesn't generate the Dev Proxy root certificate when building the image. If it did, the certificate and its private key would end up in an image layer, and everyone using the same image or Codespaces prebuild would share the same trusted CA. |
| 36 | + |
| 37 | +Instead, after the container is created (`postCreateCommand`), the Feature: |
| 38 | + |
| 39 | +1. Runs `devproxy cert ensure` as the remote user to generate a root certificate unique to the container. |
| 40 | +2. Adds the certificate to the system certificate store (`/usr/local/share/ca-certificates` and `update-ca-certificates`), so that curl, .NET, and other tools that use the system store trust it. |
| 41 | + |
| 42 | +Some runtimes don't use the system certificate store, so the Feature points them at the system CA bundle (`/etc/ssl/certs/ca-certificates.crt`): |
| 43 | + |
| 44 | +| Variable | Used by | |
| 45 | +|----------|---------| |
| 46 | +| `NODE_EXTRA_CA_CERTS` | Node.js | |
| 47 | +| `REQUESTS_CA_BUNDLE` | Python `requests` | |
| 48 | +| `SSL_CERT_FILE` | Python and other OpenSSL-based tools | |
| 49 | + |
| 50 | +Java keystores aren't supported. |
| 51 | + |
| 52 | +Python 3.13 and newer enable strict certificate verification (`VERIFY_X509_STRICT`), which rejects the certificates that Dev Proxy v3 and earlier generate for intercepted hosts. Use Dev Proxy v4 or newer (`"version": "beta"` until v4 is released) to call APIs through Dev Proxy from Python 3.13+. |
| 53 | + |
| 54 | +## Using Dev Proxy |
| 55 | + |
| 56 | +The Feature doesn't start Dev Proxy or set `HTTP_PROXY`/`HTTPS_PROXY` for the whole container. Container-wide proxy variables would route package managers, git, and VS Code's own traffic through Dev Proxy, which breaks them when Dev Proxy isn't running. |
| 57 | + |
| 58 | +Start Dev Proxy with your configuration, and configure the app you're testing to use it: |
| 59 | + |
| 60 | +```bash |
| 61 | +devproxy --config-file .devproxy/devproxyrc.json |
| 62 | +``` |
| 63 | + |
| 64 | +```bash |
| 65 | +HTTPS_PROXY=http://127.0.0.1:8000 npm start |
| 66 | +``` |
| 67 | + |
| 68 | +## Not installing the Dev Proxy Toolkit |
| 69 | + |
| 70 | +The Feature adds the [Dev Proxy Toolkit](https://marketplace.visualstudio.com/items?itemName=garrytrinder.dev-proxy-toolkit) VS Code extension. To skip it, exclude it in your `devcontainer.json`: |
| 71 | + |
| 72 | +```json |
| 73 | +"customizations": { |
| 74 | + "vscode": { |
| 75 | + "extensions": ["-garrytrinder.dev-proxy-toolkit"] |
| 76 | + } |
| 77 | +} |
| 78 | +``` |
| 79 | + |
| 80 | +## OS support |
| 81 | + |
| 82 | +The Feature supports Debian and Ubuntu-based images on x64 and arm64. Alpine and other musl-based images aren't supported. |
| 83 | + |
0 commit comments