LoginSignup
8
0
お題は不問!Qiita Engineer Festa 2023で記事投稿!

PHPでGCPのWorkload Identity連携をしようとしたら「Uncaught Google\Cloud\Core\Exception\ServiceException: invalid value in the type field」というエラーがでた

Last updated at Posted at 2023-06-28

PHPライブラリ google/cloud-bigquery でBigQueryに接続しようとして以下のエラーに遭遇し、数時間程、時間が溶けたので備忘録として残しておきます。

エラーメッセージ

PHP Fatal error:  Uncaught Google\Cloud\Core\Exception\ServiceException: 
invalid value in the type field in /var/www/app/vendor/google/cloud-core/src/RequestWrapper.php:397

原因

  • GOOGLE_APPLICATION_CREDENTIALS で指定したJSONファイルのtypeが external_account だとエラーがでる
  • 2023/06/28現在、PHPライブラリ google-auth-library-php がまだWorkload Identity連携に対応していなかった
  • google/cloud-bigquery は内部で google-auth-library-php を使用しているので、その影響でWorkload Identity連携が使用できなかった
    • google-auth-library-php を使用しているライブラリ全般で同様のことが起きていると思われる
    • 現在Workload Identity連携の部分の開発が行われているようなので、そのうち実装されそう?

対策

  • google-auth-library-php がWorkload Identity連携に対応するまで待つ
  • Workload Identity連携の代わりにGCPのサービスアカウントを使う
  • 別のプログラミング言語&ライブラリを使用する(Pythonは大丈夫だった)
  • 自前でWorkload Identity連携に対応するコードを実装する

コメント

  • Pythonの google-cloud-bigquery では問題無くWorkload Identity連携ができていたので、PHPでできなくて少しはまった
  • ソースコードがオープンで実装が確認できるというのはこんな時にありがたい
8
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
8
0