소개

소개

소개

Docker 컨테이너 내에서 실행되는 마이크로서비스가 있고 Debian 10 OS가 있는 VM에 배포되었습니다. 서버의 IP 주소는 141.45.146.55입니다.

마이크로서비스는 다음 API를 공개합니다.

GET https://<host>:8636/?username=<username>&password=<password>

다른 노드에 있는 LDAP 서버에 대해 LDAP 인증 요청을 수행합니다: ldaps://example.com:636. example.com의 IP 주소는 141.45.11.192입니다(서버의 nslookup example.com 출력).

마이크로서비스가 실행 중인 서버의 방화벽이 꺼져 있으면 모든 것이 잘 작동하지만, 방화벽을 켜면 HTTP 요청을 하는 동안 miroservice에서 다음 예외가 발생합니다.

javax.naming.CommunicationException: example.com:636 [Root exception is java.net.UnknownHostException: example.com]

방화벽이 마이크로서비스와 호스트 ldaps://example.com:636을 사용하는 원격 LDAP 서버 간의 연결을 차단하고 있는 것 같습니다.

질문

이 작업을 수행하려면 방화벽 스크립트에 어떤 종류의 방화벽 규칙을 추가하거나 제거해야 합니까? 완전성을 위해 방화벽 스크립트 내용을 추가합니다.

iptables -F
iptables -t nat -F

iptables -P INPUT DROP
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

#
# Allow only 141.45.x.x
#
iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -s 141.45.0.0/16 -j ACCEPT
#
iptables -A INPUT -p tcp -m tcp --dport 8443 -m state --state NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp -m tcp --dport 8636 -m state --state NEW,ESTABLISHED -j ACCEPT

iptables-save > /etc/firewall.conf
#
echo -n "#"      > /etc/network/if-up.d/iptables
echo -n !       >> /etc/network/if-up.d/iptables
echo /bin/sh    >> /etc/network/if-up.d/iptables
echo "iptables-restore < /etc/firewall.conf" >> /etc/network/if-up.d/iptables
#
chmod +x /etc/network/if-up.d/iptables
#

또한 mircoservice가 도커 컨테이너 내부에서 실행되고 있음을 언급하고 싶습니다.방화벽을 끄고 VM을 재부팅하면 모든 것이 제대로 작동하지만 방화벽을 켜면 마이크로서비스에서 java.net.UnknownHostException이 발생합니다.

root:~# iptables -L
Chain INPUT (policy DROP)
target     prot opt source               destination
ACCEPT     all  --  anywhere             anywhere             state ESTABLISHED
ACCEPT     all  --  anywhere             anywhere
ACCEPT     all  --  141.45.0.0/16        anywhere
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:8443 state NEW,ESTABLISHED
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:8636 state NEW,ESTABLISHED

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain DOCKER-USER (0 references)
target     prot opt source               destination

Chain DOCKER (0 references)
target     prot opt source               destination
ACCEPT     tcp  --  anywhere             172.18.0.2           tcp dpt:https
ACCEPT     tcp  --  anywhere             172.18.0.3           tcp dpt:postgresql
ACCEPT     tcp  --  anywhere             172.18.0.4           tcp dpt:https
ACCEPT     tcp  --  anywhere             172.18.0.5           tcp dpt:https

Chain DOCKER-ISOLATION-STAGE-1 (0 references)
target     prot opt source               destination

Chain DOCKER-ISOLATION-STAGE-2 (0 references)
target     prot opt source               destination

내가 지금까지 한 일

나는 의 javadoc을 읽었는데 java.net.UnknownHostException, 그것은 다음과 같습니다:

호스트의 IP 주소를 확인할 수 없음을 나타내기 위해 발생합니다.

그래서 방화벽이 DNS를 차단하고 있을 수도 있다는 생각이 들어서 nslookup example.com마이크로서비스와 방화벽이 실행되는 서버에서 시도해 보았습니다. 불행하게도 nslookup은 방화벽이 켜져 있을 때 작동합니다. example.com을 해결합니다.

또한 다음 규칙을 시도했습니다.

iptables -I INPUT -p tcp --sport 636 -j ACCEPT
iptables -I INPUT -p udp --sport 636 -j ACCEPT
iptables -I INPUT -p tcp --dport 636 -j ACCEPT
iptables -I INPUT -p udp --dport 636 -j ACCEPT

그러나 성공하지 못했습니다. 관리자는 우리가 방화벽 뒤에 있기 때문에(동일한 네트워크 내부) 필요하지 않다고 말했지만 저는 마이크로서비스 개발자이고 관리자는 도커에 익숙하지 않기 때문에 마이크로서비스를 실행하는 것은 나에게 달려 있습니다. 방화벽이 켜져 있습니다.

다른 아이디어가 있나요? Docker와 관련이 있는 것 같은데 어떻게 생각하시나요?

docker ps
CONTAINER ID   IMAGE                                     COMMAND                  CREATED      STATUS        PORTS                          
c67630f9118b   dawidlokiec/ldap-authentication-service   "/opt/docker/bin/lda…"   2 days ago   Up 18 hours   0.0.0.0:8636->443/tcp
and three other contains ...

일부 도커 특정 체인이 있고 대상 주소가 172.18.0.X인 이유는 != 141.45.XX입니다. 문제입니까?

관련 정보