使用 VPC Service Controls 保护 Cron 作业

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 仅在作业创建和作业更新时强制执行, 之前已禁用 VPC Service Controls 的 在将 Cloud Scheduler 添加到 VPC Service Controls 之前创建的 边界。即使作业目标不属于您的作业,作业也会继续执行 VPC Service Controls 边界或不是受支持的目标。接收者 对所有 Cloud Scheduler 作业强制执行 VPC Service Controls:

支持的目标

Cloud Scheduler 仅与 VPC Service Controls 集成 支持以下目标:

  • Cloud Run 函数(在 functions.net 网址上)
  • Cloud Run(位于 Cloud Run 的 run.app 网址中) 服务。不支持 Cloud Run 作业目标。如需了解 Cloud Run 的服务资源和作业资源之间的区别,请参阅服务和作业:运行代码的两种方式。)
  • Dataflow API(必须与 Cloud Scheduler 作业位于同一 Google Cloud 项目中)
  • Data Pipelines(必须与 Cloud Scheduler 作业位于同一 Google Cloud 项目中)
  • Pub/Sub(必须与 Cloud Scheduler 作业位于同一 Google Cloud 项目中)

删除不合规的作业

推荐。删除目标属于以下情况的 Cloud Scheduler 作业:

有关删除作业的说明,请参阅 删除作业

如果您未在将 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 角色,或授予此角色,请执行以下步骤:

  1. 在 Google Cloud 控制台中,浏览到 IAM

    转到 IAM

  2. 选中包括 Google 提供的角色授权复选框。

  3. 在过滤条件中,输入 Cloud Scheduler 服务账号,然后选择此主体。

  4. 查看 Cloud Scheduler 服务账号主账号的角色列。如果列出了以下角色,您可以继续操作:

    • Cloud Scheduler 服务代理

    如果未列出 Cloud Scheduler 服务账号角色,请点击 修改图标,并将 Cloud Scheduler Service Agent 角色授予 Cloud Scheduler 服务账号主账号。

指定 VPC Service Controls 边界

必需。您可以使用现有边界,也可以创建新边界 支持的 Cloud Scheduler 作业, 目标。这两种方法都可让您指定要限制的服务。 指定 Cloud Scheduler API

  • 现有边界:用于更新现有的 VPC Service Controls 边界 添加 Cloud Scheduler 更新服务边界

  • 新边界:要为 Cloud Scheduler 创建新边界, 按照相关步骤 创建服务边界

对现有作业强制执行 VPC Service Controls

推荐。如需对您在将 Cloud Scheduler 添加到 VPC Service Controls 边界之前创建的 Cloud Scheduler 作业强制执行 VPC Service Controls,请对作业运行 update。您无需更改作业,但必须运行更新,以便将 VPC Service Controls 应用于作业及其未来的执行。

您可以从 Google Cloud 控制台(选择 作业并使用修改按钮)、使用 API 或 gcloud CLI。

如需使用 VPC Service Controls 对原有作业强制执行 VPC Service Controls, gcloud CLI,请运行以下命令:

HTTP 目标

gcloud scheduler jobs update http JOB_ID

替换以下内容:

  • JOB_ID:作业的 ID

Pub/Sub 目标

gcloud scheduler jobs update pubsub JOB_ID

替换以下内容:

  • JOB_ID:作业的 ID