如何限制后端访问内部网络

How to restrict access for a back-end just to the internal network

我的 HAProxy 有超过 20 个后端,我需要将对一个特定后端 CP-API.MACKMIL.COM 的访问限制为以下内部网络子网:

10.10.0.0/16
10.20.0.0/16
10.30.0.0/16
10.40.0.0/16

目前,通过以下查询,这个域 CP-API.MACKMIL.COM 可以从外部世界访问,但我想限制它。

curl -vvv -H'Host: cp-api.mackmil.com' https://api.mackmil.com/initializations

我的Haproxy配置如下,

frontend http-https
bind :80 accept-proxy
bind :443 accept-proxy ssl crt /etc/pki/tls/private/wildcard.mackmil.com.pem crt /etc/pki/tls/private/wildcard.mackmil.de.pem

acl host_cp  hdr(host) -i cp-api.mackmil.com
acl host_cp  hdr(host) -i cp-api.prod.mackmil.com


use_backend app_cp   if host_cp

backend app_cp
server swarm-worker_10.10.30.199 10.10.30.199:64042 check
server swarm-worker_10.10.40.114 10.10.40.114:64042 check
server swarm-worker_10.20.40.159 10.20.40.159:64042 check
server swarm-worker_10.20.30.190 10.20.30.190:64042 check
server swarm-worker_10.30.40.143 10.30.40.143:64042 check
server swarm-worker_10.30.40.161 10.30.40.161:64042 check
server swarm-worker_10.40.40.107 10.40.40.107:64042 check
server swarm-worker_10.40.40.107 10.40.40.107:64042 check

我正在努力为这个端点在 HTTP/HTTPS 模式下应用这个限制。 我如何为这个后端应用这个限制?

通过将其放入该后端得到修复:

acl internal_subnets src 10.10.0.0/16
acl internal_subnets src 10.20.0.0/16
acl internal_subnets src 10.30.0.0/16
acl internal_subnets src 10.40.0.0/16
http-request deny if ! internal_subnets