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
This commit is contained in:
hermes
2026-08-25 16:01:29 +00:00
parent 0516b0ecaf
commit fbed72401a
+82
View File
@@ -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