😽

Github Actions 実行時に 'iam.serviceaccounts.actAs'権限が不足しているエラーの解決方法

2024/01/28に公開

Github Actions 実行時のエラーログ

"Caller is missing permission 'iam.serviceaccounts.actAs' on service account projects/-/serviceAccounts/{{ XXXXX }}-compute@developer.
gserviceaccount.com.Grant the role 'roles/iam.serviceAccountUser' to the caller on the service account projects/-/serviceAccounts/
{{ XXXXX }}-compute@developer.gserviceaccount.com.You can do that by running 'gcloud iam service-accounts add-iam-policy-binding projects/-/
serviceAccounts/{{ XXXXX }}-compute@developer.gserviceaccount.com --member MEMBER --role roles/iam.serviceAccountUser'where MEMBER has a prefix 
like 'user:' or 'serviceAccount:'.Details and instructions for the Cloud Console can be found at https://cloud.google.com/functions/docs/reference/
iam/roles#additional-configuration.",

エラーメッセージは、Google Cloud Platform (GCP) のIAM (Identity and Access Management)に関連する権限の問題を指しています。
具体的には、サービスアカウント {{ XXXXX }}-compute@developer.gserviceaccount.com に対して、iam.serviceaccounts.actAs 権限が不足していると言っています。

エラーメッセージには、権限を追加するための具体的なコマンドが示されています。
※ただし、このコマンドの実行には MEMBER の値が必要です。MEMBER は 'user:' または 'serviceAccount:' のプレフィックスを持つ必要があります。

gcloud iam service-accounts add-iam-policy-binding projects/-/serviceAccounts/{{ XXXXX }}-compute@developer.gserviceaccount.com --member MEMBER --role roles/iam.serviceAccountUser

具体的な対処方法

Github Actions を使用している場合、{{ XXXXX }}-compute@developer.gserviceaccount.com に権限を付与しても解決できません。実行しているサービスアカウントにIAMを設定する必要があります。

私の場合、github-action@{{ XXXXX }}.iam.gserviceaccount.com というサービスアカウントでGithub Actionsを実行しているため、このサービスアカウントにIAMを設定することで解決できました。

具体的なコマンド

gcloud iam service-accounts add-iam-policy-binding projects/-/serviceAccounts/{{ XXXXX }}-compute@developer.gserviceaccount.com --member serviceAccount:github-action@{{ XXXXX }}.iam.gserviceaccount.com --role roles/iam.serviceAccountUser
GitHubで編集を提案

Discussion