Issue Summary:
I'm trying to create a Google Cloud project using Terraform Cloud and Workload Identity. While terraform plan succeeds, terraform apply fails with the following error:
Error: failed pre-requisites: failed to check permissions on billing account "billingAccounts/<billingAccounts>": Post "https://cloudbilling.googleapis.com/v1/billingAccounts/ <billingAccounts>:testIamPermissions?alt=json&prettyPrint=false": oauth2/google: status code 403: { "error": { "code": 403, "message": "Permission 'iam.serviceAccounts.getAccessToken' denied on resource (or it may not exist).", "status": "PERMISSION_DENIED", "details": [ { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "IAM_PERMISSION_DENIED", "domain": "iam.googleapis.com", "metadata": { "permission": "iam.serviceAccounts.getAccessToken" } } ] } }
Confirmed Checks:
resource "google_project" "main" {
name = var.project_name
project_id = var.project_id
folder_id = var.folder_id
billing_account = var.billing_account
auto_create_network = false
}
Troubleshooting Attempts:
Question:
Given this information, what are the possible causes and solutions for this error?
Providing this additional information would be helpful in getting more precise advice.
Solved! Go to Solution.
Shows how it was resolved
It was a mistake to set the Workload Identity User at the project level.
https://cloud.google.com/iam/docs/workload-identity-federation?hl=ja#impersonation
As it says here, giving a service account a Workload Identity User at the project level will result in borrowing the privileges of the service account.
If you set up both direct access to the resource and borrowing of the service account, the borrowing is applied first, and then the service account borrows its own privileges, which is what I think happened.
Here is my case
Shows the permissions of the service account when it is wrong
- Project Creator (at the folder level)
- Billing Account User (at the billing account level)
- Service Account Token Creator (at the project level )
- Workload Identity User (at the project level )
- Billing Project Manager (at the folder level)
Principals with access to the service account in case of mistakes (only where relevant)
- principal://iam.googleapis.com/projects/PROJECTID/locations/global/workloadIdentityPools/POOLNAME/* (Workload Identity User)
In this case, the correct service account permissions
- Project Creator (at the folder level)
- Billing Account User (at the billing account level)
- Service Account Token Creator (at the project level)
- Billing Project Manager (at the folder level)
If you find any mistakes, please let us know.
I have resolved this.
Workload Indetity user was given in the wrong place.
The service account itself was borrowing privileges from the service account.
Hi, thanks for posting this, I am seeing the same problem, but I don't completely understand your solution,
I have setup the workload identity federation to work with terraform cloud(HCP) and it works, I can create resources on GCP after executing my workspace in HCP, the problem is that now I need to create a google project and a firebase project, and after running terraform, I always get the same error, this is the resource I am trying to create
resource "google_project" "default" {
provider = google-beta.no_user_project_override
name = var.google_project_name
project_id = var.google_project_id
# Required for any service that requires the Blaze pricing plan
# (like Firebase Authentication with GCIP)
billing_account = var.billing_account
# Required for the project to display in any list of Firebase projects.
labels = {
"firebase" = "enabled"
}
}
service account:dev-hcp-service-account@PROJECTID.iam.gserviceaccount.com
Organization Level Permissions |
|
Billing Account Level permissions |
|
I have tried many different changes but none of those work, I always get the same error
failed to check permissions on billing account
not sure what change I need to make, or where to make the changes.
could You please detail a little bit on how you solved this ? thanks in advance.
Hey, this sounds like a completely different issue. It _might_ be that your workload identity service account doesn't have access to the specified billing account though.
What I want to do in your case and mine is different, so it could possibly be different,
Are you granting Workload Identity User to the principal of the pool you are linking to?
I feel like the response here is a bit ambiguous, so I'll post what worked for me when connecting to OIDC in Vercel:
Hope this helps 🙂
Shows how it was resolved
It was a mistake to set the Workload Identity User at the project level.
https://cloud.google.com/iam/docs/workload-identity-federation?hl=ja#impersonation
As it says here, giving a service account a Workload Identity User at the project level will result in borrowing the privileges of the service account.
If you set up both direct access to the resource and borrowing of the service account, the borrowing is applied first, and then the service account borrows its own privileges, which is what I think happened.
Here is my case
Shows the permissions of the service account when it is wrong
- Project Creator (at the folder level)
- Billing Account User (at the billing account level)
- Service Account Token Creator (at the project level )
- Workload Identity User (at the project level )
- Billing Project Manager (at the folder level)
Principals with access to the service account in case of mistakes (only where relevant)
- principal://iam.googleapis.com/projects/PROJECTID/locations/global/workloadIdentityPools/POOLNAME/* (Workload Identity User)
In this case, the correct service account permissions
- Project Creator (at the folder level)
- Billing Account User (at the billing account level)
- Service Account Token Creator (at the project level)
- Billing Project Manager (at the folder level)
If you find any mistakes, please let us know.