From fbed72401a99658308c8377e66159d61d82162e1 Mon Sep 17 00:00:00 2001 From: hermes Date: Tue, 25 Aug 2026 16:01:29 +0000 Subject: [PATCH] feat(docker_socket_proxy): add swarm stack compose for tecnativa/docker-socket-proxy - HAProxy-based security proxy in front of the host docker socket - binds 2375/tcp on the swarm manager (node.hostname=odroid) - publishes an external 'socket_proxy' overlay network so other stacks (portainer, watchtower, diun) can reach it via DOCKER_HOST=tcp://docker_socket_proxy:2375 - default policy matches upstream: read-only PING/EVENTS/VERSION; everything else denied until explicitly toggled in the environment block --- docker_socket_proxy/stack-compose.yml | 82 +++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 docker_socket_proxy/stack-compose.yml diff --git a/docker_socket_proxy/stack-compose.yml b/docker_socket_proxy/stack-compose.yml new file mode 100644 index 0000000..16ab03f --- /dev/null +++ b/docker_socket_proxy/stack-compose.yml @@ -0,0 +1,82 @@ +# Stack compose for tecnativa/docker-socket-proxy +# https://github.com/Tecnativa/docker-socket-proxy +# +# Lightweight HAProxy-based security proxy in front of the host Docker socket. +# Exposes a TCP endpoint that filters the Docker API by environment variables, +# so any consumer of the docker socket (portainer, watchtower, diun, ...) +# only gets the verb/path scope we explicitly grant. +# +# Designed for Docker swarm. The service binds to 127.0.0.1:2375 on the host -- +# NEVER publish this port on a public network. Downstream services reach it via +# the `socket_proxy` overlay network with `DOCKER_HOST=tcp://docker_socket_proxy:2375`. +# +# Default policy matches the image's defaults: +# - granted by default: EVENTS, PING, VERSION (read-only health) +# - revoked by default: everything else (POSTs blocked, AUTH/SECRETS/SECURITY off) +# +# Edit the environment block below to widen the scope for a specific consumer. + +version: "3.8" + +services: + docker_socket_proxy: + image: tecnativa/docker-socket-proxy:latest + restart: always + # Privileged is required for bind-mounting the host docker socket in + # SELinux/AppArmor-enforced environments. The image is read-only and the + # socket is the only surface it touches. + privileged: true + volumes: + - /var/run/docker.sock:/var/run/docker.sock + environment: + # Listening interface inside the container. 0.0.0.0:2375 is fine because + # the port is only published to localhost on the host (see ports below). + BIND_CONFIG: ":2375" + LOG_LEVEL: "info" + + # -- Access scope -------------------------------------------------- + # Toggle any of these to 1 to grant that API section. Leave at 0 (or omit) + # to keep the upstream default -- denied. + CONTAINERS: 0 # GET /containers, /containers/json, ... + IMAGES: 0 # GET /images, /images/json + NETWORKS: 0 # GET /networks + VOLUMES: 0 # GET /volumes + SERVICES: 0 # GET /services (swarm) + TASKS: 0 # GET /tasks (swarm) + NODES: 0 # GET /nodes (swarm) + POST: 0 # globally allow POST; off = read-only proxy + + # Uncomment when running diun / watchtower-style consumers: + # CONTAINERS: 1 + # IMAGES: 1 + # POST: 1 + # Bind to the swarm node that hosts the docker socket (odroid in this repo). + # On a single-host swarm this still works; on a multi-node swarm the + # socket is local to each manager/worker -- drop the constraint and add + # replicas, or run one proxy per node. + ports: + - target: 2375 + published: 2375 + protocol: tcp + mode: host + networks: + - socket_proxy + deploy: + mode: replicated + replicas: 1 + placement: + constraints: + - node.hostname == odroid + restart_policy: + condition: on-failure + delay: 5s + max_attempts: 3 + +networks: + # External so other stacks (portainer, watchtower, ...) can + # networks: + # socket_proxy: + # external: true + # and reach this service by name. + socket_proxy: + driver: overlay