简体   繁体   English

GCP API 网关返回 403 表示托管服务“未为项目启用”

[英]GCP API gateway returning 403 saying managed service "is not enabled for the project"

Trying to access a public cloud run service and not sure why I keep getting this error message ( {"message":"PERMISSION_DENIED:API basic-express-api-1yy1jgrw4nwy2.apigateway.chrome-courage-336400.cloud.goog is not enabled for the project.","code":403} ) when hitting the gateway default hostname path with the API key in query string.尝试访问公共云运行服务,但不确定为什么我不断收到此错误消息( {"message":"PERMISSION_DENIED:API basic-express-api-1yy1jgrw4nwy2.apigateway.chrome-courage-336400.cloud.goog is not enabled for the project.","code":403} )在查询字符串中使用 API 键命中网关默认主机名路径时。 The config has a service account with the role to be able to invoke cloud run services.该配置有一个服务帐户,该帐户具有能够调用云运行服务的角色。 All required APIs are also enabled.所有必需的 API 也已启用。 Here is a link to my entire codebase, but below is my API Gateway specific terraform configuration.这是我整个代码库的链接,但下面是我的 API 网关特定 terraform 配置。

resource "google_api_gateway_api" "basic_express" {
  depends_on = [google_project_service.api_gateway, google_project_service.service_management, google_project_service.service_control]
  provider   = google-beta
  api_id     = "basic-express-api"
}

resource "google_api_gateway_api_config" "basic_express" {
  depends_on    = [google_project_service.api_gateway, google_project_service.service_management, google_project_service.service_control, google_api_gateway_api.basic_express]
  provider      = google-beta
  api           = google_api_gateway_api.basic_express.api_id
  api_config_id = "basic-express-cfg"
  openapi_documents {
    document {
      path     = "api-configs/openapi-spec-basic-express.yaml"
      contents = filebase64("api-configs/openapi-spec-basic-express.yaml")
    }
  }
  lifecycle {
    create_before_destroy = true
  }
  gateway_config {
    backend_config {
      google_service_account = google_service_account.apig_gateway_basic_express_sa.email
    }
    # https://cloud.google.com/api-gateway/docs/configure-dev-env?&_ga=2.177696806.-2072560867.1640626239#configuring_a_service_account
    # when I added this terraform said that the resource already exists, so I had to tear down all infrastructure and re-provision - also did not make a difference, still getting a 404 error when trying to hit the gateway default hostname endpoint - this resource might be immutable...
  }
}

resource "google_api_gateway_gateway" "basic_express" {
  depends_on = [google_project_service.api_gateway, google_project_service.service_management, google_project_service.service_control, google_api_gateway_api_config.basic_express, google_api_gateway_api.basic_express]
  provider   = google-beta
  api_config = google_api_gateway_api_config.basic_express.id
  gateway_id = "basic-express-gw"
  region     = var.region
}

resource "google_service_account" "apig_gateway_basic_express_sa" {
  account_id = "apig-gateway-basic-express-sa"
  depends_on = [google_project_service.iam]
}
# "Identity to be used by gateway"

resource "google_project_iam_binding" "project" {
  project = var.project_id
  role    = "roles/run.invoker"
  members = [
    "serviceAccount:${google_service_account.apig_gateway_basic_express_sa.email}"
  ]
}
# https://cloud.google.com/api-gateway/docs/configure-dev-env?&_ga=2.177696806.-2072560867.1640626239#configuring_a_service_account

Try:尝试:

PROJECT=[[YOUR-PROJECT]]
SERVICE="basic-express-api-1yy1jgrw4nwy2.apigateway.chrome-courage-336400.cloud.goog"

gcloud services enable ${SERVICE} \
--project=${PROJECT}

As others have pointed out, you need to enable the api service.正如其他人指出的那样,您需要启用 api 服务。 You can do via terraform with the google_project_service resource:您可以使用google_project_service资源通过 terraform 进行操作:

resource "google_project_service" "basic_express" {
  project = var.project_id
  service = google_api_gateway_api.basic_express.managed_service

  timeouts {
    create = "30m"
    update = "40m"
  }

  disable_dependent_services = true
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 GCP API Gateway with an API Key 失败并显示 403 error stating....cloud.goog is not enabled for the project - GCP API Gateway with an API Key fails with 403 error stating ... .cloud.goog is not enabled for the project GCP API 网关 - 在响应消息“超出配额”中隐藏项目详细信息 - GCP API Gateway - Hide project details in response message "quota exceeded" GCP API 网关中的文件上传 - FIle upload in GCP API Gateway GCP - 如何在 API 网关中更新 api 规范 - GCP - How to update api specification in API Gateway GCP API 云功能网关默认服务帐户身份验证:“您的客户端无权访问请求的 URL” - GCP API Gateway to Cloud Functions default service account authentication: "Your client does not have permission to the requested URL"" 如何列出启用了特定 API 的 GCP 项目 - How to list GCP projects with a particular API enabled GCP API 网关:无法使用路径参数 - GCP API Gateway: Cannot use path params 自定义授权方的 AWS API 网关 403 错误 - AWS API gateway 403 error for Custom Authorizer 如何让用户访问由 GCP 项目管理的应用程序脚本 - How to give users access to app script managed by a GCP Project GCP 云任务是按项目或服务定义的吗? - GCP Cloud Tasks are defined per project or service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM