커스텀 제약조건을 사용하여 함수 리소스 관리

이 페이지에서는 gcloud functions 명령어 또는 Cloud Functions v2 API를 사용하여 만든 함수에 커스텀 제약 조건을 설정하는 방법을 보충 설명합니다.

Cloud Run을 사용하여 함수를 만들거나 배포한 경우 Cloud Run의 프로젝트의 커스텀 제약 조건 관리 가이드에서 커스텀 제약 조건 사용 방법을 자세히 알아보세요.

제한사항

Cloud Functions v2 API 함수에 커스텀 조직 정책을 사용하는 경우 다음 제한사항이 적용됩니다.

  • 일괄 삽입 API를 사용할 때는 VM 인스턴스 이름에 적용되지 않습니다.
  • Compute Engine 리소스의 CREATE 메서드에만 적용됩니다.
  • Cloud Functions v2 API에서만 사용할 수 있습니다. Cloud Run Functions(1세대)에는 적용할 수 없습니다.
  • Cloud Functions v2 API를 사용할 때만 함수를 보호합니다. Cloud Run Functions는 Cloud Run API에서도 수정할 수 있습니다. 추가 보호를 위해 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 
WORKER_POOL을 Cloud Build 작업자 풀의 이름으로 바꿉니다.
함수가 모든 컨테이너 이미지를 특정 이미지 저장소에 저장하도록 요구
    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
REPO_PATH를 모든 함수가 컨테이너 이미지를 저장할 이미지 저장소 URL의 URI로 바꿉니다.

다음 단계