Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PIN: Enqueuing Cloud Tasks results in error - The principal (user or service account) lacks IAM permission iam.serviceAccounts.actAs #47

Open
thclark opened this issue Oct 13, 2023 · 0 comments

Comments

@thclark
Copy link
Contributor

thclark commented Oct 13, 2023

Pinned Note

NOTE: THIS IS NOT A BUG IN DJANGO-GCP

What is the current behavior?

On trying to enqueue a task from a django server running in Google Cloud Run, you may get the following error:

Traceback (most recent call last): File "/usr/local/lib/python3.9/site-packages/google/api_core/grpc_helpers.py", line 72, in error_remapped_callable return callable_(*args, **kwargs) 
File "/usr/local/lib/python3.9/site-packages/grpc/_channel.py", line 1030, in __call__ return _end_unary_response_blocking(state, call, False, None) 
File "/usr/local/lib/python3.9/site-packages/grpc/_channel.py", line 910, in _end_unary_response_blocking raise _InactiveRpcError(state) # pytype: disable=not-instantiable grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: 
status = StatusCode.PERMISSION_DENIED 
details = "The principal (user or service account) lacks IAM permission "iam.serviceAccounts.actAs" for the resource "yourserviceaccount@yourproject.iam.gserviceaccount.com" (or the resource may not exist)." 

Until recently, django-gcp worked as expected. Some time around or somewhat before October 12th 2023, GCP changed something under the hood that broke the ability to place tasks in the queue. We started to get the above error on any attempt to enqueue() a task.

Fix

After a lot of diagnostics and a full measure of total disbelief, it turns out that now, in order to place a task on a queue, you have to allow the service account you're using to impersonate itself.

The solution to this in gcloud is to do:

gcloud iam service-accounts add-iam-policy-binding yourserviceaccount@yourproject.iam.gserviceaccount.com --member serviceAccount:yourserviceaccount@yourproject.iam.gserviceaccount.com --role roles/iam.serviceAccountUser

WARNING!

DO NOT TRY: An alternative solution of applying the roles/iam.serviceAccountUser to your entire project is floating around. This presents a grave security hole - a good discussion on that is given at the end of this thread.

@thclark thclark pinned this issue Oct 13, 2023
@thclark thclark changed the title Enqueuing tasks results in 'The principal (user or service account) lacks IAM permission "iam.serviceAccounts.actAs"' Enqueuing tasks results in error - The principal (user or service account) lacks IAM permission iam.serviceAccounts.actAs Oct 13, 2023
@thclark thclark changed the title Enqueuing tasks results in error - The principal (user or service account) lacks IAM permission iam.serviceAccounts.actAs Enqueuing Cloud Tasks results in error - The principal (user or service account) lacks IAM permission iam.serviceAccounts.actAs Oct 13, 2023
@thclark thclark changed the title Enqueuing Cloud Tasks results in error - The principal (user or service account) lacks IAM permission iam.serviceAccounts.actAs PIN: Enqueuing Cloud Tasks results in error - The principal (user or service account) lacks IAM permission iam.serviceAccounts.actAs Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant