VPC Service Controls 是一项 Google Cloud 功能,可让您设置安全的边界以防数据渗漏。本指南介绍了如何将 Cloud Scheduler 作业纳入 VPC Service Controls 边界。
限制
以下限制适用于 VPC Service Controls 对 Cloud Scheduler 的支持。
强制执行的操作
仅对以下操作执行 VPC Service Controls:
创建 Cloud Scheduler 作业
更新 Cloud Scheduler 作业
这一点为什么非常重要?
由于 VPC Service Controls 仅在创建作业和更新作业时强制执行,因此对于在您将 Cloud Scheduler 添加到 VPC Service Controls 边界之前创建的作业,VPC Service Controls 不会自动强制执行。即使作业目标不在 VPC Service Controls 边界内或不是受支持的目标,作业也会继续执行。如需针对所有 Cloud Scheduler 作业强制执行 VPC Service Controls,请执行以下操作:
如果您未在将 Cloud Scheduler 添加到 VPC Service Controls 边界之前删除这些作业,则这些作业会继续运行,但 VPC Service Controls 不会对其强制执行。在本文档中,请参阅强制执行的操作。
例如,如果您有一个 Cloud Scheduler 作业,其目标是不受支持的目标(例如 Cloud Run 自定义网域),那么在您将 Cloud Scheduler 添加到 VPC Service Controls 边界后,该作业会继续运行,但不受 VPC Service Controls 保护。对于目标位于 VPC Service Controls 边界之外的现有作业,情况也是如此。
添加必需的 IAM 角色
必需。如需使用 VPC Service Controls,Cloud Scheduler 服务账号必须具有 Cloud Scheduler Service Agent IAM 角色。系统会自动为您的项目创建 Cloud Scheduler 服务账号。如需验证该项目是否具有 Cloud Scheduler 服务代理 IAM 角色,或授予此角色,请执行以下步骤:
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[],[],null,["# Secure cron jobs with VPC Service Controls\n\n[VPC Service Controls](/vpc-service-controls/docs/overview) is a Google Cloud feature\nthat lets you set up a secure perimeter to guard against data exfiltration.\nThis guide shows how to include Cloud Scheduler jobs in a\nVPC Service Controls perimeter.\n\nLimitations\n-----------\n\nThe following limitations apply to VPC Service Controls support for\nCloud Scheduler.\n\n### Enforced actions\n\nVPC Service Controls is only enforced on the following actions:\n\n- Cloud Scheduler job creation\n- Cloud Scheduler job updates\n\n#### Why does this matter?\n\nBecause VPC Service Controls is only enforced on job creation and job updates,\nVPC Service Controls is not automatically enforced for jobs that were\ncreated before you added Cloud Scheduler to your VPC Service Controls\nperimeter. Jobs continue to execute even if the job targets aren't part of your\nVPC Service Controls perimeter or are not [supported targets](#targets). To\nenforce VPC Service Controls for all Cloud Scheduler jobs:\n\n- **Jobs with targets that are either unsupported or are outside your\n perimeter:** Delete the jobs. In this document, see [Delete non-compliant jobs](#non-compliant).\n- **Jobs with targets that are both supported and inside your perimeter:** Run an update on each job after adding Cloud Scheduler to your perimeter. In this document, see [Enforce VPC Service Controls on pre-existing jobs](#preexisting).\n\n### Supported targets\n\nThe Cloud Scheduler integration with VPC Service Controls supports\nthe following targets. HTTP endpoints are supported if listed; however,\narbitrary HTTP endpoints are *not* supported.\n\n- Cloud Run functions---on the `functions.net` URL\n- Cloud Run---on the `run.app` URL for Cloud Run services. Cloud Run job targets are not supported. To learn about the difference between Cloud Run service and job resources, see [Services and jobs: two ways to run your code](/run/docs/overview/what-is-cloud-run#services-and-jobs).\n- Dataflow API---must be in the same Google Cloud project as your Cloud Scheduler job\n- Data Pipelines---must be in the same Google Cloud project as your Cloud Scheduler job\n- Pub/Sub---must be in the same Google Cloud project as your Cloud Scheduler job\n\nDelete non-compliant jobs\n-------------------------\n\nRecommended. Delete Cloud Scheduler jobs with targets that are\neither:\n\n- Unsupported (see [Supported targets](#targets))\n- Outside of the VPC Service Controls perimeter you plan to use\n\nFor instructions on deleting jobs, see\n[Delete a job](/scheduler/docs/creating#delete).\n\nIf you don't delete these jobs before adding Cloud Scheduler to\nyour VPC Service Controls perimeter, the jobs continue to run, but\nVPC Service Controls is not enforced on them. In this document, see\n[Enforced actions](#enforced-actions).\n\nFor example, if you have a Cloud Scheduler job that targets an\nunsupported target (such as a Cloud Run custom domain), the job\ncontinues to run after you add Cloud Scheduler to your\nVPC Service Controls perimeter, but it is not protected by VPC Service Controls. The\nsame is true for a pre-existing job with a target outside of your\nVPC Service Controls perimeter.\n\nAdd required IAM roles\n----------------------\n\nRequired. In order to use VPC Service Controls, the Cloud Scheduler\nservice account must have the **Cloud Scheduler Service Agent**\nIAM role. The Cloud Scheduler service account is created\nfor your project automatically. To verify that it has the Cloud Scheduler\nService Agent IAM role, or to grant this role, take the following\nsteps:\n\n1. In the Google Cloud console, go to **IAM**.\n\n [Go to IAM](https://console.cloud.google.com/iam-admin)\n2. Select the **Include Google-provided role grants** checkbox.\n\n3. In the filter, type **Cloud Scheduler Service Account**, and select this\n principal.\n\n4. Look at the **Role** column for the **Cloud Scheduler Service Account**\n principal. You can proceed if the following role is listed:\n\n - **Cloud Scheduler Service Agent**\n\n If the Cloud Scheduler Service Account role is not listed, click the\n **Edit** icon and grant the **Cloud Scheduler Service Agent** role to the\n Cloud Scheduler Service Account principal.\n\nSpecify a VPC Service Controls perimeter\n----------------------------------------\n\nRequired. You can use an existing perimeter or create a new perimeter to\nprotect your Cloud Scheduler jobs that have supported\ntargets. Both approaches give you the chance to specify services to restrict.\nSpecify the **Cloud Scheduler API**.\n\n- **Existing perimeters:** To update an existing VPC Service Controls perimeter\n to include Cloud Scheduler, follow the steps for\n [updating a service perimeter](/vpc-service-controls/docs/manage-service-perimeters#update).\n\n- **New perimeters:** To create a new perimeter for Cloud Scheduler,\n follow the steps to\n [create a service perimeter](/vpc-service-controls/docs/create-service-perimeters).\n\nEnforce VPC Service Controls on pre-existing jobs\n-------------------------------------------------\n\nRecommended. To enforce VPC Service Controls on Cloud Scheduler jobs\nthat you created before you added Cloud Scheduler to your\nVPC Service Controls perimeter, run an `update` on the job. You don't have to\nchange the job, but you must run the update in order for VPC Service Controls to\napply to the job and its future executions.\n\nYou can run an update for the job from the Google Cloud console (select\nthe job and use the **Edit** button), using the API, or with the\ngcloud CLI.\n\nTo enforce VPC Service Controls on a pre-existing job by using the\ngcloud CLI, run the following: \n\n### HTTP targets\n\n```bash\ngcloud scheduler jobs update http JOB_ID\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eJOB_ID\u003c/var\u003e: the ID of your job\n\n### Pub/Sub targets\n\n```bash\ngcloud scheduler jobs update pubsub JOB_ID\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eJOB_ID\u003c/var\u003e: the ID of your job"]]