커스텀 제약조건 만들기

Google Cloud 조직 정책을 사용하면 조직 리소스를 중앙에서 프로그래매틱 방식으로 제어할 수 있습니다. 조직 정책 관리자Google Cloud 리소스 계층 구조에서Google Cloud 리소스와 해당 리소스의 하위 요소에 적용되는 제약 조건이라는 제한사항 집합인 조직 정책을 정의할 수 있습니다. 조직, 폴더, 프로젝트 수준에서 조직 정책을 적용할 수 있습니다.

조직 정책은 다양한Google Cloud 서비스에 대한 사전 정의된 제약 조건을 제공합니다. 그러나 조직 정책에서 제한되는 특정 필드를 보다 세부적으로 맞춤설정 가능한 방식으로 제어하려면 커스텀 제약조건을 만들고 조직 정책에 이러한 커스텀 제약조건을 사용할 수 있습니다.

이점

커스텀 조직 정책을 사용하여 Managed Service for Apache Spark 배치, 세션, 세션 템플릿에 대한 특정 작업을 허용하거나 거부할 수 있습니다. 예를 들어 배치 워크로드 생성 요청이 조직 정책에 설정된 대로 맞춤 제약 조건 검증을 충족하지 못하면 요청이 실패하고 호출자에게 오류가 반환됩니다.

정책 상속

기본적으로 조직 정책은 정책을 적용하는 리소스의 하위 요소에 상속됩니다. 예를 들어 폴더에 정책을 적용하면 Google Cloud 가 폴더의 모든 프로젝트에 정책을 적용합니다. 이 동작 및 이를 변경하는 방법에 대한 자세한 내용은 계층 구조 평가 규칙을 참조하세요.

가격 책정

사전 정의된 제약조건 및 커스텀 제약조건을 포함하여 조직 정책 서비스는 무료로 제공됩니다.

시작하기 전에

  1. 프로젝트 설정
    1. Google Cloud 계정에 로그인합니다. Google Cloud를 처음 사용하는 경우 계정을 만들고 Google 제품의 실제 성능을 평가해 보세요. 신규 고객에게는 워크로드를 실행, 테스트, 배포하는 데 사용할 수 있는 $300의 무료 크레딧이 제공됩니다.
    2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

      Roles required to select or create a project

      • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
      • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

      Go to project selector

    3. Verify that billing is enabled for your Google Cloud project.

    4. Enable the Managed Service for Apache Spark API.

      Roles required to enable APIs

      To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

      Enable the API

    5. Google Cloud CLI를 설치합니다.

    6. 외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

    7. gcloud CLI를 초기화하려면, 다음 명령어를 실행합니다.

      gcloud init
    8. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

      Roles required to select or create a project

      • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
      • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

      Go to project selector

    9. Verify that billing is enabled for your Google Cloud project.

    10. Enable the Managed Service for Apache Spark API.

      Roles required to enable APIs

      To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

      Enable the API

    11. Google Cloud CLI를 설치합니다.

    12. 외부 ID 공급업체(IdP)를 사용하는 경우 먼저 제휴 ID로 gcloud CLI에 로그인해야 합니다.

    13. gcloud CLI를 초기화하려면, 다음 명령어를 실행합니다.

      gcloud init
    14. 조직 ID를 알고 있어야 합니다.

필요한 역할

조직 정책을 관리하는 데 필요한 권한을 얻으려면 관리자에게 조직 리소스에 대한 조직 정책 관리자(roles/orgpolicy.policyAdmin) IAM 역할을 부여해 달라고 요청하세요. 역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.

이 사전 정의된 역할에는 조직 정책을 관리하는 데 필요한 권한이 포함되어 있습니다. 필수 권한 섹션을 펼치면 필요한 권한을 정확하게 확인할 수 있습니다.

필수 권한

조직 정책을 관리하려면 다음 권한이 필요합니다.

  • orgpolicy.constraints.list
  • orgpolicy.policies.create
  • orgpolicy.policies.delete
  • orgpolicy.policies.list
  • orgpolicy.policies.update
  • orgpolicy.policy.get
  • orgpolicy.policy.set

커스텀 역할이나 다른 사전 정의된 역할을 사용하여 이 권한을 부여받을 수도 있습니다.

커스텀 제약 조건 만들기

커스텀 제약 조건은 적용되는 리소스, 메서드, 조건, 작업으로 YAML 파일에서 정의됩니다. Apache Spark용 관리형 서비스는 일괄 및 세션 리소스의 CREATE 메서드에 적용되는 맞춤 제약 조건을 지원합니다.

커스텀 제약조건을 만드는 방법은 커스텀 조직 정책 만들기 및 관리를 참조하세요.

일괄 리소스의 맞춤 제약 조건 만들기

일괄 리소스의 Managed Service for Apache Spark 커스텀 제약 조건에 대해 YAML 파일을 만들려면 다음 형식을 사용하세요.

name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
resourceTypes:
- dataproc.googleapis.com/Batch
methodTypes: 
- CREATE
condition: CONDITION
actionType: ACTION
displayName: DISPLAY_NAME
description: DESCRIPTION

다음을 바꿉니다.

  • ORGANIZATION_ID: 조직 ID(예: 123456789)

  • CONSTRAINT_NAME: 새 커스텀 제약 조건에 사용할 이름. 커스텀 제약 조건은 custom.으로 시작해야 하며 대문자, 소문자 또는 숫자만 포함할 수 있습니다(예: custom.batchMustHaveSpecifiedCategoryLabel). 이 필드의 최대 길이는 프리픽스를 제외하고 70자입니다(예: organizations/123456789/customConstraints/custom.).

  • CONDITION: 지원되는 서비스 리소스의 표현에 대해 작성된 CEL 조건입니다. 이 필드의 최대 길이는 1,000자(영문 기준)입니다. 조건을 작성하는 데 사용할 수 있는 리소스에 대한 자세한 내용은 리소스 및 작업에 대한 Dataproc 서버리스 제약 조건을 참고하세요. 샘플 조건: ("category" in resource.labels) && (resource.labels['category'] in ['retail', 'ads', 'service'])

  • ACTION: 조건이 충족될 때 수행할 작업. ALLOW 또는 DENY일 수 있습니다.

  • DISPLAY_NAME: 제약조건에 대한 사용자 친화적인 이름. 샘플 표시 이름: "배치 '카테고리' 라벨 요구 조건 적용". 이 필드의 최대 길이는 200자(영문 기준)입니다.

  • DESCRIPTION: 정책을 위반할 때 오류 메시지로 표시할 제약조건에 대한 사용자 친화적인 설명입니다. 이 필드의 최대 길이는 2,000자(영문 기준)입니다. 샘플 설명: '소매업체', '광고' 또는 '서비스' 값이 있는 '카테고리' 라벨이 있는 경우에만 Dataproc 배치 만들기 허용'.

세션 리소스의 맞춤 제약 조건 만들기

세션 리소스의 Managed Service for Apache Spark 커스텀 제약 조건에 대해 YAML 파일을 만들려면 다음 형식을 사용하세요.

name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
resourceTypes:
- dataproc.googleapis.com/Session
methodTypes: 
- CREATE
condition: CONDITION
actionType: ACTION
displayName: DISPLAY_NAME
description: DESCRIPTION

다음을 바꿉니다.

  • ORGANIZATION_ID: 조직 ID(예: 123456789)

  • CONSTRAINT_NAME: 새 커스텀 제약 조건에 사용할 이름. 커스텀 제약 조건은 custom.으로 시작해야 하며 대문자, 소문자 또는 숫자만 포함할 수 있습니다(예: custom.SessionNameMustStartWithTeamName). 이 필드의 최대 길이는 접두사를 제외하고 70자입니다(예: organizations/123456789/customConstraints/custom.).

  • CONDITION: 지원되는 서비스 리소스의 표현에 대해 작성된 CEL 조건입니다. 이 필드의 최대 길이는 1,000자(영문 기준)입니다. 조건을 작성하는 데 사용할 수 있는 리소스에 대한 자세한 내용은 리소스 및 작업에 대한 Dataproc 서버리스 제약조건을 참고하세요. 샘플 조건: (resource.name.startsWith("dataproc")

  • ACTION: 조건이 충족될 때 수행할 작업. ALLOW 또는 DENY일 수 있습니다.

  • DISPLAY_NAME: 제약조건에 대한 사용자 친화적인 이름. 샘플 표시 이름: '세션의 ttl이 2시간 미만이어야 함'. 이 필드의 최대 길이는 200자(영문 기준)입니다.

  • DESCRIPTION: 정책을 위반할 때 오류 메시지로 표시할 제약조건에 대한 사용자 친화적인 설명입니다. 이 필드의 최대 길이는 2,000자(영문 기준)입니다. 샘플 설명: '허용되는 TTL을 설정하는 경우에만 세션 생성 허용'.

세션 템플릿 리소스의 맞춤 제약 조건 만들기

세션 템플릿 리소스에 대해 Managed Service for Apache Spark 커스텀 제약 조건의 YAML 파일을 만들려면 다음 형식을 사용하세요.

name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
resourceTypes:
- dataproc.googleapis.com/SessionTemplate
methodTypes: 
- CREATE
- UPDATE
condition: CONDITION
actionType: ACTION
displayName: DISPLAY_NAME
description: DESCRIPTION

다음을 바꿉니다.

  • ORGANIZATION_ID: 조직 ID(예: 123456789)

  • CONSTRAINT_NAME: 새 커스텀 제약 조건에 사용할 이름. 커스텀 제약 조건은 custom.으로 시작해야 하며 대문자, 소문자 또는 숫자만 포함할 수 있습니다(예: custom.SessionTemplateNameMustStartWithTeamName). 이 필드의 최대 길이는 프리픽스를 제외하고 70자(영문 기준)입니다(예: organizations/123456789/customConstraints/custom.).

  • CONDITION: 지원되는 서비스 리소스의 표현에 대해 작성된 CEL 조건입니다. 이 필드의 최대 길이는 1,000자(영문 기준)입니다. 조건을 작성하는 데 사용할 수 있는 리소스에 대한 자세한 내용은 리소스 및 작업에 대한 제약 조건을 참고하세요. 샘플 조건: (resource.name.startsWith("dataproc")

  • ACTION: 조건이 충족될 때 수행할 작업. ALLOW 또는 DENY일 수 있습니다.

  • DISPLAY_NAME: 제약조건에 대한 사용자 친화적인 이름. 샘플 표시 이름: '세션 템플릿의 ttl이 2시간 미만이어야 함'. 이 필드의 최대 길이는 200자(영문 기준)입니다.

  • DESCRIPTION: 정책을 위반할 때 오류 메시지로 표시할 제약조건에 대한 사용자 친화적인 설명입니다. 이 필드의 최대 길이는 2,000자(영문 기준)입니다. 샘플 설명: '허용되는 TTL을 설정하는 경우에만 세션 템플릿 만들기 허용'.

커스텀 제약조건 설정

콘솔

커스텀 제약 조건을 만들려면 다음을 수행합니다.

  1. Google Cloud 콘솔에서 조직 정책 페이지로 이동합니다.

    조직 정책으로 이동

  2. 프로젝트 선택 도구에서 조직 정책을 설정할 프로젝트를 선택합니다.
  3. 커스텀 제약조건을 클릭합니다.
  4. 표시 이름 상자에 인간이 읽을 수 있는 제약 조건 이름을 입력합니다. 이 이름은 오류 메시지에 사용되며 식별과 디버깅에 사용할 수 있습니다. 이 이름은 오류 메시지에 노출될 수 있으므로 표시 이름에 개인 식별 정보 (PII)나 민감한 정보를 사용하지 마세요. 이 필드는 최대 200자(영문 기준)까지 포함할 수 있습니다.
  5. 제약 조건 ID 상자에 새 맞춤 제약 조건에 사용하려는 ID를 입력합니다. 커스텀 제약 조건은 문자(대문자 및 소문자 포함) 또는 숫자만 포함할 수 있습니다(예: custom.batchMustHaveSpecifiedCategoryLabel). 이 필드는 프리픽스(custom.)를 제외하고 최대 70자(영문 기준)까지 포함할 수 있습니다(예: organizations/123456789/customConstraints/custom). 오류 메시지에 노출될 수 있으므로 제약 조건 ID에 개인 식별 정보나 민감한 정보를 포함하지 마세요.
  6. 설명 상자에 인간이 읽을 수 있는 제약 조건 설명을 입력합니다. 이 설명은 정책이 위반되었을 때 오류 메시지로 사용됩니다. 정책 위반이 발생한 이유와 정책 위반을 해결하는 방법에 대한 세부정보를 포함합니다. 오류 메시지에 노출될 수 있으므로 설명에 개인 식별 정보나 민감한 정보를 포함하지 마세요. 이 필드는 최대 2,000자(영문 기준)까지 포함할 수 있습니다.
  7. 리소스 유형 상자에서 제한하려는 객체와 필드가 포함된 Google Cloud REST 리소스 이름을 선택합니다(예: container.googleapis.com/NodePool). 대부분의 리소스 유형은 커스텀 제약 조건을 최대 20개까지 지원합니다. 커스텀 제약 조건을 더 만들려고 하면 작업이 실패합니다.
  8. 이 제약 조건은 REST CREATE 메서드에만 적용할 수 있습니다.
  9. 각 서비스에 지원되는 메서드를 보려면 커스텀 제약조건을 지원하는 서비스에서 서비스를 찾으세요.

  10. 조건을 정의하려면 조건 수정을 클릭합니다.
    1. 조건 추가 패널에서 지원되는 서비스 리소스를 참조하는 CEL 조건을 만듭니다(예: resource.management.autoUpgrade == false). 이 필드는 최대 1,000자(영문 기준)까지 포함할 수 있습니다. CEL 사용 방법에 대한 자세한 내용은 Common Expression Language를 참조하세요. 커스텀 제약 조건에 사용할 수 있는 서비스 리소스에 대한 자세한 내용은 커스텀 제약 조건 지원 서비스를 참조하세요.
    2. 저장을 클릭합니다.
  11. 작업에서 조건이 충족될 경우 평가된 메서드를 허용하거나 거부할지를 선택합니다.
  12. 거부 작업은 조건이 true로 평가되면 리소스를 만들거나 업데이트하는 작업이 차단됨을 의미합니다.

    허용 작업은 조건이 true로 평가되는 경우에만 리소스를 만들거나 업데이트하는 작업이 허용됨을 의미합니다. 조건에 명시적으로 나열된 케이스를 제외한 다른 모든 케이스가 차단됩니다.

  13. 제약 조건 만들기를 클릭합니다.
  14. 각 필드에 값을 입력하면 이 커스텀 제약 조건에 해당하는 YAML 구성이 오른쪽에 표시됩니다.

gcloud

  1. 커스텀 제약 조건을 만들려면 다음 형식을 사용하여 YAML 파일을 만듭니다.
  2. name: organizations/ORGANIZATION_ID/customConstraints/CONSTRAINT_NAME
    resourceTypes: RESOURCE_NAME
    methodTypes:
      - CREATE
    condition: "CONDITION"
    actionType: ACTION
    displayName: DISPLAY_NAME
    description: DESCRIPTION

    다음을 바꿉니다.

    • ORGANIZATION_ID: 조직 ID(예: 123456789)
    • CONSTRAINT_NAME: 새 커스텀 제약 조건에 사용할 이름. 커스텀 제약 조건은 문자(대문자 및 소문자 포함) 또는 숫자만 포함할 수 있습니다(예: custom.batchMustHaveSpecifiedCategoryLabel). 이 필드는 프리픽스(custom.)를 제외하고 최대 70자(영문 기준)까지 포함할 수 있습니다(예: organizations/123456789/customConstraints/custom). 오류 메시지에 노출될 수 있으므로 제약 조건 ID에 개인 식별 정보나 민감한 정보를 포함하지 마세요.
    • RESOURCE_NAME: 제한하려는 객체와 필드가 포함된 Google Cloud리소스의 정규화된 이름. 예를 들면 dataproc.googleapis.com/batch입니다. 대부분의 리소스 유형은 커스텀 제약 조건을 최대 20개까지 지원합니다. 커스텀 제약 조건을 더 만들려고 하면 작업이 실패합니다.
    • methodTypes: 제약 조건이 적용되는 REST 메서드입니다. CREATE만 가능합니다.
    • 각 서비스에 지원되는 메서드를 보려면 커스텀 제약 조건 지원 서비스에서 서비스를 찾으세요.

    • CONDITION: 지원되는 서비스 리소스의 표현에 대해 작성된 CEL 조건. 이 필드는 최대 1,000자(영문 기준)까지 포함할 수 있습니다. 예를 들면 ("category" in resource.labels) && (resource.labels['category'] in ['retail', 'ads', 'service'])입니다.
    • 조건을 작성하는 데 사용할 수 있는 리소스에 대한 자세한 내용은 지원되는 리소스를 참조하세요.

    • ACTION: condition이 충족되면 수행할 작업. ALLOW만 가능합니다.
    • 허용 작업은 조건이 true로 평가되면 리소스를 만들거나 업데이트하는 작업이 허용됨을 의미합니다. 즉, 조건에 명시적으로 나열된 케이스를 제외한 다른 모든 케이스는 차단됩니다.

    • DISPLAY_NAME: 사람이 읽을 수 있는 제약 조건 이름입니다. 이 이름은 오류 메시지에 사용되며 식별과 디버깅에 사용할 수 있습니다. 이 이름은 오류 메시지에 노출될 수 있으므로 표시 이름에 개인 식별 정보나 민감한 정보를 사용하지 마세요. 이 필드는 최대 200자(영문 기준)까지 포함할 수 있습니다.
    • DESCRIPTION: 정책이 위반될 때 오류 메시지로 표시할 사용자 친화적인 제약 조건 설명. 이 필드는 최대 2,000자(영문 기준)까지 포함할 수 있습니다.
  3. 새 커스텀 제약 조건에 사용할 YAML 파일을 만든 후에는 조직의 조직 정책에 이 파일을 사용할 수 있도록 설정해야 합니다. 커스텀 제약 조건을 설정하려면 gcloud org-policies set-custom-constraint 명령어를 사용합니다.
  4. gcloud org-policies set-custom-constraint CONSTRAINT_PATH

    CONSTRAINT_PATH를 커스텀 제약 조건 파일의 전체 경로로 바꿉니다. 예를 들면 /home/user/customconstraint.yaml입니다.

    이 작업이 완료되면 Google Cloud 조직 정책 목록에서 조직 정책으로 커스텀 제약 조건을 사용할 수 있습니다.

  5. 커스텀 제약 조건이 있는지 확인하려면 gcloud org-policies list-custom-constraints 명령어를 사용합니다.
  6. gcloud org-policies list-custom-constraints --organization=ORGANIZATION_ID

    ORGANIZATION_ID를 조직 리소스의 ID로 바꿉니다.

    자세한 내용은 조직 정책 보기를 참조하세요.

커스텀 제약 조건 적용

제약 조건을 참조하는 조직 정책을 만든 후 해당 조직 정책을 Google Cloud 리소스에 적용하여 제약 조건을 적용할 수 있습니다.

콘솔

  1. Google Cloud 콘솔에서 조직 정책 페이지로 이동합니다.

    조직 정책으로 이동

  2. 프로젝트 선택 도구에서 조직 정책을 설정할 프로젝트를 선택합니다.
  3. 조직 정책 페이지의 목록에서 제약 조건을 선택하여 해당 제약조건의 정책 세부정보 페이지를 봅니다.
  4. 이 리소스의 조직 정책을 구성하려면 정책 관리를 클릭합니다.
  5. 정책 수정 페이지에서 상위 정책 재정의를 선택합니다.
  6. 규칙 추가를 클릭합니다.
  7. 적용 섹션에서 이 조직 정책을 적용할지 여부를 선택합니다.
  8. (선택사항) 태그로 조직 정책을 조건부로 만들려면 조건 추가를 클릭합니다. 조건부 규칙을 조직 정책에 추가하면 비조건부 규칙을 최소 하나 이상 추가해야 합니다. 그러지 않으면 정책을 저장할 수 없습니다. 자세한 내용은 태그를 사용하여 조직 정책 범위 지정을 참고하세요.
  9. 변경사항 테스트를 클릭하여 조직 정책 효과를 시뮬레이션합니다. 자세한 내용은 정책 시뮬레이터로 조직 정책 변경사항 테스트를 참조하세요.
  10. 테스트 실행 모드의 조직 정책을 적용하려면 테스트 실행 정책 설정을 클릭합니다. 자세한 내용은 조직 정책 테스트를 참고하세요.
  11. 테스트 실행 모드의 조직 정책이 의도한 대로 작동하는지 확인한 후 정책 설정을 클릭하여 실시간 정책을 설정합니다.

gcloud

  1. 불리언 규칙이 있는 조직 정책을 만들려면 제약 조건을 참조하는 정책 YAML 파일을 만듭니다.
  2. name: projects/PROJECT_ID/policies/CONSTRAINT_NAME
    spec:
      rules:
      - enforce: true
    
    dryRunSpec:
      rules:
      - enforce: true

    다음을 바꿉니다.

    • PROJECT_ID: 제약 조건을 적용할 프로젝트
    • CONSTRAINT_NAME: 커스텀 제약 조건에 정의한 이름. 예를 들면 custom.batchMustHaveSpecifiedCategoryLabel입니다.
  3. 테스트 실행 모드의 조직 정책을 적용하려면 dryRunSpec 플래그와 함께 다음 명령어를 실행합니다.
  4. gcloud org-policies set-policy POLICY_PATH --update-mask=dryRunSpec

    POLICY_PATH를 조직 정책 YAML 파일의 전체 경로로 바꿉니다. 정책이 적용되는 데 최대 15분이 소요됩니다.

  5. 테스트 실행 모드의 조직 정책이 의도한 대로 작동하는지 확인한 후 org-policies set-policy 명령어와 spec 플래그를 사용하여 실시간 정책을 설정합니다.
  6. gcloud org-policies set-policy POLICY_PATH --update-mask=spec

    POLICY_PATH를 조직 정책 YAML 파일의 전체 경로로 바꿉니다. 정책이 적용되는 데 최대 15분이 걸립니다.

커스텀 제약조건 테스트

이 섹션에서는 배치, 세션, 세션 템플릿 리소스의 맞춤 제약 조건을 테스트하는 방법을 설명합니다.

일괄 리소스의 커스텀 제약 조건 테스트

다음 배치 만들기 예시에서는 커스텀 제약조건이 생성되었으며 배치 생성 시 배치에 '소매업', '광고' 또는 '서비스' 값이 연결된 '카테고리' 라벨을 포함하게 되어 있다고 가정합니다: ("category" in resource.labels) && (resource.labels['category'] in ['retail', 'ads', 'service']).

gcloud dataproc batches submit spark \
  --region us-west1
  --jars file:///usr/lib/spark/examples/jars/spark-examples.jar \
  --class org.apache.spark.examples.SparkPi  \
  --network default \
  --labels category=foo \
  --100

샘플 출력:

Operation denied by custom org policies: ["customConstraints/custom.batchMustHaveSpecifiedCategoryLabel": ""Only allow Dataproc batch creation if it has a 'category' label with
  a 'retail', 'ads', or 'service' value""]

세션 리소스의 커스텀 제약 조건 테스트

다음 세션 생성 예시에서는 세션에 orgName로 시작하는 name가 포함되도록 요구하기 위해 커스텀 제약조건을 만들고 세션 생성 시 적용했다고 가정합니다.

gcloud beta dataproc sessions create spark test-session
  --location us-central1

샘플 출력:

Operation denied by custom org policy:
["customConstraints/custom.denySessionNameNotStartingWithOrgName": "Deny session
creation if its name does not start with 'orgName'"]

세션 템플릿 리소스의 커스텀 제약조건 테스트

다음 세션 템플릿 생성 예시에서는 세션 템플릿 생성 및 업데이트 시 orgName로 시작하는 name이(가) 세션 템플릿에 있어야 한다는 커스텀 제약 조건이 생성되고 적용되었다고 가정합니다.

gcloud beta dataproc session-templates import test-session-template
--source=saved-template.yaml

샘플 출력:

Operation denied by custom org policy:
["customConstraints/custom.denySessionTemplateNameNotStartingWithOrgName":
"Deny session template creation or update if its name does not start with
'orgName'"]

리소스 및 작업에 대한 제약 조건

이 섹션에는 일괄 및 세션 리소스에 사용할 수 있는 Managed Service for Apache Spark 맞춤 제약 조건이 나열되어 있습니다.

지원되는 일괄 제약 조건

다음 Apache Spark용 관리형 서비스 커스텀 제약 조건은 배치 워크로드를 생성 (제출)할 때 사용할 수 있습니다.

일반

  • resource.labels

PySparkBatch

  • resource.pysparkBatch.mainPythonFileUri
  • resource.pysparkBatch.args
  • resource.pysparkBatch.pythonFileUris
  • resource.pysparkBatch.jarFileUris
  • resource.pysparkBatch.fileUris
  • resource.pysparkBatch.archiveUris

SparkBatch

  • resource.sparkBatch.mainJarFileUri
  • resource.sparkBatch.mainClass
  • resource.sparkBatch.args
  • resource.sparkBatch.jarFileUris
  • resource.sparkBatch.fileUris
  • resource.sparkBatch.archiveUris

SparRBatch

  • resource.sparkRBatch.mainRFileUri
  • resource.sparkRBatch.args
  • resource.sparkRBatch.fileUris
  • resource.sparkRBatch.archiveUris

SparkSqlBatch

  • resource.sparkSqlBatch.queryFileUri
  • resource.sparkSqlBatch.queryVariables
  • resource.sparkSqlBatch.jarFileUris

RuntimeConfig

  • resource.runtimeConfig.version
  • resource.runtimeConfig.containerImage
  • resource.runtimeConfig.properties
  • resource.runtimeConfig.repositoryConfig.pypiRepositoryConfig.pypiRepository
  • resource.runtimeConfig.autotuningConfig.scenarios
  • resource.runtimeConfig.cohort

ExecutionConfig

  • resource.environmentConfig.executionConfig.serviceAccount
  • resource.environmentConfig.executionConfig.networkUri
  • resource.environmentConfig.executionConfig.subnetworkUri
  • resource.environmentConfig.executionConfig.networkTags
  • resource.environmentConfig.executionConfig.kmsKey
  • resource.environmentConfig.executionConfig.idleTtl
  • resource.environmentConfig.executionConfig.ttl
  • resource.environmentConfig.executionConfig.stagingBucket
  • resource.environmentConfig.executionConfig.authenticationConfig.userWorkloadAuthenticationType

PeripheralsConfig

  • resource.environmentConfig.peripheralsConfig.metastoreService
  • resource.environmentConfig.peripheralsConfig.sparkHistoryServerConfig.dataprocCluster

지원되는 세션 제약 조건

서버리스 세션에서 맞춤 제약 조건을 만들 때 다음 세션 속성을 사용할 수 있습니다.

일반

  • resource.name
  • resource.sparkConnectSession
  • resource.user
  • resource.sessionTemplate

JupyterSession

  • resource.jupyterSession.kernel
  • resource.jupyterSession.displayName

RuntimeConfig

  • resource.runtimeConfig.version
  • resource.runtimeConfig.containerImage
  • resource.runtimeConfig.properties
  • resource.runtimeConfig.repositoryConfig.pypiRepositoryConfig.pypiRepository
  • resource.runtimeConfig.autotuningConfig.scenarios
  • resource.runtimeConfig.cohort

ExecutionConfig

  • resource.environmentConfig.executionConfig.serviceAccount
  • resource.environmentConfig.executionConfig.networkUri
  • resource.environmentConfig.executionConfig.subnetworkUri
  • resource.environmentConfig.executionConfig.networkTags
  • resource.environmentConfig.executionConfig.kmsKey
  • resource.environmentConfig.executionConfig.idleTtl
  • resource.environmentConfig.executionConfig.ttl
  • resource.environmentConfig.executionConfig.stagingBucket
  • resource.environmentConfig.executionConfig.authenticationConfig.userWorkloadAuthenticationType

PeripheralsConfig

  • resource.environmentConfig.peripheralsConfig.metastoreService
  • resource.environmentConfig.peripheralsConfig.sparkHistoryServerConfig.dataprocCluster

지원되는 세션 템플릿 제약 조건

서버리스 세션 템플릿에서 커스텀 제약 조건을 만들 때 다음 세션 템플릿 속성을 사용할 수 있습니다.

일반

  • resource.name
  • resource.description
  • resource.sparkConnectSession

JupyterSession

  • resource.jupyterSession.kernel
  • resource.jupyterSession.displayName

RuntimeConfig

  • resource.runtimeConfig.version
  • resource.runtimeConfig.containerImage
  • resource.runtimeConfig.properties
  • resource.runtimeConfig.repositoryConfig.pypiRepositoryConfig.pypiRepository
  • resource.runtimeConfig.autotuningConfig.scenarios
  • resource.runtimeConfig.cohort

ExecutionConfig

  • resource.environmentConfig.executionConfig.serviceAccount
  • resource.environmentConfig.executionConfig.networkUri
  • resource.environmentConfig.executionConfig.subnetworkUri
  • resource.environmentConfig.executionConfig.networkTags
  • resource.environmentConfig.executionConfig.kmsKey
  • resource.environmentConfig.executionConfig.idleTtl
  • resource.environmentConfig.executionConfig.ttl
  • resource.environmentConfig.executionConfig.stagingBucket
  • resource.environmentConfig.executionConfig.authenticationConfig.userWorkloadAuthenticationType

PeripheralsConfig

  • resource.environmentConfig.peripheralsConfig.metastoreService
  • resource.environmentConfig.peripheralsConfig.sparkHistoryServerConfig.dataprocCluster

일반적인 사용 사례에 대한 커스텀 제약 조건 예시

이 섹션에는 배치 및 세션 리소스의 일반적인 사용 사례에 대한 맞춤 제약 조건의 예가 포함되어 있습니다.

일괄 리소스의 맞춤 제약 조건 예시

다음 표에서는 Apache Spark용 관리형 서비스 배치 커스텀 제약 조건의 예시를 제공합니다.

설명 제약조건 구문
배치는 허용되는 값과 함께 "카테고리" 라벨을 연결해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchMustHaveSpecifiedCategoryLabel
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition: ("category" in resource.labels) && (resource.labels['category'] in ['retail', 'ads', 'service'])
    actionType: ALLOW
    displayName: Enforce batch "category" label requirement.
    description: Only allow batch creation if it attaches a "category" label with an allowable value.
배치는 허용되는 런타임 버전을 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchMustUseAllowedVersion
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition:  (has(resource.runtimeConfig.version)) && (resource.runtimeConfig.version in ["2.0.45", "2.0.48"])
    actionType: ALLOW
    displayName: Enforce batch runtime version.
    description: Only allow batch creation if it sets an allowable runtime version.
SparkSQL을 사용해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchMustUseSparkSQL
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition: (has(resource.sparkSqlBatch))
    actionType: ALLOW
    displayName: Enforce batch only use SparkSQL Batch.
    description: Only allow creation of SparkSQL Batch.
배치는 TTL을 2시간 미만으로 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchMustSetLessThan2hTtl
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition:  (has(resource.environmentConfig.executionConfig.ttl)) && (resource.environmentConfig.executionConfig.ttl <= duration('2h'))
    actionType: ALLOW
    displayName: Enforce batch TTL.
    description: Only allow batch creation if it sets an allowable TTL.
Spark 초기 실행자는 20개를 초과하여 배치를 설정할 수 없습니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition: (has(resource.runtimeConfig.properties)) && ('spark.executor.instances' in resource.runtimeConfig.properties)
     && (int(resource.runtimeConfig.properties['spark.executor.instances'])>20)
    actionType: DENY
    displayName: Enforce maximum number of batch Spark executor instances.
    description: Deny batch creation if it specifies more than 20 Spark executor instances.
배치에서는 Spark 동적 할당 초기 실행자를 20개 넘게 설정할 수 없습니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchDynamicAllocationInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition: (has(resource.runtimeConfig.properties)) && ('spark.dynamicAllocation.initialExecutors' in resource.runtimeConfig.properties)
     && (int(resource.runtimeConfig.properties['spark.dynamicAllocation.initialExecutors'])>20)
    actionType: DENY
    displayName: Enforce maximum number of batch dynamic allocation initial executors.
    description: Deny batch creation if it specifies more than 20 Spark dynamic allocation initial executors.
배치에서 동적 할당 실행자를 20개 넘게 허용하지 않아야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchDynamicAllocationMaxExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition: (resource.runtimeConfig.properties['spark.dynamicAllocation.enabled']=='false') || (('spark.dynamicAllocation.maxExecutors' in resource.runtimeConfig.properties) && (int(resource.runtimeConfig.properties['spark.dynamicAllocation.maxExecutors'])<=20))
    actionType: ALLOW
    displayName: Enforce batch maximum number of dynamic allocation executors.
    description:  Only allow batch creation if dynamic allocation is disabled or
    the maximum number of dynamic allocation executors is set to less than or equal to 20.
배치는 허용되는 패턴으로 KMS 키를 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/custom.batchKmsPattern
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition:  matches(resource.environmentConfig.executionConfig.kmsKey, '^keypattern[a-z]$')
    actionType: ALLOW
    displayName: Enforce batch KMS Key pattern.
    description: Only allow batch creation if it sets the KMS key to an allowable pattern.
배치는 스테이징 버킷 프리픽스를 허용되는 값으로 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchStagingBucketPrefix
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition:  resource.environmentConfig.executionConfig.stagingBucket.startsWith(ALLOWED_PREFIX)
    actionType: ALLOW
    displayName: Enforce batch staging bucket prefix.
    description: Only allow batch creation if it sets the staging bucket prefix to ALLOWED_PREFIX.
배치 실행기 메모리 설정은 m 접미사로 끝나야 하며 20000m 미만이어야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.batchExecutorMemoryMax
    resourceTypes:
    - dataproc.googleapis.com/Batch
    methodTypes:
    - CREATE
    condition:  ('spark.executor.memory' in resource.runtimeConfig.properties) && (resource.runtimeConfig.properties['spark.executor.memory'].endsWith('m')) && (int(resource.runtimeConfig.properties['spark.executor.memory'].split('m')[0])<20000)
    actionType: ALLOW
    displayName: Enforce batch executor maximum memory.
    description: Only allow batch creation if the executor memory setting ends with a suffix 'm' and is less than 20000 m.

세션 리소스의 맞춤 제약 조건 예시

다음 표에서는 Apache Spark용 관리형 서비스 세션 맞춤 제약 조건의 예를 제공합니다.

설명 제약조건 구문
세션에서 sessionTemplate을 빈 문자열로 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateMustBeEmpty
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: resource.sessionTemplate == ""
    actionType: ALLOW
    displayName: Enforce empty session templates.
    description: Only allow session creation if session template is empty string.
sessionTemplate는 승인된 템플릿 ID와 같아야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateIdMustBeApproved
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition:
    resource.sessionTemplate.startsWith("https://www.googleapis.com/compute/v1/projects/")
      &&
      resource.sessionTemplate.contains("/locations/") &&
      resource.sessionTemplate.contains("/sessionTemplates/") &&
       (
         resource.sessionTemplate.endsWith("/1") ||
         resource.sessionTemplate.endsWith("/2") ||
         resource.sessionTemplate.endsWith("/13")
       )
    actionType: ALLOW
    displayName: Enforce templateId must be 1, 2, or 13.
    description: Only allow session creation if session template ID is in the
    approved list, that is, 1, 2 and 13.
세션은 최종 사용자 인증 정보를 사용하여 워크로드를 인증해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.AllowEUCSessions
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition:
    resource.environmentConfig.executionConfig.authenticationConfig.userWorkloadAuthenticationType=="END_USER_CREDENTIALS"
    actionType: ALLOW
    displayName: Require end user credential authenticated sessions.
    description: Allow session creation only if the workload is authenticated
    using end-user credentials.
세션은 허용되는 런타임 버전을 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/custom.sessionMustUseAllowedVersion
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: (has(resource.runtimeConfig.version)) &&
    (resource.runtimeConfig.version in ["2.0.45", "2.0.48"])
    actionType: ALLOW
    displayName: Enforce session runtime version.
    description: Only allow session creation if it sets an allowable runtime
    version.
세션은 TTL을 2시간 미만으로 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionMustSetLessThan2hTtl
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: (has(resource.environmentConfig.executionConfig.ttl)) &&
    (resource.environmentConfig.executionConfig.ttl <= duration('2h'))
    actionType: ALLOW
    displayName: Enforce session TTL.
    description: Only allow session creation if it sets an allowable TTL.
세션에서는 Spark 초기 실행자를 20개 넘게 설정할 수 없습니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: (has(resource.runtimeConfig.properties)) &&
    ('spark.executor.instances' in resource.runtimeConfig.properties) &&
    (int(resource.runtimeConfig.properties['spark.executor.instances'])>20)
    actionType: DENY
    displayName: Enforce maximum number of session Spark executor instances.
    description: Deny session creation if it specifies more than 20 Spark executor
    instances.
세션에서는 Spark 동적 할당 초기 실행자를 20개 넘게 설정할 수 없습니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionDynamicAllocationInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: (has(resource.runtimeConfig.properties)) &&
    ('spark.dynamicAllocation.initialExecutors' in resource.runtimeConfig.properties)
    && (int(resource.runtimeConfig.properties['spark.dynamicAllocation.initialExecutors'])>20)
    actionType: DENY
    displayName: Enforce maximum number of session dynamic allocation initial executors.
    description: Deny session creation if it specifies more than 20 Spark dynamic
    allocation initial executors.
세션은 허용되는 패턴으로 KMS 키를 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionKmsPattern
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: matches(resource.environmentConfig.executionConfig.kmsKey, '^keypattern[a-z]$')
    actionType: ALLOW
    displayName: Enforce session KMS Key pattern.
    description: Only allow session creation if it sets the KMS key to an
    allowable pattern.
세션은 스테이징 버킷 프리픽스를 허용되는 값으로 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionStagingBucketPrefix
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: resource.environmentConfig.executionConfig.stagingBucket.startsWith(ALLOWED_PREFIX)
    actionType: ALLOW
    displayName: Enforce session staging bucket prefix.
    description: Only allow session creation if it sets the staging bucket prefix
    to ALLOWED_PREFIX.
세션 실행기 메모리 설정은 m 접미사로 끝나야 하며 20000m보다 작아야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionExecutorMemoryMax
    resourceTypes:
    - dataproc.googleapis.com/Session
    methodTypes:
    - CREATE
    condition: ('spark.executor.memory' in resource.runtimeConfig.properties) &&
    (resource.runtimeConfig.properties['spark.executor.memory'].endsWith('m')) &&
    (int(resource.runtimeConfig.properties['spark.executor.memory'].split('m')[0])<20000)
    actionType: ALLOW
    displayName: Enforce session executor maximum memory.
    description: Only allow session creation if the executor memory setting ends
    with a suffix 'm' and is less than 20000 m.

세션 템플릿 리소스의 맞춤 제약 조건 예시

다음 표에서는 Apache Spark용 관리형 서비스 세션 템플릿 맞춤 제약 조건의 예를 보여줍니다.

설명 제약조건 구문
세션 템플릿 이름은 org-name로 끝나야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.denySessionTemplateNameNotEndingWithOrgName
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: '!resource.name.endsWith(''org-name'')'
    actionType: DENY
    displayName: DenySessionTemplateNameNotEndingWithOrgName
    description: Deny session template creation/update if its name does not end with 'org-name'
세션 템플릿은 허용되는 런타임 버전을 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/custom.sessionTemplateMustUseAllowedVersion
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: (has(resource.runtimeConfig.version)) &&
    (resource.runtimeConfig.version in ["2.0.45", "2.0.48"])
    actionType: ALLOW
    displayName: Enforce session template runtime version.
    description: Only allow session template creation or update if it sets an
    allowable runtime version.
세션 템플릿은 TTL을 2시간 미만으로 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateMustSetLessThan2hTtl
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: (has(resource.environmentConfig.executionConfig.ttl)) &&
    (resource.environmentConfig.executionConfig.ttl <= duration('2h'))
    actionType: ALLOW
    displayName: Enforce session template TTL.
    description: Only allow session template creation or update if it sets an
    allowable TTL.
세션 템플릿은 Spark 초기 실행자를 20개 넘게 설정할 수 없습니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: (has(resource.runtimeConfig.properties)) &&
    ('spark.executor.instances' in resource.runtimeConfig.properties) &&
    (int(resource.runtimeConfig.properties['spark.executor.instances'])>20)
    actionType: DENY
    displayName: Enforce maximum number of session Spark executor instances.
    description: Deny session template creation or update if it specifies more
    than 20 Spark executor instances.
세션 템플릿에서는 Spark 동적 할당 초기 실행자를 20개 넘게 설정할 수 없습니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateDynamicAllocationInitialExecutorMax20
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: (has(resource.runtimeConfig.properties)) &&
    ('spark.dynamicAllocation.initialExecutors' in resource.runtimeConfig.properties)
    && (int(resource.runtimeConfig.properties['spark.dynamicAllocation.initialExecutors'])>20)
    actionType: DENY
    displayName: Enforce maximum number of session dynamic allocation initial executors.
    description: Deny session template creation or update if it specifies more than 20
    Spark dynamic allocation initial executors.
세션 템플릿은 허용되는 패턴으로 KMS 키를 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateKmsPattern
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: matches(resource.environmentConfig.executionConfig.kmsKey, '^keypattern[a-z]$')
    actionType: ALLOW
    displayName: Enforce session KMS Key pattern.
    description: Only allow session template creation or update if it sets the KMS key to an
    allowable pattern.
세션 템플릿은 스테이징 버킷 접두사를 허용되는 값으로 설정해야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateStagingBucketPrefix
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: resource.environmentConfig.executionConfig.stagingBucket.startsWith(ALLOWED_PREFIX)
    actionType: ALLOW
    displayName: Enforce session staging bucket prefix.
    description: Only allow session template creation or update if it sets the staging
    bucket prefix to ALLOWED_PREFIX.
세션 템플릿 실행기 메모리 설정은 m 접미사로 끝나야 하며 20,000m보다 작아야 합니다.
    name: organizations/ORGANIZATION_ID/customConstraints/custom.sessionTemplateExecutorMemoryMax
    resourceTypes:
    - dataproc.googleapis.com/SessionTemplate
    methodTypes:
    - CREATE
    - UPDATE
    condition: ('spark.executor.memory' in resource.runtimeConfig.properties) &&
    (resource.runtimeConfig.properties['spark.executor.memory'].endsWith('m')) &&
    (int(resource.runtimeConfig.properties['spark.executor.memory'].split('m')[0])<20000)
    actionType: ALLOW
    displayName: Enforce session executor maximum memory.
    description: Only allow session template creation or update if the executor memory setting ends
    with a suffix 'm' and is less than 20000 m.

다음 단계