LoginSignup
2
0

Istio IngressGatewayが「X-Forwarded-Proto:https」を「http」に書き換えてしまう対策

Last updated at Posted at 2023-09-01

はまった事象

「Client(https) -> ALB(https終端) -> IngressGateway(http) -> WebPod(http)」の構成で、SpringBootで作ったWebApplicationでリダイレクトをすると、Locationが「http://example.com:443/hoge」 のようになってしまう事象にはまった。

ALBは、XFFヘッダを付加する設定(XFF Append Mode)になっており以下のヘッダが付加されている。

  • X-Forwarded-For
  • X-Forwarded-Port
  • X-Forwarded-Proto

このヘッダが適切に設定されていれば、リダイレクトLocationを正しく組み立てられるはず。

調査

調べてみると、上記のようなALBでSSL終端するような構成の時、Istio IngressGatewayが「X-Forwarded-Proto」をhttps -> httpに書き換えてしまうらしい。

ということで、ドキュメントに従って設定を入れてみる。

対応策

対応策は2つ。

  • EnvoyFilterを使う
  • Istio Operatorの設定を変更する

弊社の基盤では、Istio 1.15系。
案2の設定オプションが1.15系対応していたので、こちらを採用することにした。

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
  meshConfig:
    defaultConfig:
      gatewayTopology:
        numTrustedProxies: 2 # Change as needed.

実際には、複数のIngressGatewayのうち特定のIngressGatwayにのみ設定を入れたいので、基盤メンバーとも相談して「meshConfig」ではなく「podAnnotations: proxy.istio.io/config」を書いて設定を注入するようにした。

apiVersion: install.istio.io/v1alpha1
kind: IstioOperator
spec:
  components:
    ingressGateways:
    - name: web-app-istio-ingressgateway
      ~ 中略
      k8s:
        ~ 中略
        podAnnotations:
          proxy.istio.io/config: '{ "gatewayTopology": {"numTrustedProxies": 2} }'
        ~ 中略

結果

Istio IngressGatewayが「X-Forwarded-Proto」をhttps -> httpに書き変えなくなり、ちゃんと期待通りにリダイレクトが動くようになった。

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0