Repository navigation
Open
Description
Hello,
just got started using this container to secure watchtower.
but i see strange behavior when i send requests to the api in the below setup:
version: '2'
services:
watchtower:
environment:
DOCKER_HOST: tcp://socket-proxy:2375
image: ${MY_CONTAINER_REPO}containrrr/watchtower
depends_on:
- socket-proxy
command: -R updatetest_updatetest_1
restart: unless-stopped
socket-proxy:
image: ${MY_CONTAINER_REPO}tecnativa/docker-socket-proxy:edge
environment:
POST: 1
CONTAINERS: 1
IMAGES: 1
NETWORKS: 1
ALLOW_START: 1
ALLOW_STOP: 1
ALLOW_RESTARTS: 1
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
this lets watchtower do its job nicely and the socket-proxy logs show clearly what requests have been done.
however, there is more:
expected behavior:
- post requests on containers, images etc. are allowed (and matches watchtowers need)
- requests to volumes / exec or any other endpoint is not allowed.
- DELETE method is not possible (you do not define it as being allowed in haproxy?)
actual behavior:
- a get request to volumes is not allowed(good):
curl http://socket-proxy:2375/volumes
<html><body><h1>403 Forbidden</h1>
Request forbidden by administrative rules.
</body></html>
- a post request to exec is allowed!(bad):
curl --json '{"AttachStdin": false, "AttachStdout": true, "AttachStderr": true, "DetachKeys": "ctrl-p,ctrl-q", "Tty": false, "Cmd": ["hostname"]}' http://socket-proxy:2375/containers/913d03458185f403a03133c3ac4fd537e05e8386cc200e0a37
354bfebf69a3d2/exec
{"Id":"9e72a0b2294259fa05309aeb26af6355f38310212a0e32f7493f1e94f9730e5c"}
- a delete request is allowed (strange):
below log from watchtower update action:
socket-proxy_1 | ::ffff:192.168.112.3:52366 [25/Jan/2024:16:39:39.507] dockerfrontend dockerbackend/dockersocket 0/0/0/14/14 204 165 - - ---- 1/1/0/0/0 0/0 "DELETE /v1.25/containers/7ec9c82ebaba98045db83ab80ca618c78d0c5e4f03a09f1ab02a7319abb5b0d6?force=1 HTTP/1.1"
environment:
- tecnativa/docker-socket-proxy:edge
- docker 20.10 on debian bookworm
- let me know if you need more info..
Metadata
Metadata
Assignees
Labels
No labels
Activity
polarathene commentedon Sep 14, 2024
That is because there is presently no difference between READ/WRITE, only enable/disable of an endpoint. While most exec operation belong to the
/execendpoint, this one belongs to/containersat/containers/{id}/execthus the ENV isCONTAINERS=1and it is aPOSTrequest thusPOST=1allows it:docker-socket-proxy/haproxy.cfg
Line 56 in 0e8d660
docker-socket-proxy/haproxy.cfg
Line 59 in 0e8d660
docker-socket-proxy/haproxy.cfg
Line 48 in 0e8d660
There is a PR to run lua script to separate the read vs write permissions: #126
If that lands you would have
CONTAINERS_READ=1andCONTAINERS_WRITE=0Likewise due to the referenced rule with
POST=1check, while the name is poorly chosen, it allows any other request likeDELETEto be permitted. Since you haveCONTAINERS=1that is granted. With that referenced PRCONTAINERS_WRITE=1will enable bothPOSTandDELETErequests, there is no further granularity there, although that should be sufficient for most needs.Add ALLOW_EXEC / ALLOW_KILL / ALLOW_DELETE granular flags
fix: deny exec-create and pause paths when their env vars are unset