使用自定义限制条件管理函数资源
本页面提供了有关为使用 Cloud Functions v2 API(例如通过 gcloud functions
命令)创建的函数设置自定义限制条件的补充信息。
限制
以下限制适用于为 Cloud Functions v2 API 函数使用自定义组织政策:
- 仅适用于 Cloud Functions v2 API。
- 它们不会应用于 Cloud Run functions(第 1 代)。
- 仅在使用 Cloud Functions v2 API 时保护函数。 您也可以通过 Cloud Run API 修改 Cloud Run functions。为了获得额外保护,您可能还需要对 Cloud Run 应用自定义限制条件。
常见的组织政策示例
下表介绍了一些可能对您有用的自定义组织政策的语法:
说明 | 限制条件语法 |
---|---|
禁止使用特定语言创建函数 |
name: organizations/ORGANIZATION_ID/customConstraints/custom.cloudFunctionRuntimeBlock resource_types: cloudfunctions.googleapis.com/Function method_types: - CREATE - UPDATE condition: resource.buildConfig.runtime == "python312" action_type: DENY display_name: Deny functions using Python 3.12 description: Functions cannot be created with Python 3.12 as the language runtime |
要求函数使用特定的工作器池 |
name: organizations/ORGANIZATION_ID/customConstraints/custom.cloudFunctionsWorkerPool resource_types: cloudfunctions.googleapis.com/Function method_types: - CREATE - UPDATE condition: resource.buildConfig.workerPool == "WORKER_POOL" action_type: DENY display_name: Require worker pool description: Functions must use a worker pool |
要求函数将所有容器映像存储在特定映像代码库中 |
name: organizations/ORGANIZATION_ID/customConstraints/custom.cloudFunctionsRepository resource_types: cloudfunctions.googleapis.com/Function method_types: - CREATE - UPDATE condition: resource.buildConfig.dockerRepository.startsWith("REPO_PATH") action_type: DENY display_name: Image repository constraint description: Functions must push images to a central image repository under REPO_PATH |