Terraform実行時に以下のエラーが出力されました。
Error: retrieving AWS account details: validating provider credentials: retrieving caller identity from STS: operation error STS: GetCallerIdentity, https response error StatusCode: 403, RequestID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx, api error SignatureDoesNotMatch: Signature expired: 20231027T055458Z is now earlier than 20231027T055839Z (20231027T061339Z - 15 min.)
この対応についてのメモです。
エラーメッセージ
エラーメッセージを読むと、以下のような意味になります。
Error: retrieving AWS account details:
エラー:AWSアカウントの詳細を取得
validating provider credentials:
プロバイダー認証の検証
retrieving caller identity from STS
STSから実行者のIDを取得
operation error STS:
STSの操作エラー
GetCallerIdentity, https response error StatusCode: 403,
実行者のIDをGet、httpsのレスポンスエラー、ステータスコード403
RequestID: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx,
リスエストID
api error SignatureDoesNotMatch:
APIのエラー、署名がマッチしない
Signature expired: 20231027T055458Z is now earlier than 20231027T055839Z (20231027T061339Z - 15 min.)
署名の有効期限切れ、20231027T055458Zが20231027T055839Zより早い
意味を考える
うーん、ざっと訳した感じ、最後の時間がポイントっぽいのでWSL上の時刻を取得する。
$ date Fri Oct 27 15:19:34 JST 2023
※ちなみに、この時PC上の時刻は15:35あたりでした。
WSL2の時刻がだいぶずれていることが判明。
ちょっとGoogle先生で調べただけでも結構WSLの時刻がずれるという記事が出てきます。先人に感謝感謝。
ということで、原因は時刻ずれじゃないかなと想定、(20231027T061339Z - 15 min.)と出ているので、おそらく15分以上時刻がずれるとこのエラーが出るのかなと考えました。
WSL2の時刻同期をする
いろんな方法があるみたいですが、自分的には一番なじみのあるntpを実行することに。
ntpdateコマンドを実行しようとしたところ、ntpdateはWSL2のUbuntuには入っていなさそうだったのでインストールから
$ ntpdate Command 'ntpdate' not found, but can be installed with: sudo apt install ntpdate # version 1:4.2.8p12+dfsg-3ubuntu4.20.04.1, or sudo apt install ntpsec-ntpdate # version 1.1.8+dfsg1-4build1
ntpdateのインストール
上で出ているようにaptでntpdateをインストール
$ sudo apt install ntpdate Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: ntpdate 0 upgraded, 1 newly installed, 0 to remove and 257 not upgraded. Need to get 48.8 kB of archives. After this operation, 178 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu focal-updates/universe amd64 ntpdate amd64 1:4.2.8p12+dfsg-3ubuntu4.20.04.1 [48.8 kB] Fetched 48.8 kB in 1s (44.8 kB/s) Selecting previously unselected package ntpdate. (Reading database ... 51086 files and directories currently installed.) Preparing to unpack .../ntpdate_1%3a4.2.8p12+dfsg-3ubuntu4.20.04.1_amd64.deb ... Unpacking ntpdate (1:4.2.8p12+dfsg-3ubuntu4.20.04.1) ... Setting up ntpdate (1:4.2.8p12+dfsg-3ubuntu4.20.04.1) ... Processing triggers for man-db (2.9.1-1) ...
エラー解消
当初予想した通り、WSL2の時刻がかなりずれていたことでSTSのSignatureとのタイムラグが問題となりエラーとなっていたようです。
時刻同期を実施後にterraform planを実行したところ問題なく動作しました。