Stop Trusting Container TCP: Use Pinned Sockets

November 25, 2026
11 min read
17 reads
Stop Trusting Container TCP: Use Pinned Sockets

Every reverse proxy eventually hits the same awkward truth: reaching an application container over Docker's bridge network proves nothing about who sent the request.

If your container listens on a TCP port, odac-proxy is not the only neighbor in the building. A published host port, another container sharing the same Docker network, or a compromised sidecar can open a TCP socket straight to your app and hand it forged X-Forwarded-For or X-Forwarded-Proto headers with a straight face.

In ODAC v2.3.1, we closed that trust gap at both the transport and cryptographic layers. Linux bridge-networked containers now get a fast, kernel-pinned Unix Domain Socket path via ODAC_PROXY_SOCKET, and every forwarded request, including ODAC Cloud tunnel traffic, carries an HMAC-SHA256 signature verified with ODAC_PROXY_KEY.

Best of all, the contract is completely language-agnostic. Whether your container runs Go, Node.js, Python, PHP, or Rust, you get the exact same primitives without locking into a single framework.

Why Standard Proxy Headers and Protocols Fall Short

Before writing a single line of socket code, we asked why existing standards fail inside a multi-tenant container platform.

The classic answer is "just trust private IP ranges." That breaks the moment two containers share a bridge network or an operator publishes a port for debugging. Any peer on that subnet can spoof X-Real-IP, pretend a plain HTTP request arrived over HTTPS, and bypass rate limits or origin checks.

Standard HTTP authentication mechanisms do not fit cleanly either:

  • RFC 9421 (Signature header) collides with upstream apps: Protocols like ActivityPub receive Signature headers from federated servers and verify them end-to-end. A proxy that overwrites or appends to Signature breaks application-level federation.
  • The PROXY protocol ties metadata to one TCP connection: PROXY protocol headers describe a single connection at handshake time, while odac-proxy pools and reuses persistent upstream connections across thousands of different visitors.
  • Raw tunnel byte pipes cannot vouch for requests: Previously, ODAC Cloud tunnels forwarded yamux streams over WebSocket as raw bidirectional TCP pipes, leaving tunneled apps with no cryptographic proof of who connected at the edge.

We needed a contract where the proxy authenticates every visitor claim per request over TCP, and skips the TCP stack entirely when local Linux isolation allows it.

Dual-path trust routing from odac-proxy, ODAC Cloud tunnels, and untrusted container neighbors into an app container

Pinned Unix Domain Sockets Without the Symlink Trap

On Linux hosts, ODAC v2.3.1 creates a dedicated, empty socket directory for every bridge-networked container under <base>/sockets/<container> and bind-mounts it into the container at /odac-proxy. At container start, ODAC injects ODAC_PROXY_SOCKET=/odac-proxy/http.sock.

Look closely at the filesystem permissions, because they solve a tricky privilege problem. The parent sockets root is locked to 0700, while each per-container directory is 0777. Containerized apps run under arbitrary non-root UIDs, so the app must be allowed to bind its socket inside /odac-proxy. Meanwhile, the 0700 parent keeps unprivileged host users out, and no other container mounts that subdirectory.

That creates a subtle attack surface. Because the container owns /odac-proxy, a compromised app could delete http.sock and drop a symlink pointing straight to /var/run/docker.sock, which the ODAC server container holds.

If odac-proxy simply called lstat followed by net.Dial("unix", path), an attacker could win a classic TOCTOU (Time-of-Check to Time-of-Use) race and swap the socket for a symlink in the microseconds before connect().

To eliminate symlink escapes and race conditions permanently, internal/proxy/proxy/pinned_linux.go implements dialPinned using descriptor-relative Linux syscalls:

  1. Strict path validation: On every config sync, odac-proxy verifies that the socket path sits strictly two components deep (<root>/<dir>/<name>) inside ODAC_BACKEND_SOCKET_DIR, rejecting anything outside that tree.
  2. No-follow traversal: dialPinned opens the root directory with O_PATH | O_DIRECTORY | O_CLOEXEC, then opens <dir> and <name> step by step via openat with O_NOFOLLOW.
  3. Inode verification: Before dialing, fstat inspects the opened file descriptor itself and aborts unless st.Mode & S_IFMT == S_IFSOCK.
  4. Kernel-pinned connect: Finally, the Go dialer connects to /proc/self/fd/<fd>, which points directly to the verified kernel socket inode rather than re-resolving any filesystem path.

Kernel-pinned Unix domain socket traversal blocking symlink escapes via O_NOFOLLOW, Fstat, and /proc/self/fd

Every socket backend receives its own isolated http.Transport connection pool, so idle connections from two apps never mix. Both live requests and background cache revalidation use this pinned socket pool automatically.

If dialing the socket ever fails (for example, while an app restarts its worker), odac-proxy logs the fallback at most once per minute per backend and immediately retries over container-bridge TCP on the exact same request. No visitor sees a dropped connection.

Blue-Green Renames and Socket Lifecycle

ODAC deploys apps using a Blue-Green swap, which renames the newly promoted green container to the active app name. Because Docker keeps the original bind-mount source path across a rename, deriving the socket directory from the container's current name would point to the wrong directory after a deploy.

Instead, ODAC inspects the container's /odac-proxy mount source directly alongside its IP during backend resolution. When a container is replaced or deleted, a periodic sweeper (SweepProxySockets) removes unmounted socket directories after a 5-minute grace period, and explicitly aborts cleanup if the Docker daemon query fails so live directories are never touched during a daemon hiccup.

On a plain container start (outside Blue-Green deploys), ODAC polls for up to 60 intervals for http.sock to appear and triggers a proxy config sync the moment the inode becomes a socket.

Cryptographic Request Signing and Signed Cloud Tunnels

Unix sockets handle bridge-networked Linux apps, but TCP is still very much alive. Host-networked apps (networkMode: host), non-Linux development hosts, automatic TCP fallback traffic, and ODAC Cloud tunnels all reach your container over TCP.

In ODAC v2.3.1, every container receives an ODAC_PROXY_KEY environment variable at startup. On every forwarded HTTP request, odac-proxy strips any client-supplied forwarding or ODAC connection headers inside httputil.ReverseProxy.Rewrite (running after hop-by-hop Connection header stripping so clients cannot trick the proxy into deleting signed headers) and writes three connection headers:

  • X-Odac-Connection-RemoteAddress: The visitor's IP address.
  • X-Odac-Connection-Ssl: Set to true when the visitor connected over HTTPS, or omitted on plain HTTP.
  • X-Odac-Connection-Signature: Formatted as t=<unix seconds>,v1=<hex>.

Note that ODAC_PROXY_KEY shares the same underlying per-app secret as ODAC_CLIENT_CERT_KEY, but the two signatures use distinct version prefixes (odac-connection-v1 versus v1 for client certificates) so a signature from one domain can never impersonate the other.

To prevent signature replay across routes, methods, or virtual hosts, the HMAC-SHA256 digest covers seven newline-separated fields with no trailing newline (using an empty string for absent headers):

odac-connection-v1
<t>
<method>
<Host header>
<request target>
<X-Odac-Connection-RemoteAddress>
<X-Odac-Connection-Ssl>

The <request target> is the raw path and query string exactly as received on the HTTP request line (such as /search?q=a%20b), with zero URL decoding or path normalization. After computing HMAC-SHA256 with ODAC_PROXY_KEY, your app compares the lowercase hex digest in constant time and rejects timestamps more than 60 seconds away from local system time.

You can validate your verifier implementation against the documented test vector: using key k, a GET request to example.com for /a?b=1 from 203.0.113.7 over HTTPS at t=1700000000 produces:

t=1700000000,v1=d9a16b4e0be33e772aac465b062640fb9fa3163a9e7bf997c7b1323579b979c8

Seven-line canonical HMAC-SHA256 request signing contract with ODAC_PROXY_KEY, constant-time compare, and 60-second replay window

Cloud Tunnels Join the Same Contract

Previously, Cloud tunnels dialed wss://tunnel.odac.run/_odac/ws and bridged yamux streams straight to the container's TCP port as raw bytes. That made it impossible to sign per-request headers.

In v2.3.1, each tunnel session runs an embedded HTTP server backed by httputil.ReverseProxy. The agent reads the visitor IP (validated with net.ParseIP) and TLS flag reported by ODAC Cloud over the verified TLS tunnel, strips untrusted forwarding headers, and signs the outbound request with ODAC_PROXY_KEY using the exact same odac-connection-v1 pipeline. Tunneled requests now look identical to local proxy requests from your app's point of view.

Language-Agnostic Integration Examples

Because the contract relies solely on environment variables, a Unix socket, and standard HTTP headers, any language stack can adopt it in a few lines of code.

Go: Dual-Listener and Signature Verification

At startup, inspect ODAC_PROXY_SOCKET, safely remove a stale socket or symlink with os.Lstat (never following symlinks), and serve HTTP/1.1 on both the Unix socket and PORT:

handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
	w.Write([]byte("hello"))
})

if path := os.Getenv("ODAC_PROXY_SOCKET"); path != "" {
	if fi, err := os.Lstat(path); err == nil && fi.Mode()&(fs.ModeSocket|fs.ModeSymlink) != 0 {
		os.Remove(path)
	}
	if ln, err := net.Listen("unix", path); err == nil {
		go http.Serve(ln, handler)
	} else {
		log.Printf("proxy socket: %v", err)
	}
}
log.Fatal(http.ListenAndServe(":"+os.Getenv("PORT"), handler))

For requests arriving over TCP, verify X-Odac-Connection-Signature before trusting X-Odac-Connection-RemoteAddress or X-Odac-Connection-Ssl:

func fromOdacProxy(r *http.Request) bool {
	key := os.Getenv("ODAC_PROXY_KEY")
	rest, ok := strings.CutPrefix(r.Header.Get("X-Odac-Connection-Signature"), "t=")
	ts, sig, found := strings.Cut(rest, ",v1=")
	t, err := strconv.ParseInt(ts, 10, 64)
	if key == "" || !ok || !found || err != nil || time.Since(time.Unix(t, 0)).Abs() > time.Minute {
		return false
	}
	got, err := hex.DecodeString(sig)
	if err != nil {
		return false
	}
	mac := hmac.New(sha256.New, []byte(key))
	mac.Write([]byte(strings.Join([]string{
		"odac-connection-v1", ts, r.Method, r.Host, r.RequestURI,
		r.Header.Get("X-Odac-Connection-RemoteAddress"), r.Header.Get("X-Odac-Connection-Ssl"),
	}, "\n")))
	return hmac.Equal(mac.Sum(nil), got)
}

Python and Gunicorn: Zero-Code Dual Binding

Python apps using Gunicorn can bind both PORT and ODAC_PROXY_SOCKET directly from the command line (use uvicorn.workers.UvicornWorker for ASGI frameworks, since standalone uvicorn binds either a TCP port or a socket, not both):

gunicorn app:app --bind "0.0.0.0:$PORT" ${ODAC_PROXY_SOCKET:+--bind "unix:$ODAC_PROXY_SOCKET"}

Inside your Python request middleware, compute the HMAC-SHA256 digest against the raw request target (environ["RAW_URI"] in Gunicorn, or scope["raw_path"] plus ? and scope["query_string"] in ASGI) and compare with hmac.compare_digest.

Node.js and PHP Verification

Node.js services follow the exact same pattern: fs.lstatSync to clear a leftover socket or symlink before listen(socketPath), and crypto.createHmac('sha256', key) with crypto.timingSafeEqual on TCP requests.

For PHP apps running behind PHP-FPM, watch out for one critical default: PHP-FPM clears environment variables from worker pools unless configured otherwise. Add env[ODAC_PROXY_KEY] = $ODAC_PROXY_KEY to your pool configuration or set clear_env = no so getenv('ODAC_PROXY_KEY') is populated when verifying $_SERVER['HTTP_X_ODAC_CONNECTION_SIGNATURE'].

Step-by-Step Rollout for Your Apps

Ready to upgrade existing workloads? Follow this sequence to enable pinned sockets and connection verification with zero guesswork:

  1. Update your ODAC server to v2.3.1: Trigger the server update with one click from app.odac.run, or run odac update in your terminal.
  2. Restart or redeploy your containers: Environment variables and /odac-proxy mounts are attached only at container start. Restart each app from app.odac.run, or run odac app restart <app-name> via the CLI.
  3. Bind ODAC_PROXY_SOCKET early, and keep PORT alive: Open the Unix socket before or alongside PORT so the proxy detects it within the startup poll window. Never tear down PORT, because ODAC health checks, port detection, host-mode apps, Cloud tunnels, and TCP fallback all depend on it. Never crash container startup if binding the Unix socket fails; log the error and keep serving TCP.
  4. Enforce per-request trust in middleware: Trust X-Odac-Connection-RemoteAddress and X-Odac-Connection-Ssl unconditionally when a request arrives on ODAC_PROXY_SOCKET. On TCP requests, trust those headers only when X-Odac-Connection-Signature verifies within the 60-second window. Treat everything else as a direct, untrusted connection.
  5. Know the operator kill switch: If you ever need to force all backends onto TCP for debugging or compatibility, set ODAC_BACKEND_SOCKETS=off in the ODAC server environment. Apps stop receiving ODAC_PROXY_SOCKET, while ODAC_PROXY_KEY request signing stays active.

Subtle Gotchas to Keep in Mind

Even clean primitives have sharp edges if you miss a detail during integration:

  • Do not trust X-Forwarded-* from the signature: ODAC still populates X-Forwarded-For, X-Real-IP, X-Forwarded-Proto, and X-Forwarded-Host for convenience, but the HMAC signature covers X-Odac-Connection-RemoteAddress and X-Odac-Connection-Ssl. Always read visitor IP and TLS state from the signed X-Odac-Connection-* headers.
  • Socket mode is Linux bridge-only: Apps running in networkMode: host or on non-Linux hosts do not receive ODAC_PROXY_SOCKET. Keep your TCP signature verification path active everywhere.
  • Containers started pre-upgrade have no key: An already-running container started on an older ODAC release will not have ODAC_PROXY_KEY until its next restart or redeploy.

By pairing kernel-pinned Unix domain sockets with per-request HMAC-SHA256 signing, ODAC v2.3.1 removes implicit Docker network trust from the equation. Local traffic skips the TCP stack safely without opening symlink escape hatches, and TCP or tunneled traffic carries cryptographic proof of every visitor's origin.