public note

workload identity federation での認証は Cloud SDK CLI に制限がある

結論

2021/11/22 現在、google-github-actions/auth など GCPworkload identity federation ログインで利用できるのは gcloud コマンドのみで、gsutil や bq は対象外になっています。

確認したこと

この制限に気づかずに、GitHub Actions にて google-github-actions/auth で認証したあとに gsutil cp を実行して、以下のエラーが発生しました。

ServiceException: 401 Anonymous caller does not have storage.objects.create access to the Google Cloud Storage object.

最初はサービスアカウントに storage.objects.create 権限をつけ忘れたのかと考えたのですが、確認したらそんなことはなく、権限は付与されているのになぜ...と各種ドキュメントを確認したところ、私が注意書きを見逃していたことがわかりました。

Note this does NOT work for the gsutil tool.

github.com

その他のドキュメントも確認すると、gcloud auth login コマンドのリファレンスに同様の記載がありました。

Login with workload identity federation is not yet supported in other Cloud SDK CLIs (e.g. gsutil and bq) and is only applicable to gcloud commands.

この一文で、bq コマンドも対象外であることがわかりました。

この認証方法は有効期間を短くできて安心ですので、gcloud 以外も対応されるまでは、SDK を使って実装しようと思います。