借助 Identity and Access Management (IAM),您可以通过向主账号(例如用户、群组和服务账号)授予特定权限来管理对 Cloud Scheduler 资源的访问权限。您可以分配预定义角色或自定义角色,以控制谁可以查看、配置和运行预定作业。
概览
Cloud Scheduler 使用 IAM 进行访问权限控制。
如需了解 IAM 及其功能,请参阅 IAM 概览。如需了解如何授予和撤消访问权限,请参阅管理对项目、文件夹和组织的访问权限。
如需查看 Cloud Scheduler 支持的权限和角色列表,请参阅以下各部分。
启用 Cloud Scheduler API
如需查看和分配 Cloud Scheduler 的 IAM 角色,您必须为项目启用 Cloud Scheduler API。在启用此 API 之前,您不会在 Google Cloud 控制台中看到 Cloud Scheduler 角色。
启用 API 所需的角色
如需启用 API,您需要拥有 serviceusage.services.enable 权限。如果您创建了项目,则可能已经通过 Owner 角色 (roles/owner) 拥有此权限。否则,您可以通过 Service Usage Admin 角色 (roles/serviceusage.serviceUsageAdmin) 获得此权限。了解如何授予角色。
预定义角色
下表列出了 Cloud Scheduler 预定义的 IAM 角色以及每个角色包含的所有权限的相应列表。
预定义角色可满足大多数典型的用例。如果预定义角色无法满足您的用例,您可以创建 IAM 自定义角色。
Cloud Scheduler 角色
| Role | Permissions |
|---|---|
Cloud Scheduler Admin( Full access to jobs and executions. Note that a Cloud Scheduler Admin (or any custom role with the permission cloudscheduler.jobs.create) can create jobs that publish to any Pub/Sub topics within the project. Lowest-level resources where you can grant this role:
|
|
Cloud Scheduler Viewer( Get and list access to jobs, executions, and locations. Lowest-level resources where you can grant this role:
|
|
Cloud Scheduler Job Runner( Access to run jobs. Lowest-level resources where you can grant this role:
|
|
Service agent roles
Service agent roles should only be granted to service agents.
| Role | Permissions |
|---|---|
Cloud Scheduler Service Agent( Grants Cloud Scheduler Service Account access to manage resources. |
|
项目级层 IAM 管理
在项目级层,或通过从文件夹或组织继承,您可以使用Google Cloud 控制台、IAM API 或 Google Cloud CLI 来授予、更改和撤消 IAM 角色。如需了解详情,请参阅管理对项目、文件夹和组织的访问权限。
Cloud Scheduler 不支持对单个作业使用资源级 IAM 政策或 IAM Conditions 资源特性。授予主账号的任何 Cloud Scheduler 角色都适用于项目中的所有作业:
如需限制哪些主账号可以查看、修改或运行特定作业,请在单独的项目中创建这些作业。
如需限制单个 HTTP 目标作业在运行时可以调用的目标资源,请为该作业配置一个专用的用户代管式服务账号,该账号仅具有该目标所需的权限。创建或更新作业的主账号还必须对该服务账号拥有
iam.serviceAccounts.actAs权限,您可以使用 Service Account User 角色 (roles/iam.serviceAccountUser) 针对各个服务账号授予该权限。
Cloud Scheduler 服务代理
Cloud Scheduler 使用Google Cloud 创建和管理的服务代理,代表您执行经过身份验证的 HTTP 和 Pub/Sub 目标作业。此服务代理需要 Cloud Scheduler Service Agent 角色 (roles/cloudscheduler.serviceAgent)。如需详细了解如何验证或授予此角色,请参阅授予 Cloud Scheduler Service Agent 角色。