2023-08-30 21:13:08 +08:00
|
|
|
# Inspiration: https://github.com/Tecnativa/docker-socket-proxy/blob/master/haproxy.cfg
|
|
|
|
|
2023-10-20 02:37:17 +08:00
|
|
|
global
|
|
|
|
maxconn 10
|
|
|
|
|
2023-08-24 20:09:21 +08:00
|
|
|
defaults
|
|
|
|
timeout connect 10s
|
2023-08-30 20:59:08 +08:00
|
|
|
timeout client 10s
|
|
|
|
timeout server 10s
|
2023-08-24 20:09:21 +08:00
|
|
|
|
2023-08-30 20:59:08 +08:00
|
|
|
frontend http
|
|
|
|
mode http
|
2023-08-31 18:46:19 +08:00
|
|
|
bind :::2375 v4v6
|
2023-08-30 21:23:40 +08:00
|
|
|
http-request deny unless { src 127.0.0.1 } || { src ::1 } || { src NC_IPV4_PLACEHOLDER } || { src NC_IPV6_PLACEHOLDER }
|
2023-10-05 18:16:37 +08:00
|
|
|
# docker system _ping
|
|
|
|
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/_ping } METH_GET
|
2023-08-31 17:03:24 +08:00
|
|
|
# container inspect: GET containers/%s/json
|
|
|
|
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/nc_app_[a-zA-Z0-9_.-]+/json } METH_GET
|
|
|
|
# container start/stop: POST containers/%s/start containers/%s/stop
|
2023-08-30 23:02:49 +08:00
|
|
|
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/nc_app_[a-zA-Z0-9_.-]+/((start)|(stop)) } METH_POST
|
2023-08-31 17:03:24 +08:00
|
|
|
# container rm: DELETE containers/%s
|
|
|
|
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/nc_app_[a-zA-Z0-9_.-]+ } METH_DELETE
|
|
|
|
|
2023-08-30 21:16:35 +08:00
|
|
|
|
2023-08-31 17:03:24 +08:00
|
|
|
# container create: POST containers/create?name=%s
|
2023-08-30 21:16:35 +08:00
|
|
|
# ACL to restrict container name to nc_app_[a-zA-Z0-9_.-]+
|
|
|
|
acl nc_app_container_name url_param(name) -m reg -i "^nc_app_[a-zA-Z0-9_.-]+"
|
|
|
|
|
|
|
|
# ACL to restrict the number of Mounts to 1
|
|
|
|
acl one_mount_volume req.body -m reg -i "\"Mounts\"\s*:\s*\[\s*(?:(?!\"Mounts\"\s*:\s*\[)[^}]*)}[^}]*\]"
|
|
|
|
# ACL to deny if there are any binds
|
|
|
|
acl binds_present req.body -m reg -i "\"HostConfig\"\s*:.*\"Binds\"\s*:"
|
|
|
|
# ACL to restrict the type of Mounts to volume
|
|
|
|
acl type_not_volume req.body -m reg -i "\"Mounts\":\s*\[[^\]]*(\"Type\":\s*\"(?!volume\b)\w+\"[^\]]*)+\]"
|
|
|
|
http-request deny if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/create } nc_app_container_name !one_mount_volume binds_present type_not_volume METH_POST
|
|
|
|
|
2023-08-31 17:33:49 +08:00
|
|
|
# ACL to restrict container creation, that it has HostConfig.Privileged not set
|
2023-10-05 18:21:30 +08:00
|
|
|
acl no_privileged_flag req.body -m reg -i "\"HostConfig\":\s?{[^}]*\"Privileged\""
|
2023-08-30 21:16:35 +08:00
|
|
|
# ACL to allow mount volume with strict pattern for name: nc_app_[a-zA-Z0-9_.-]+_data
|
|
|
|
acl nc_app_volume_data_only req.body -m reg -i "\"Mounts\":\s?\[\s?{[^}]*\"Source\":\s?\"nc_app_[a-zA-Z0-9_.-]+_data\""
|
2023-08-31 17:45:19 +08:00
|
|
|
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/containers/create } nc_app_container_name !no_privileged_flag nc_app_volume_data_only METH_POST
|
2023-08-31 17:03:24 +08:00
|
|
|
# end of container create
|
2023-08-30 21:16:35 +08:00
|
|
|
|
2023-08-31 17:03:24 +08:00
|
|
|
# volume create: POST volumes/create
|
|
|
|
# restrict name
|
2023-08-30 21:16:35 +08:00
|
|
|
acl nc_app_volume_data req.body -m reg -i "\"Name\":\s?\"nc_app_[a-zA-Z0-9_.-]+_data\""
|
2023-08-31 17:03:24 +08:00
|
|
|
# do not allow to use "device" word e.g., "--opt device=:/path/to/dir"
|
|
|
|
acl volume_no_device req.body -m reg -i "\"device\""
|
|
|
|
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/volumes/create } nc_app_volume_data !volume_no_device METH_POST
|
|
|
|
# volume rm: DELETE volumes/%s
|
2023-08-30 21:16:35 +08:00
|
|
|
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/volumes/nc_app_[a-zA-Z0-9_.-]+_data } METH_DELETE
|
2023-08-31 17:03:24 +08:00
|
|
|
# image pull: POST images/create?fromImage=%s
|
2023-08-30 21:16:35 +08:00
|
|
|
http-request allow if { path,url_dec -m reg -i ^(/v[\d\.]+)?/images/create } METH_POST
|
2023-08-24 20:09:21 +08:00
|
|
|
http-request deny
|
|
|
|
default_backend dockerbackend
|
2023-08-30 20:59:08 +08:00
|
|
|
|
|
|
|
backend dockerbackend
|
|
|
|
mode http
|
|
|
|
server dockersocket /var/run/docker.sock
|