Project Phoenyx – Part 5: The Invisible Guardian (Socket Proxy)

Category: Core Stack / Security | Read Time: approx. 12 minutes

Why This Step is Vital

We are preparing to install Traefik. Traefik is brilliant because it "magically" detects when we start a new Docker container. But for this magic to work, Traefik needs to talk to the Docker Daemon. And herein lies the danger.

The Danger: The Docker Socket (/var/run/docker.sock) is the master key to your server. Whoever has access to it effectively has root privileges.

If we gave Traefik this master key and Traefik had a vulnerability, an attacker could use Traefik to start any container – including one that gives them full access to your host's filesystem.

The Solution: Tecnativa Socket Proxy

We place a "filter" in between. We use the excellent Docker Socket Proxy by Tecnativa. It is a small, specialized HAProxy container that takes the real socket and exposes a "sanitized" version of it on an internal network.

The Configuration Explained

Here is the socket-proxy-docker-compose.yml:

services:
  socket-proxy:
    image: tecnativa/docker-socket-proxy
    environment:
      CONTAINERS: 1  # Allowed: "Show me all containers"
      NETWORKS: 1    # Allowed: "Show me all networks"
      SERVICES: 1    # Allowed: "Show me services"
      TASKS: 1
      POST: 0        # FORBIDDEN: "Create/Delete something"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
    networks:
      - socket_proxy

What is happening here?
We set variables to 1 (allowed) or 0 (forbidden). The most important one is POST: 0. HTTP POST requests are used to send data or trigger actions (e.g., "Start Container X"). By forbidding this, we make the socket "Read-Only". Traefik can look, but not touch.


Excursion: Where is the "networks" section?

You might have noticed something: In the file above, we reference the network socket_proxy, but we don't define it anywhere at the bottom of the file (no top-level networks: ... block).

Why does this work?

This is the magic of Docker Compose Includes, which we discussed in Part 4. Here is what Docker does at startup:

  1. It reads the master file (docker-compose.yml).
  2. It loads networks/network.yml first (where ALL networks are defined).
  3. It then loads socket-proxy-docker-compose.yml.
  4. It "merges" everything into a single, huge configuration.

Since the network socket_proxy is already known in the "total package" via network.yml, we don't have to (and shouldn't) redefine it in the service file. This prevents redundancy and ensures that all services use exactly the same networks.


Outlook

Our security foundation is laid. Now we can install Traefik and connect it to this secure socket without fearing a compromise of the entire host.