oranie's blog

旧:iをgに変えると・・・なんだっけ・・・

fluentd + BigQuery pluginを利用する時に認証処理で「invalid_grant」エラーになる時の対処

結論から言うと、システム時間を確認しましょう。

環境はDocker上のfluentdで

2014-10-02 06:31:47 +0900 [error]: unexpected error error_class=Signet::AuthorizationError error=#<Signet::AuthorizationError: Authorization failed.  Server message:
{
  "error" : "invalid_grant"
}>

というエラーが出て起動出来なかった。でも認証情報は合っているし、GoogleDeveloperConsleで見てもAPIの許可とかはしている。で調べて見ると
https://github.com/abronte/BigQuery
にも記載があるが

Troubleshooting

If you're getting an "invalid_grant" error it usually means your system clock is off.

If you're getting unauthorized requested but you've been able to successfully connect before, you need to refresh your auth by running the "refresh_auth" method.

なので、Doker上の時間を確認するとズレまくっていた。とりあえず

ntpdate -q ntp.nict.jp

を実行して時間を合わせたらフツーに起動出来た。

という訳でDokerを使う場合は時間の確認もちゃんとしましょう。
http://stackoverflow.com/questions/24551592/how-to-make-sure-dockers-time-syncs-with-that-of-the-host
に書いてるように

docker run -v /etc/localtime:/etc/localtime:ro -i -t mattdm/fedora /bin/bash

とかでrunさせるのがベストプラクティスなんですかね。