【问题标题】:GCP Cloud Scheduler ERROR with status INTERNAL for an HTTP targetGCP Cloud Scheduler 错误,HTTP 目标的状态为 INTERNAL
【发布时间】:2021-05-24 08:27:00
【问题描述】:

我有一个调度程序作业,每 8 小时调用一次我的函数。当角色角色/cloudfunctions.invoker 的成员为“allUsers”时,该函数正常工作并返回 HTTP 200 状态。但是,当我通过 serviceAccount:${google_service_account.ServiceAccount.email} 使用我的服务帐户作为成员时,会出现此错误:

{
   insertId: "---"
     jsonPayload: {
       status: "INTERNAL"
       @type: "type.googleapis.com/google.cloud.scheduler.logging.AttemptFinished"
       targetType: "HTTP"
       jobName: "projects/projectname/locations/asia-northeast1/jobs/Function_Name"
       url: "https://asia-northeast1-projectname.cloudfunctions.net/Function_Name"
}
httpRequest: {
   status: 500
}
resource: {
  type: "cloud_scheduler_job"
  labels: {
     project_id: "projectname"
     job_id: "Function_Name"
     location: "asia-northeast1"
  }
}
timestamp: "2021-05-24T08:14:39.131999796Z"
severity: "ERROR"
logName: "projects/projectname/logs/cloudscheduler.googleapis.com%2Fexecutions"
receiveTimestamp: "2021-05-24T08:14:39.131999796Z"
}

调度程序结果为“失败”而不是“成功”。

如何解决此错误?我用于 Google Cloud Platform 的 terraform 版本是 2.20.3。代码如下所示:

resource "google_cloud_scheduler_job" "test" {
  name             = "Function_Name_Schedule_Job"
  description      = "Triggers ${google_cloudfunctions_function.Function_Name.name} function every 8 hours."
  time_zone        = "Asia/Singapore"
  schedule         =  "59 7,15,23 * * *"
  region           = "${var.Region}"
  retry_config {
    retry_count        = 5
    max_retry_duration = "520s"
  }
  http_target  {
    uri                     = "${google_cloudfunctions_function.Function_Name.https_trigger_url}"
    oidc_token {
      service_account_email = "${google_service_account.ServiceAccount.email}"
    }
  }
  depends_on = ["google_cloudfunctions_function.Function_Name"]
}

【问题讨论】:

    标签: google-cloud-platform terraform terraform-provider-gcp google-cloud-scheduler


    【解决方案1】:

    您需要在oidc_token 定义中添加受众。等于您的 Cloud Functions URL(没有任何额外的路径或参数)

        oidc_token {
          service_account_email = "${google_service_account.ServiceAccount.email}"
          audience = "${google_cloudfunctions_function.Function_Name.https_trigger_url}"
        }
    
    

    【讨论】:

    • 您好,“service_account_email”是云功能->详情->服务帐号下的那个吗?还是我用来设置 GCP 的个人电子邮件?
    • 不,它是云调度服务帐户(如果不存在则创建一个新帐户)。不是 Cloud Functions 的标识(即使从技术上讲,您可以为两种服务使用相同的标识,但这样做没有意义)
    • 使用云调度程序服务帐户和云函数的触发 URL 添加 OIDC 令牌后,我仍然收到“权限被拒绝”。
    • 403 还是 401?您确定新服务帐户具有授予函数(或更广泛的项目)的 Cloud Functions Invoker 角色吗?
    • 是的,我已将其设置为所有角色 -> Cloud Invoker。状态 403
    猜你喜欢
    • 2020-03-20
    • 1970-01-01
    • 2019-08-03
    • 2019-04-11
    • 1970-01-01
    • 2016-09-18
    • 2019-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多