Cloud Tasks cannot authenticate calls to Cloud Run Jobs

I’ve been racking my brain trying to figure out what’s wrong with this setup. I’ve managed to get things going but think I’m just missing this last part.

I have a setup with the follow:

  1. Cloud Run Job A (“enqueue-tasks”)
  2. Cloud Run Job B (“process-item”)
  3. a Cloud Tasks queue (“process-items”)

My goal is to schedule a biweekly trigger of the “enqueue-tasks” job. This job does some stuff (not important), and then queues up some tasks in the “process-items” queue.

This seems to be working fine

Each tasks should call the “process-item” job with some overrides. The queue should manage the rate-limit at which each tasks runs.

This seems to be the problem.

IAM Setup:

  • cloud task service account
    • Role: Cloud Run Invoker w/ Overrides
      • run.jobs.run
      • run.jobs.runWithOverrides
      • run.routes.invoke
  • cloud run job service account (Default compute service account)
    • Cloud Tasks Enqueuer
    • Service Account Token Creator
    • Service Account User

I created a custom role with the run.jobs.runWithOverrides permission so that I may pass additional overrides to the “process-item” job via args in each task

Excerpt of how I create/enqueue the tasks (note, everything is in us-west1 region):

// NOTE: This code is inside the "enqueue-tasks" job

import { CloudTasksClient } from "@google-cloud/tasks"

const client = new CloudTasksClient()

const project = "my-project-id"
const location = "us-west1"
const queueName = "process-items"
const taskId = "task-123" // example for item #123
const url = "https://run.googleapis.com/v2/projects/my-project-id/locations/us-west1/jobs/process-item:run"

await client.createTask({
    parent: client.queuePath(project, location, queueName),
    task: {
        name: client.taskPath(project, location, queueName, taskId),
        httpRequest: {
            httpMethod: "POST",
            url: url,
            oidcToken: {
                serviceAccountEmail: "[email protected]",
                audience: url,
            },
            headers: {
                "Content-Type": "application/json",
            },
            body: Buffer.from(JSON.stringify({ overrides: { containerOverrides: [{args: "--item-id=123"}]}})).toString("base64"),
        },
    },
})

Now, even though I’m a little new to GCP, I believe I’m doing everything right! For some reason though, when the cloud tasks run, they always fails with status “UNAUTHORIZED” and when looking at the dashboard for my Cloud Run Jobs I don’t see any invocation for them

To test and make sure that my cloud task SA is correct, I’ve gone ahead and created an access-token as the SA from the gcloud CLI with the following:

gcloud auth print-access-token --impersonate-service-account=cloud-task-service-account@my-project.iam.gserviceaccount.com

Then used Bruno (postman/insomnia like app) to try making the call manually as the cloud task SA.

> POST https://run.googleapis.com/v2/projects/my-project-id/locations/us-west1/jobs/process-item:run
> authorization: Bearer ya29.c.c0AY...XYZ
> content-type: application/json
> data {"overrides":{"containerOverrides":[{"args":["--item-id=123"]}]}}

This succeeds just fine! This leads me to believe that there must be something wrong with how im enqueueing the tasks. The docs are incredibly confusing and even digging through YouTube videos I can’t seem to find any resources online that for from Cloud Run Job -> Cloud Tasks -> Cloud Run Job. Happy to add more details if needed but really curious if I’m just missing something here :/

After looking into this similar issue, I wonder if the issue is with the OIDC audience. I looked to the docs for the endpoint to trigger a cloud run job via REST and found this, but maybe there is another undocumented endpoint Im suppose to use with OIDC?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật