URL: /docs/secrets-proxy

---
title: Secrets proxy
description: How a job uses credentials without holding them, how the proxy is configured, and the guarantees it makes.
---

<Note>
  The proxy (`packages/proxy`, issue [#15](https://github.com/turntable-ci/turntable/issues/15)) is wired into job execution for Docker and Daytona sandboxes, see [Wiring into job execution](#wiring-into-job-execution). Token exchange and streaming are not built.
</Note>

A job never holds a raw secret. It holds a **per-job proxy credential**, and its outbound HTTPS traffic goes through a proxy that adds the real credential to the requests a rule allows.

## Architecture

```
sandbox  --CONNECT host:443 + proxy credential-->  proxy  --pinned, validated connection-->  upstream
         <--TLS terminated with the job's CA-----
```

- **Explicit forward proxy.** The sandbox is given `HTTPS_PROXY` and `HTTP_PROXY` with the proxy credential as the userinfo, and its tools' CA variables (`SSL_CERT_FILE`, `NODE_EXTRA_CA_CERTS`, `CURL_CA_BUNDLE`, `REQUESTS_CA_BUNDLE`, `GIT_SSL_CAINFO`) point at the job's CA.
- **TLS interception, HTTP/1.1 only.** The proxy answers `CONNECT`, then terminates TLS with a leaf certificate for that host, signed by a CA created for this one attempt. The CA key is generated in the proxy, kept in memory and never exported. The CA certificate is the only thing delivered to the sandbox, and it is trusted only there. Certificates are built in-process with `node:crypto` (ECDSA P-256), so nothing depends on `openssl` and it works in the single binary.
- **One credential per attempt.** The proxy credential is `attempt id : random token`. Only a hash of the token is stored.
- **Upstream.** Requests leave through `@turntable/net`: the name is resolved once, every address must be public, and the connection is pinned to the validated address.
- **Nothing is stored.** Bodies are not kept. The audit log holds ids, hosts, methods, rule ids and reasons.

## How a job reaches the proxy

The proxy only helps if the sandbox has no other way out. What each provider can enforce today:

| Provider | Egress locked to the proxy | Notes |
| --- | --- | --- |
| Docker | Yes, with Docker 28 or newer | `deny-all-except-proxy`: the sandbox sits alone on an `--internal` network created with an isolated gateway (`gateway_mode_ipv4=isolated`, so the host has no address on it and its own listeners are unreachable). An older daemon is refused, fail closed with a small relay container that forwards one port to the controller's proxy. The relay runs in the sandbox image (so it needs `node`), is read-only with every capability dropped, and exits at the sandbox TTL. Both are removed with the sandbox; an expired network is swept at the next create. |
| Daytona | Yes, with a public TLS listener and the endpoint's stable IPv4 addresses (see [the design](/docs/design/daytona-proxy)) | The sandbox is created with a per-sandbox `networkAllowList` of exactly those addresses, in the create call (no open window): a hard refusal for everything else, DNS dropped. A relay inside the sandbox (Node, present because act needs it) turns the plain local proxy address that tools use into TLS to the public endpoint and verifies its certificate by name. Verified by the canary with real requests: public, private and metadata addresses, and a public address on the proxy's port, must give no HTTP answer, and the proxy must answer. A reply that does not carry the list back fails the create. Needs Tier 3. **Without stable addresses** the strict policy is refused. The only alternative is `proxy-domain-filtered`, a domain list of the endpoint's name, which Daytona enforces on the TLS server name and so rests on its filter parsing the first bytes correctly: it exists only when the operator sets `allowDomainListConfinement: true` in the provider config, it is reported as a different (weaker) policy, and a proxied job uses it only when the endpoint has no addresses. |
| Fake (tests) | n/a | |

A job on a provider that cannot reach the proxy falls to a delivery tier below.

## Wiring into job execution

Opt in with `TURNTABLE_SECRETS_PROXY=1` on a worker that has the vault (`TURNTABLE_MASTER_KEY_FILE`). Optional: `TURNTABLE_PROXY_PORT` (default a free port), `TURNTABLE_PROXY_BIND` (default: the Docker bridge's gateway address on Linux, which is what a container reaches as the host and no other interface, else `127.0.0.1`, which is where Docker Desktop routes `host.docker.internal`; `0.0.0.0` is an explicit opt-in and logs a warning at startup) and `TURNTABLE_PROXY_ADVERTISE_HOST` (how the provider's host names this machine, default `host.docker.internal`).

- **Rules** live in the `proxy_rules` table, one row per rule, managed with the operations `set_proxy_rule`, `list_proxy_rules` and `delete_proxy_rule` (REST, MCP, OpenAPI). They need `release_operator` and are audited. A rule's host must be one of the named secret's destinations, when it is written and again when an attempt is registered. A rule is never derived from a workflow file.
- **Per attempt**, before the runner starts, the worker registers the project's rules and gets a credential; it revokes them when the attempt ends in any way, and at once if the attempt is aborted (cancel, timeout, lease loss).
- **No proxy for** `untrusted_pr` or any class that may not hold secrets: nothing is registered and the job's egress is unchanged. A project with no rules runs as before.
- **Artifact upload.** A job whose plan has an `actions/upload-artifact` step, and whose egress is not open, gets three more rules when the control plane has an artifact store: `POST` of the artifact service's `CreateArtifact` and `FinalizeArtifact`, and `PUT` of `/_artifacts/*/upload/*`, on the store's host and port, nothing injected. It is the way a sandbox with no network reaches Turntable itself, with an upload-only credential (see [Compatibility](/docs/compatibility#artifacts)). It makes the job proxied, but not secret-bearing: a job with only these rules holds no secret. This applies to every class, `untrusted_pr` included; the artifact is recorded with the class of the attempt that wrote it.
- **A proxied job is secret-bearing.** It never runs with open egress: a plan that asks for `open` is refused (`infra_error`) before anything starts. Its sandbox is always `deny-all-except-proxy`, and the proxy is the only path. Hosts with a rule get injection. Any other host is refused, unless the project listed it as a passthrough host (`add_proxy_passthrough_host`, `list_proxy_passthrough_hosts`, `delete_proxy_passthrough_host`; `release_operator`, audited): then it gets a plain tunnel, nothing injected, the job's own TLS end to end. Each entry is an exact host or `*.suffix` and the ports a tunnel may use (default `[443]`; a CONNECT to any other port is refused before anything is dialled). With no list, rule hosts only. A job that checks out or installs packages inside the sandbox needs those hosts listed (for example `github.com`, `codeload.github.com`, `registry.npmjs.org`), or its sources pre-staged.
- **The sandbox** gets the proxy through a file, never a provider env field or an argv (the proxy URL carries the attempt's credential): the worker writes `export` lines to a `0600` file in the sandbox and the launcher sources it and deletes it before act starts. The variables are `HTTP(S)_PROXY` and a trust bundle (system roots plus the attempt's CA) as `SSL_CERT_FILE`, `CURL_CA_BUNDLE`, `REQUESTS_CA_BUNDLE`, `NODE_EXTRA_CA_CERTS` and `GIT_SSL_CAINFO`.
- **Verified before the job runs:** from inside the sandbox the direct path must be closed, the host's address on the sandbox's network must be closed (including the proxy's own port), and the proxy relay open (the egress canary). Anything else, or a provider that cannot enforce the policy, ends the attempt as `infra_error` without running the job. The image needs `curl` for the check.
- **Values** are resolved per request through the vault's one policy path (class, scope, destination, rotation, freeze and audit apply) and added to the attempt's redaction set as they are used, so the log redactor backs up the proxy's own scrubbing.
- **A re-attached attempt** (after a worker restart) is refused when its project has rules: its credential lived in the old process's memory.

Daytona's path is built but not yet run against a real account (design: [Daytona proxy](/docs/design/daytona-proxy)). Not built: token exchange and streaming.

### A public listener, for Daytona

Set `TURNTABLE_PROXY_TLS_CERT_FILE` and `TURNTABLE_PROXY_TLS_KEY_FILE` (both, for the listener's public name, from a public CA) and `TURNTABLE_PROXY_ADVERTISE_HOST` (that name). Optional: `TURNTABLE_PROXY_ADVERTISE_PORT` when the platform forwards a different port, `TURNTABLE_PROXY_ADVERTISE_ADDRESSES` (comma-separated stable IPv4 addresses: required for the strict Daytona confinement, which is an allow list of exactly those; see the Daytona row above for the weaker, opt-in alternative), and `TURNTABLE_PROXY_BIND` (`0.0.0.0` for a public listener, with its startup warning). The listener speaks `CONNECT` inside TLS, so the per-attempt credential never travels in clear. Its limits are written for sandboxes that share egress addresses, so they never turn a valid credential away because of someone else's failures: connections that have not authenticated yet are capped separately from authenticated tunnels (512 in total, 128 per source, an IPv6 source counting as its /64), the CONNECT head has an absolute 10 second deadline (a client that sends a byte at a time still runs out), and a failed authentication is answered after a delay that doubles with each recent failure of the same source and username (250 ms up to 5 s), never a block. A TLS handshake has 10 seconds, and the per-source books are pruned every 30 seconds. Not built: reading the real client address from a trusted forwarder (the PROXY protocol).

## Configuration

A rule names where a credential may go and how it is attached: A rule names where a credential may go and how it is attached:

| Field | Meaning |
| --- | --- |
| `id` | Rule id, recorded in the audit log. |
| `host` | One exact hostname (no IP literals, no wildcards). |
| `port` | Default 443. |
| `methods` | An explicit list such as `["GET", "HEAD"]`. `*` is not accepted. |
| `pathPrefix` | A path prefix such as `/v1/`, matched on segment boundaries. |
| `inject` | `none`, `header` (name and format, such as `Bearer {secret}`) or `basic` (a fixed username, the secret as the password). |
| `forwardHeaders` | Extra request headers to forward to this host when the rule injects (never a method override). |
| `secret` | The name the secret source resolves, for `header` and `basic`. |

The secret is resolved by a `SecretSource` for every injection, given ids and the destination (never a trust class). The proxy never stores a value in a rule, a log or an error. Token exchange (the proxy trades a stored secret for a short-lived token at an authorisation endpoint) is designed but not built yet.

## Guarantees

Each is enforced by the proxy and has a test named for it.

- A host with no rule for the job is refused.
- A credential is injected only for the hosts, ports, methods and path prefixes its rule names.
- Path prefixes match on segment boundaries, and a path must be in canonical form to match. A path with a `;` parameter, an encoded dot, slash or backslash, or a dot segment is refused, because some upstreams read `..;x` as `..`.
- The upstream address is derived only from the `CONNECT` authority; the inner `Host` header and the TLS server name must equal it.
- Plain HTTP, absolute-form requests and ports a rule does not name are refused.
- The proxy never follows a redirect, so a credential is never sent to a host other than the one that was requested.
- A job's own copy of an injected header is replaced, never added to.
- A rule that injects forwards only an allowlist of request headers (`accept`, `accept-language`, `content-type`, `user-agent`, and any a rule names); headers that override the method or the target are never forwarded.
- The status line of a response is the proxy's own: the upstream's reason phrase is not passed on.
- A job's proxy credential works for its attempt only and stops working when the attempt ends or is revoked.
- Unknown, wrong and expired proxy credentials get the same answer.
- Open tunnels are closed when the attempt is revoked. The per-attempt tunnel cap counts tunnels whose audit write is still pending, so a burst of connections cannot exceed it.
- Chunked request bodies are parsed once as they arrive, capped at 4096 chunks per request.
- An injected value that appears in a response, in its raw, base64, URL-encoded or wire form, is redacted before the job sees it.
- Once an attempt has had anything injected, a compressed response to any of its requests is refused, since it cannot be scanned.
- Once an attempt has had anything injected, its requests carry no `Range`, `If-Range` or conditional headers, and a partial (`206`) response is refused.
- A response that still holds a long piece (16 characters or more) of an injected value after scrubbing is refused.
- Request framing is bounded: header, header line, body, chunk-size line, trailer line and total trailer sizes are capped, and so is everything buffered for one request. Header parsing does no backtracking.
- A secret too short to be redacted is not injected.
- Every injection and every refusal is audited, and if the audit write fails nothing is injected.
- Upstream connections go only to public addresses, pinned to the validated one.

## Publish rules

Rules also carry what a registry publish needs. `npmPackage` allows the one encoded slash of a scoped package's exact path and nothing else. `pathExact` matches one path, not a prefix. `pathShape` matches a path segment by segment (`*` is exactly one segment, `{sha256}` one `sha256:<64 hex>` segment), so a rule for `/v2/app/manifests/*` does not match `/v2/app/manifests/a/b`. `bodyCheck` refuses a request body before any credential is attached: `npm-publish` (one attachment with an approved sha256 and honest `dist.integrity`), `sha256` (the whole body, for an OCI manifest) and `json` (a field value, such as `draft: true`). An `oci-bearer` injection makes the proxy answer a registry's token challenge itself: it asks the registry for its realm, refuses a realm on another host or over plain http, exchanges the credential for a token scoped to the rule's repository, keeps it in memory for its short life and attaches it. The release lane uses these for [compat publishing](/docs/release-lane).

## Limits

- A job can still make the requests its rules allow, with the credential attached, while its attempt lives. The proxy prevents a secret being copied out of the job, not used during it. Scope rules to the host, path and methods the job needs.
- Responses are buffered up to a cap (64 MiB by default); large downloads through an injecting rule are not supported yet.
- HTTP/2 and WebSocket upgrades are not intercepted: the proxy offers HTTP/1.1 only.
- A tool that ignores the proxy and CA variables is stopped by egress (above), not by the proxy.

## Delivery tiers

Decided: proxy first, with honest fallbacks. Where the proxy cannot sit in front of a job, delivery falls back, strongest first:

1. **Proxy injection** (this page), the default: the job never holds the value.
2. **Short-lived minted credentials**: the Turntable OIDC issuer (#43) or a cloud STS exchange mints a credential for the job, delivered as an environment variable with a TTL.
3. **Raw injection into the environment**, only when an admin has flagged that secret `allow_raw_injection`. Never for an untrusted class, always audited, and the run and the UI show a visible marker that raw injection was used.
