dockersocket
Docker app from IBRACORP's Repository
This is a security-enhanced proxy for the Docker Socket.
Overview
Readme
View on GitHubLast image-template GitHub Container Registry Docker Hub
Docker Socket Proxy
What?
This is a security-enhanced proxy for the Docker Socket.
Why?
Giving access to your Docker socket could mean giving root access to your host, or even to your whole swarm, but some services require hooking into that socket to react to events, etc. Using this proxy lets you block anything you consider those services should not do.
How?
We use the official Alpine-based HAProxy image with a small configuration file.
It blocks access to the Docker socket API according to the environment variables you
set. It returns a HTTP 403 Forbidden status for those dangerous requests that should
never happen.
Security recommendations
- Never expose this container's port to a public network. Only to a Docker networks where only reside the proxy itself and the service that uses it.
- Revoke access to any API section that you consider your service should not need.
- This image does not include TLS support, just plain HTTP proxy to the host Docker Unix socket (which is not TLS protected even if you configured your host for TLS protection). This is by design because you are supposed to restrict access to it through Docker's built-in firewall.
- Read the docs for the API version you are using, and know what you are doing.
Usage
Run the API proxy (
--privilegedflag is required here because it connects with the docker socket, which is a privileged connection in some SELinux/AppArmor contexts and would get locked otherwise):$ docker container run \ -d --privileged \ --name dockerproxy \ -v /var/run/docker.sock:/var/run/docker.sock \ -p 127.0.0.1:2375:2375 \ tecnativa/docker-socket-proxyConnect your local docker client to that socket:
$ export DOCKER_HOST=tcp://localhost:2375You can see the docker version:
$ docker version Client: Version: 17.03.1-ce API version: 1.27 Go version: go1.7.5 Git commit: c6d412e Built: Mon Mar 27 17:14:43 2017 OS/Arch: linux/amd64 Server: Version: 17.03.1-ce API version: 1.27 (minimum version 1.12) Go version: go1.7.5 Git commit: c6d412e Built: Mon Mar 27 17:14:43 2017 OS/Arch: linux/amd64 Experimental: falseYou cannot see running containers:
$ docker container ls Error response from daemon: <html><body><h1>403 Forbidden</h1> Request forbidden by administrative rules. </body></html>
The same will happen to any containers that use this proxy's 2375 port to access the
Docker socket API.
Grant or revoke access to certain API sections
You grant and revoke access to certain features of the Docker API through environment variables.
Normally the variables match the URL prefix (i.e. AUTH blocks access to /auth/*
parts of the API, etc.).
Possible values for these variables:
0to revoke access.1to grant access.
Access granted by default
These API sections are mostly harmless and almost required for any service that uses the API, so they are granted by default.
EVENTSPINGVERSION
Access revoked by default
Security-critical
These API sections are considered security-critical, and thus access is revoked by default. Maximum caution when enabling these.
AUTHSECRETSPOST: When disabled, onlyGETandHEADoperations are allowed, meaning any section of the API is read-only.
Not always needed
You will possibly need to grant access to some of these API sections, which are not so extremely critical but can expose some information that your service does not need.
BUILDCOMMITCONFIGSCONTAINERSALLOW_START(containers/id/start)ALLOW_STOP(containers/id/stop)ALLOW_RESTARTS(containers/id/stop|restart|kill)ALLOW_PAUSE(containers/id/pause)ALLOW_UNPAUSE(containers/id/unpause)DISTRIBUTIONEXECGRPCIMAGESINFONETWORKSNODESPLUGINSSERVICESSESSIONSWARMSYSTEMTASKSVOLUMES
Use a different Docker socket location
If your OS stores its Docker socket in a different location and you are unable to bind
mount it in your container specification, you can specify this via the SOCKET_PATH
environment variable.
For example, balenaOS exposes its socket at
/var/run/balena-engine.sock. To accommodate this, merely set the SOCKET_PATH
environment variable to /var/run/balena-engine.sock.
Development
All the dependencies you need to develop this project (apart from Docker itself) are managed with uv.
To set up your development environment, run:
uv sync
To build the image locally, you can use Docker Bake or build directly with docker build
# check docker-bake.hcl for configurable variables
docker bake --var TAG_SUFFIX=-local-only
# docker build
docker image build . -f Dockerfile -t custom_tag
Testing
To run the tests locally, add --prebuild to autobuild the image before testing:
uv run pytest --prebuild
By default, the image that the tests use (and optionally prebuild) is named
tecnativa/docker-socket-proxy:lts-testonly. If you prefer, you can build it separately
before testing, and remove the --prebuild flag, to run the tests with that image you
built:
docker bake --var TAG_SUFFIX=-testonly
uv run pytest
If you want to use a different image, use the --image pytest flag and prebuilt it before:
docker image build -t my_custom_image .
uv run pytest --image=my_custom_image
Logging
You can set the logging level or severity level of the messages to be logged with the
environment variable LOG_LEVEL. Default value is info. Possible values are: debug,
info, notice, warning, err, crit, alert and emerg.
Supported API versions
Image tags
Right now, the only supported tags in our container images are the ones following these rules:
:ltslatest image built from haproxy:lts.:latestsame as lts.:3.4latest iamge built from haproxy:3.4.
Images are built weekly, if you need to always use the same image, pin it using its sha.
Any other tags you find in our Docker Hub image or Github Container Registry are deprecated.
Feedback
Please send any issues to the issue tracker. For other kind of feedback, you can use our forum.
If you want to keep up with important news and changes plase follow the News and announcements discussion.
Categories
Download Statistics
Total Downloads Over Time
Related apps
Explore more like this
Explore allLinks
Details
ghcr.io/tecnativa/docker-socket-proxy:latestRuntime arguments
- Network
bridge- Shell
sh- Privileged
- false
- Extra Params
--restart unless-stopped
Template configuration
Allow access to running containers
- Target
- CONTAINERS
- Default
- 1
- Value
- 1
Disable access to
- Target
- POST
- Default
- 0
- Value
- 0
docker.sock
- Target
- /var/run/docker.sock
- Default
- /var/run/docker.sock
- Value
- /var/run/docker.sock