LoginSignup
10
2

More than 1 year has passed since last update.

CloudFront でオリジンに Authorization ヘッダを送る設定をしようと思うとエラーが出て設定できない

Last updated at Posted at 2021-02-10

経緯

CloudFront のバックにあるオリジンサーバーに対して Authorization ヘッダを送信する設定をしたい。 しかし、この設定を実施しようと Origin Request Policy の Header: whitelist とした後、Authorization を指定すると "The parameter Headers contains Authorization that is not allowed" というエラーになる。

SnapCrab_NoName_2021-2-11_2-45-40_No-00.png

なお、これを CloudFormation でやると "Invalid Parameter" としか出てこないので原因の特定にものすごい時間がかかった。

対処方法

一応、公式でも説明されている。

まとめると、

  • Origin Request Policy に Authorization ヘッダを含めることはできない
  • Authorization ヘッダをオリジンに渡したければ Cache Policy の Header に whitelist として Authorization を含めることで解決可能
  • あるいは Legacy Setting を使う

23/02/05 追記

CloudFront からオリジンに各種ヘッダを送付する場合、何も考えずに全てのヘッダを送付したいこともある。 その場合、標準で提供されている AllViewer のポリシー を利用すると Authorization ヘッダを含めて全てのヘッダを送付できる。

ただし、例えば API Gateway をオリジンにする場合、Host をそのまま渡すと失敗したりするケースがあるので、全ての場合に AllViewer が利用できるわけではない点に注意のこと。

10
2
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
10
2