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

时间:2018-11-14 11:41:47

标签: backend haproxy restrict

我有一个具有20多个后端的HAProxy,我需要将对一个特定后端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模式应用此限制。 我如何在此后端应用此限制?

1 个答案:

答案 0 :(得分:2)

已通过将其放在该后端中进行修复:

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