⛺
IstioでPod間の通信を暗号化させる
Kubernetesのデフォルト環境では、Pod間の通信は暗号化されていません。CiliumやIstioなどのツールを利用すれば、Pod間通信の暗号化を簡単に設定できます。今回は、IstioでPod間の通信を相互認証(mtls)にする方法を紹介します。
まず、現在の通信データをtcpdumpで確認します。
TcpdumpでPod間の通信データを確認
ローカル環境で立ち上げたkind clusterで通信データをtcpdumpします。
$ alias k=kubectl
$ k create ns test
namespace/test created
$ k -n test create deploy d1 --image=nginx --replicas=1
deployment.apps/d1 created
$ k -n test create deploy d2 --image=nginx --replicas=1
deployment.apps/d2 created
$ k -n test expose deploy/d2 --name nginx --port 80
service/nginx exposed
$ k -n test get pods
NAME READY STATUS RESTARTS AGE
d1-7496d488fd-dqhvt 1/1 Running 0 12m
d2-56b67cdd77-7cbkb 1/1 Running 0 11m
$ k -n test exec d1-7496d488fd-dqhvt -it -- sh
$ apt-get update && apt-get -y install tcpdump
...
$ tcpdump -n -i eth0 -X
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
別のターミナルでサービスを叩いてみます。
$ k -n test exec d1-7496d488fd-dqhvt -- curl nginx
<!DOCTYPE html>
<html>
...
<body>
<h1>Welcome to nginx!</h1>
...
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
先のターミナルからパケットの情報を確認して、Nginxのサイト情報が丸見えです。
IstioでPod間の通信を暗号化させる
Ciliumなどのツールはコンテナ側(カーネル層)で暗号化させる一方、IstioではEnvoyが実装されているSidecarコンテナを通じてPodの通信代役をします。
Istioをインストール
Helmを通してインストールする
$ helm install istio-base istio/base -n istio-system --set defaultRevision=default --create-namespace
$ helm install istiod istio/istiod -n istio-system --wait
$ kubectl create namespace istio-ingress
$ helm install istio-ingress istio/gateway -n istio-ingress --wait
検証してみます
Istioを注入するために、対象のnamespaceにistioラベルを貼り、deploymentに属するpod群を再起動します。起動後、tcpdumpしてみます。
$ k label ns test istio-injection=enabled
namespace/test labeled
$ k -n test rollout restart deploy/d1
deployment.apps/d1 restarted
$ k -n test rollout restart deploy/d2
deployment.apps/d2 restarted
$ k -n test get pods
NAME READY STATUS RESTARTS AGE
d1-56ddf9c466-5xbng 2/2 Running 0 23m
d2-7c7b79546d-hjzfn 2/2 Running 0 23m
$ k -n test exec d1-56ddf9c466-5xbng -it -- sh
$ apt-get update && apt-get -y install tcpdump
...
$ tcpdump -n -i eth0 -X
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), snapshot length 262144 bytes
最初と同様に、別のターミナルでサービスを叩いてみます。
k -n test exec d1-56ddf9c466-5xbng -- curl nginx
<!DOCTYPE html>
<html>
...
<body>
<h1>Welcome to nginx!</h1>
...
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
先のターミナルからパケットの情報を確認します。通信情報は暗号化され、解読不能になりました。
Discussion